char *lgu;
GNUNET_snprintf (fn, sizeof (fn), "/proc/%u/maps", getpid ());
- f = FOPEN (fn, "r");
- if (f == NULL)
+ if (NULL == (f = FOPEN (fn, "r")))
return NULL;
while (NULL != fgets (line, sizeof (line), f))
{
return NULL;
}
+
/**
* Try to determine path by reading /proc/PID/exe
*/
#if DARWIN
typedef int (*MyNSGetExecutablePathProto) (char *buf, size_t * bufsize);
+
static char *
get_path_from_NSGetExecutablePath ()
{
char *path;
size_t len;
MyNSGetExecutablePathProto func;
- int ret;
path = NULL;
- func =
- (MyNSGetExecutablePathProto) dlsym (RTLD_DEFAULT, "_NSGetExecutablePath");
- if (!func)
+ if (NULL == (func =
+ (MyNSGetExecutablePathProto) dlsym (RTLD_DEFAULT, "_NSGetExecutablePath")))
return NULL;
path = &zero;
len = 0;
/* get the path len, including the trailing \0 */
func (path, &len);
- if (len == 0)
+ if (0 == len)
return NULL;
path = GNUNET_malloc (len);
- ret = func (path, &len);
- if (ret != 0)
+ if (0 != func (path, &len))
{
GNUNET_free (path);
return NULL;
return path;
}
+
static char *
get_path_from_dyld_image ()
{
const char *path;
- char *p, *s;
+ char *p;
+ char *s;
int i;
int c;
if (_dyld_get_image_header (i) == &_mh_dylib_header)
{
path = _dyld_get_image_name (i);
- if (path != NULL && strlen (path) > 0)
+ if ( (NULL != path) && (strlen (path) > 0) )
{
p = GNUNET_strdup (path);
s = p + strlen (p);
- while ((s > p) && (*s != '/'))
+ while ((s > p) && ('/' != *s))
s--;
s++;
*s = '\0';
}
#endif
+
/**
* Return the actual path to a file found in the current
* PATH environment variable.
const char *p;
p = getenv ("PATH");
- if (p == NULL)
+ if (NULL == p)
return NULL;
path = GNUNET_strdup (p); /* because we write on it */
buf = GNUNET_malloc (strlen (path) + 20);
pos = end + 1;
}
sprintf (buf, "%s/%s", pos, binary);
- if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
+ if (GNUNET_YES == GNUNET_DISK_file_test (buf))
{
pos = GNUNET_strdup (pos);
GNUNET_free (buf);
return NULL;
}
+
static char *
get_path_from_GNUNET_PREFIX ()
{
const char *p;
- p = getenv ("GNUNET_PREFIX");
- if (p != NULL)
+ if (NULL != (p = getenv ("GNUNET_PREFIX")))
return GNUNET_strdup (p);
return NULL;
}
+
/**
* @brief get the path to GNUnet bin/ or lib/, prefering the lib/ path
* @author Milan
{
char *ret;
- ret = get_path_from_GNUNET_PREFIX ();
- if (ret != NULL)
+ if (NULL != (ret = get_path_from_GNUNET_PREFIX ()))
return ret;
#if LINUX
- ret = get_path_from_proc_maps ();
- if (ret != NULL)
+ if (NULL != (ret = get_path_from_proc_maps ()))
return ret;
- ret = get_path_from_proc_exe ();
- if (ret != NULL)
+ if (NULL != (ret = get_path_from_proc_exe ()))
return ret;
#endif
#if WINDOWS
- ret = get_path_from_module_filename ();
- if (ret != NULL)
+ if (NULL != (ret = get_path_from_module_filename ()))
return ret;
#endif
#if DARWIN
- ret = get_path_from_dyld_image ();
- if (ret != NULL)
+ if (NULL != (ret = get_path_from_dyld_image ()))
return ret;
- ret = get_path_from_NSGetExecutablePath ();
- if (ret != NULL)
+ if (NULL != (ret = get_path_from_NSGetExecutablePath ()))
return ret;
#endif
- ret = get_path_from_PATH ("gnunet-arm");
- if (ret != NULL)
+ if (NULL != (ret = get_path_from_PATH ("gnunet-arm")))
return ret;
/* other attempts here */
LOG (GNUNET_ERROR_TYPE_ERROR,
{
char *ret;
- ret = NULL;
#if LINUX
- ret = get_path_from_proc_exe ();
- if (ret != NULL)
+ if (NULL != (ret = get_path_from_proc_exe ()))
return ret;
#endif
#if WINDOWS
- ret = get_path_from_module_filename ();
- if (ret != NULL)
+ if (NULL != (ret = get_path_from_module_filename ()))
return ret;
#endif
#if DARWIN
- ret = get_path_from_NSGetExecutablePath ();
- if (ret != NULL)
+ if (NULL != (ret = get_path_from_NSGetExecutablePath ()))
return ret;
#endif
/* other attempts here */
- return ret;
+ return NULL;
}
/* try to get GNUnet's bin/ or lib/, or if previous was unsuccessful some
* guess for the current app */
- if (execpath == NULL)
+ if (NULL == execpath)
execpath = os_get_gnunet_path ();
- if (execpath == NULL)
+ if (NULL == execpath)
return NULL;
n = strlen (execpath);
- if (n == 0)
+ if (0 == n)
{
/* should never happen, but better safe than sorry */
GNUNET_free (execpath);
return NULL;
}
/* remove filename itself */
- while ((n > 1) && (execpath[n - 1] == DIR_SEPARATOR))
+ while ((n > 1) && (DIR_SEPARATOR == execpath[n - 1]))
execpath[--n] = '\0';
isbasedir = 1;
((0 == strcasecmp (&execpath[n - 5], "lib32")) ||
(0 == strcasecmp (&execpath[n - 5], "lib64"))))
{
- if (dirkind != GNUNET_OS_IPK_LIBDIR)
+ if (GNUNET_OS_IPK_LIBDIR != dirkind)
{
/* strip '/lib32' or '/lib64' */
execpath[n - 5] = '\0';
struct stat statbuf;
char *p;
char *pf;
-
#ifdef MINGW
SOCKET rawsock;
char *binaryexe;
GNUNET_asprintf (&binaryexe, "%s.exe", binary);
- p = get_path_from_PATH (binaryexe);
- if (p != NULL)
+ if (DIR_SEPARATOR == binary[0])
+ p = GNUNET_strdup (binary);
+ else
{
- GNUNET_asprintf (&pf, "%s/%s", p, binaryexe);
- GNUNET_free (p);
- p = pf;
+ p = get_path_from_PATH (binaryexe);
+ if (NULL != p)
+ {
+ GNUNET_asprintf (&pf, "%s/%s", p, binaryexe);
+ GNUNET_free (p);
+ p = pf;
+ }
}
GNUNET_free (binaryexe);
#else
- p = get_path_from_PATH (binary);
- if (p != NULL)
+ if (DIR_SEPARATOR == binary[0])
+ p = GNUNET_strdup (binary);
+ else
{
- GNUNET_asprintf (&pf, "%s/%s", p, binary);
- GNUNET_free (p);
- p = pf;
+ p = get_path_from_PATH (binary);
+ if (NULL != p)
+ {
+ GNUNET_asprintf (&pf, "%s/%s", p, binary);
+ GNUNET_free (p);
+ p = pf;
+ }
}
#endif
- if (p == NULL)
+ if (NULL == p)
{
LOG (GNUNET_ERROR_TYPE_INFO, _("Could not find binary `%s' in PATH!\n"),
binary);
#include "gnunet_resolver_service.h"
#include "resolver.h"
-#define VERBOSE GNUNET_NO
/**
* Using DNS root servers to check gnunet's resolver service
#define ROOTSERVER_NAME "a.root-servers.net"
#define ROOTSERVER_IP "198.41.0.4"
+
static void
check_hostname (void *cls, const struct sockaddr *sa, socklen_t salen)
{
int *ok = cls;
- if (salen == 0)
+ if (0 == salen)
{
(*ok) &= ~8;
return;
{
int *ok = cls;
- if (hostname == NULL)
+ if (NULL == hostname)
return;
if (0 == strcmp (hostname, "localhost"))
{
}
}
+
static void
check_127 (void *cls, const struct sockaddr *sa, socklen_t salen)
{
int *ok = cls;
const struct sockaddr_in *sai = (const struct sockaddr_in *) sa;
- if (sa == NULL)
+ if (NULL == sa)
return;
GNUNET_assert (sizeof (struct sockaddr_in) == salen);
if (sai->sin_addr.s_addr == htonl (INADDR_LOOPBACK))
}
}
+
static void
check_local_fqdn (void *cls, const char *gnunet_fqdn)
{
}
-
static void
check_rootserver_ip (void *cls, const struct sockaddr *sa, socklen_t salen)
{
int *ok = cls;
const struct sockaddr_in *sai = (const struct sockaddr_in *) sa;
- if (sa == NULL)
+ if (NULL == sa)
return;
GNUNET_assert (sizeof (struct sockaddr_in) == salen);
}
}
+
static void
check_rootserver_name (void *cls, const char *hostname)
{
int *ok = cls;
- if (hostname == NULL)
+ if (NULL == hostname)
return;
if (0 == strcmp (hostname, ROOTSERVER_NAME))
}
}
+
static void
run (void *cls, char *const *args, const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *cfg)
}
-static int
-check ()
+
+int
+main (int argc, char *argv[])
{
int ok = 1 + 2 + 4 + 8;
char *fn;
char *pfx;
struct GNUNET_OS_Process *proc;
-
- char *const argv[] =
- { "test-resolver-api", "-c", "test_resolver_api_data.conf",
-#if VERBOSE
- "-L", "DEBUG",
-#endif
- NULL
+ char *const argvx[] = {
+ "test-resolver-api", "-c", "test_resolver_api_data.conf", NULL
};
struct GNUNET_GETOPT_CommandLineOption options[] =
{ GNUNET_GETOPT_OPTION_END };
+
+ GNUNET_log_setup ("test-resolver-api",
+ "WARNING",
+ NULL);
pfx = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_BINDIR);
GNUNET_asprintf (&fn, "%s%cgnunet-service-resolver", pfx, DIR_SEPARATOR);
GNUNET_free (pfx);
proc = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, fn, "gnunet-service-resolver",
-#if VERBOSE
- "-L", "DEBUG",
-#endif
"-c", "test_resolver_api_data.conf", NULL);
GNUNET_assert (NULL != proc);
GNUNET_free (fn);
GNUNET_assert (GNUNET_OK ==
- GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
- argv, "test-resolver-api", "nohelp",
+ GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
+ argvx, "test-resolver-api", "nohelp",
options, &run, &ok));
if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
{
GNUNET_OS_process_wait (proc);
GNUNET_OS_process_destroy (proc);
proc = NULL;
- if (ok != 0)
+ if (0 != ok)
FPRINTF (stderr, "Missed some resolutions: %u\n", ok);
return ok;
}
-int
-main (int argc, char *argv[])
-{
- int ret;
-
- GNUNET_log_setup ("test-resolver-api",
-#if VERBOSE
- "DEBUG",
-#else
- "WARNING",
-#endif
- NULL);
- ret = check ();
-
- return ret;
-}
/* end of test_resolver_api.c */