* @brief get paths used by the program
* @author Milan
*/
-
-#ifdef __cplusplus
-extern "C"
-{
-#if 0 /* keep Emacsens' auto-indent happy */
-}
-#endif
-#endif
-
#include <sys/stat.h>
#include <stdlib.h>
#include <string.h>
get_path_from_proc_maps ()
{
char fn[64];
- char *line;
- char *dir;
+ char line[1024];
+ char dir[1024];
FILE *f;
+ char *lgu;
- GNUNET_snprintf (fn, 64, "/proc/%u/maps", getpid ());
- line = GNUNET_malloc (1024);
- dir = GNUNET_malloc (1024);
+ GNUNET_snprintf (fn,
+ sizeof(fn),
+ "/proc/%u/maps",
+ getpid ());
f = fopen (fn, "r");
- if (f != NULL)
+ if (f == NULL)
+ return NULL;
+ while (NULL != fgets (line, sizeof(line), f))
{
- while (NULL != fgets (line, 1024, f))
- {
- if ((1 == sscanf (line,
- "%*x-%*x %*c%*c%*c%*c %*x %*2u:%*2u %*u%*[ ]%s",
- dir)) && (NULL != strstr (dir, "libgnunetutil")))
- {
- strstr (dir, "libgnunetutil")[0] = '\0';
- fclose (f);
- GNUNET_free (line);
- return dir;
- }
- }
- fclose (f);
+ if ((1 == sscanf (line,
+ "%*x-%*x %*c%*c%*c%*c %*x %*2u:%*2u %*u%*[ ]%s",
+ dir)) &&
+ (NULL != (lgu = strstr (dir, "libgnunetutil"))))
+ {
+ lgu[0] = '\0';
+ fclose (f);
+ return GNUNET_strdup (dir);
+ }
}
- GNUNET_free (dir);
- GNUNET_free (line);
+ fclose (f);
return NULL;
}
get_path_from_proc_exe ()
{
char fn[64];
- char *lnk;
- size_t size;
+ char lnk[1024];
+ ssize_t size;
- GNUNET_snprintf (fn, 64, "/proc/%u/exe", getpid ());
- lnk = GNUNET_malloc (1024);
- size = readlink (fn, lnk, 1023);
- if ((size == 0) || (size >= 1024))
+ GNUNET_snprintf (fn,
+ sizeof(fn), "/proc/%u/exe", getpid ());
+ size = readlink (fn, lnk, sizeof (lnk)-1);
+ if (size <= 0)
{
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "readlink", fn);
- GNUNET_free (lnk);
return NULL;
}
+ GNUNET_assert (size < sizeof (lnk));
lnk[size] = '\0';
while ((lnk[size] != '/') && (size > 0))
size--;
if ((size < 4) || (lnk[size - 4] != '/'))
{
/* not installed in "/bin/" -- binary path probably useless */
- GNUNET_free (lnk);
return NULL;
}
lnk[size] = '\0';
- return lnk;
+ return GNUNET_strdup (lnk);
}
#endif
static char *
get_path_from_module_filename ()
{
- char *path;
+ char path[4097];
char *idx;
- path = GNUNET_malloc (4097);
- GetModuleFileName (NULL, path, 4096);
+ GetModuleFileName (NULL, path, sizeof(path)-1);
idx = path + strlen (path);
while ((idx > path) && (*idx != '\\') && (*idx != '/'))
idx--;
*idx = '\0';
- return path;
+ return GNUNET_strdup (path);
}
#endif
while (NULL != (end = strchr (pos, ':')))
{
*end = '\0';
- sprintf (buf, "%s/%s", pos, "gnunetd");
+ sprintf (buf, "%s/%s", pos, "gnunet-arm");
if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
{
pos = GNUNET_strdup (pos);
}
pos = end + 1;
}
- sprintf (buf, "%s/%s", pos, "gnunetd");
+ sprintf (buf, "%s/%s", pos, "gnunet-arm");
if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
{
pos = GNUNET_strdup (pos);
return ret;
/* other attempts here */
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not determine installation path for GNUnet. Set `%s' environment variable.\n"),
- "GNUNET_PREFIX");
+ _
+ ("Could not determine installation path for %s. Set `%s' environment variable.\n"),
+ "GNUnet",
+ "GNUNET_PREFIX");
return NULL;
}
return tmp;
}
-#if 0 /* keep Emacsens' auto-indent happy */
-{
-#endif
-#ifdef __cplusplus
-}
-#endif
/* end of os_installation.c */