Added MINGW support for compiling in Windows
* Still need a fix for missing libresolv.
This commit is contained in:
parent
3c3474eacd
commit
7d3418e9c7
7 changed files with 202 additions and 100 deletions
|
@ -46,9 +46,49 @@ Expect these resolutions:
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#ifdef __MINGW32__
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define u_char unsigned char
|
||||||
|
#define u_int16_t uint16_t
|
||||||
|
#define u_int32_t uint32_t
|
||||||
|
#define NS_MAXDNAME 1025 /*%< maximum domain name */
|
||||||
|
#define ns_c_in 1
|
||||||
|
#define ns_t_txt 16
|
||||||
|
|
||||||
|
typedef enum __ns_sect {
|
||||||
|
ns_s_qd = 0, /*%< Query: Question. */
|
||||||
|
ns_s_zn = 0, /*%< Update: Zone. */
|
||||||
|
ns_s_an = 1, /*%< Query: Answer. */
|
||||||
|
ns_s_pr = 1, /*%< Update: Prerequisites. */
|
||||||
|
ns_s_ns = 2, /*%< Query: Name servers. */
|
||||||
|
ns_s_ud = 2, /*%< Update: Update. */
|
||||||
|
ns_s_ar = 3, /*%< Query|Update: Additional records. */
|
||||||
|
ns_s_max = 4
|
||||||
|
} ns_sect;
|
||||||
|
|
||||||
|
typedef struct __ns_msg {
|
||||||
|
const unsigned char *_msg, *_eom;
|
||||||
|
u_int16_t _id, _flags, _counts[ns_s_max];
|
||||||
|
const unsigned char *_sections[ns_s_max];
|
||||||
|
ns_sect _sect;
|
||||||
|
int _rrnum;
|
||||||
|
const unsigned char *_msg_ptr;
|
||||||
|
} ns_msg;
|
||||||
|
|
||||||
|
typedef struct __ns_rr {
|
||||||
|
char name[NS_MAXDNAME];
|
||||||
|
u_int16_t type;
|
||||||
|
u_int16_t rr_class;
|
||||||
|
u_int32_t ttl;
|
||||||
|
u_int16_t rdlength;
|
||||||
|
const u_char * rdata;
|
||||||
|
} ns_rr;
|
||||||
|
#else
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <arpa/nameser.h>
|
#include <arpa/nameser.h>
|
||||||
#include <resolv.h>
|
#include <resolv.h>
|
||||||
|
#endif
|
||||||
#include "ipfs/namesys/namesys.h"
|
#include "ipfs/namesys/namesys.h"
|
||||||
#define IPFS_DNSLINK_C
|
#define IPFS_DNSLINK_C
|
||||||
#include "ipfs/dnslink/dnslink.h"
|
#include "ipfs/dnslink/dnslink.h"
|
||||||
|
@ -57,6 +97,11 @@ Expect these resolutions:
|
||||||
|
|
||||||
int ipfs_dns (int argc, char **argv)
|
int ipfs_dns (int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
#ifdef __MINGW32__
|
||||||
|
fprintf (stderr, "Sorry, dns has not yet been implemented for the Windows version.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
#else
|
||||||
int err, r=0, i;
|
int err, r=0, i;
|
||||||
char **txt, *path, *param;
|
char **txt, *path, *param;
|
||||||
|
|
||||||
|
@ -116,6 +161,7 @@ int ipfs_dns (int argc, char **argv)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif // MINGW
|
||||||
|
|
||||||
// ipfs_dnslink_resolve resolves the dnslink at a particular domain. It will
|
// ipfs_dnslink_resolve resolves the dnslink at a particular domain. It will
|
||||||
// recursively keep resolving until reaching the defaultDepth of Resolver. If
|
// recursively keep resolving until reaching the defaultDepth of Resolver. If
|
||||||
|
@ -190,6 +236,7 @@ int ipfs_dnslink_resolve_n (char **p, char *d, int depth)
|
||||||
return ErrResolveLimit;
|
return ErrResolveLimit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef __MINGW32__
|
||||||
// lookup using libresolv -lresolv
|
// lookup using libresolv -lresolv
|
||||||
int ipfs_dnslink_resolv_lookupTXT(char ***txt, char *domain)
|
int ipfs_dnslink_resolv_lookupTXT(char ***txt, char *domain)
|
||||||
{
|
{
|
||||||
|
@ -240,6 +287,7 @@ int ipfs_dnslink_resolv_lookupTXT(char ***txt, char *domain)
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// ipfs_dnslink_resolve_once implements resolver.
|
// ipfs_dnslink_resolve_once implements resolver.
|
||||||
int ipfs_dnslink_resolve_once (char ***p, char *domain)
|
int ipfs_dnslink_resolve_once (char ***p, char *domain)
|
||||||
|
@ -257,11 +305,13 @@ int ipfs_dnslink_resolve_once (char ***p, char *domain)
|
||||||
return ErrInvalidDomain;
|
return ErrInvalidDomain;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef __MINGW32__
|
||||||
if (!ipfs_dnslink_lookup_txt) { // if not set
|
if (!ipfs_dnslink_lookup_txt) { // if not set
|
||||||
ipfs_dnslink_lookup_txt = ipfs_dnslink_resolv_lookupTXT; // use default libresolv
|
ipfs_dnslink_lookup_txt = ipfs_dnslink_resolv_lookupTXT; // use default libresolv
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ipfs_dnslink_lookup_txt (&txt, domain);
|
err = ipfs_dnslink_lookup_txt (&txt, domain);
|
||||||
|
#endif
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,8 +50,11 @@ int ipfs_flatfs_create_directory(const char* full_directory) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
// it is not there, create it
|
// it is not there, create it
|
||||||
|
#ifdef __MINGW32__
|
||||||
|
if (mkdir(full_directory) == -1)
|
||||||
|
#else
|
||||||
if (mkdir(full_directory, S_IRWXU) == -1)
|
if (mkdir(full_directory, S_IRWXU) == -1)
|
||||||
return 0;
|
#endif return 0;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
27
main/main.c
27
main/main.c
|
@ -6,6 +6,33 @@
|
||||||
#include "ipfs/importer/exporter.h"
|
#include "ipfs/importer/exporter.h"
|
||||||
#include "ipfs/dnslink/dnslink.h"
|
#include "ipfs/dnslink/dnslink.h"
|
||||||
|
|
||||||
|
#ifdef __MINGW32__
|
||||||
|
void bzero(void *s, size_t n)
|
||||||
|
{
|
||||||
|
memset (s, '\0', n);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *strtok_r(char *str, const char *delim, char **save)
|
||||||
|
{
|
||||||
|
char *res, *last;
|
||||||
|
|
||||||
|
if( !save )
|
||||||
|
return strtok(str, delim);
|
||||||
|
if( !str && !(str = *save) )
|
||||||
|
return NULL;
|
||||||
|
last = str + strlen(str);
|
||||||
|
if( (*save = res = strtok(str, delim)) )
|
||||||
|
{
|
||||||
|
*save += strlen(res);
|
||||||
|
if( *save < last )
|
||||||
|
(*save)++;
|
||||||
|
else
|
||||||
|
*save = NULL;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
#endif // MINGW
|
||||||
|
|
||||||
void stripit(int argc, char** argv) {
|
void stripit(int argc, char** argv) {
|
||||||
char tmp[strlen(argv[argc])];
|
char tmp[strlen(argv[argc])];
|
||||||
strcpy(tmp, &argv[argc][1]);
|
strcpy(tmp, &argv[argc][1]);
|
||||||
|
|
12
os/utils.c
12
os/utils.c
|
@ -1,9 +1,12 @@
|
||||||
#include "ipfs/os/utils.h"
|
#include "ipfs/os/utils.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#ifndef __MINGW32__
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
|
#endif
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
@ -25,7 +28,11 @@ char* os_utils_getenv(const char* variable) {
|
||||||
* @returns true(1) on success
|
* @returns true(1) on success
|
||||||
*/
|
*/
|
||||||
int os_utils_setenv(const char* variable, const char* value, int overwrite) {
|
int os_utils_setenv(const char* variable, const char* value, int overwrite) {
|
||||||
return setenv(variable, value, overwrite);
|
#ifdef __MINGW32__
|
||||||
|
return 0;
|
||||||
|
#else
|
||||||
|
setenv(variable, value, overwrite);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,8 +40,11 @@ int os_utils_setenv(const char* variable, const char* value, int overwrite) {
|
||||||
* @returns the home directory
|
* @returns the home directory
|
||||||
*/
|
*/
|
||||||
char* os_utils_get_homedir() {
|
char* os_utils_get_homedir() {
|
||||||
|
#ifndef __MINGW32__
|
||||||
struct passwd *pw = getpwuid(getuid());
|
struct passwd *pw = getpwuid(getuid());
|
||||||
return pw->pw_dir;
|
return pw->pw_dir;
|
||||||
|
#endif
|
||||||
|
return ".";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -482,7 +482,11 @@ int ipfs_repo_fsrepo_blockstore_init(const struct FSRepo* fs_repo) {
|
||||||
if (retVal == 0)
|
if (retVal == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
#ifdef __MINGW32__
|
||||||
|
if (mkdir(full_path) != 0)
|
||||||
|
#else
|
||||||
if (mkdir(full_path, S_IRWXU) != 0)
|
if (mkdir(full_path, S_IRWXU) != 0)
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -183,6 +183,10 @@ int repo_fsrepo_lmdb_cast(struct Datastore* datastore) {
|
||||||
* @returns true(1) on success
|
* @returns true(1) on success
|
||||||
*/
|
*/
|
||||||
int repo_fsrepo_lmdb_create_directory(struct Datastore* datastore) {
|
int repo_fsrepo_lmdb_create_directory(struct Datastore* datastore) {
|
||||||
|
#ifdef __MINGW32__
|
||||||
|
return mkdir(datastore->path) == 0;
|
||||||
|
#else
|
||||||
return mkdir(datastore->path, S_IRWXU) == 0;
|
return mkdir(datastore->path, S_IRWXU) == 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,11 @@ int ipfs_repo_init(int argc, char** argv) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
// make the directory
|
// make the directory
|
||||||
|
#ifdef __MINGW32__
|
||||||
|
if (mkdir(dir) == -1) {
|
||||||
|
#else
|
||||||
if (mkdir(dir, S_IRWXU) == -1) {
|
if (mkdir(dir, S_IRWXU) == -1) {
|
||||||
|
#endif
|
||||||
printf("Unable to create the directory: %s\n", dir);
|
printf("Unable to create the directory: %s\n", dir);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue