aboutsummaryrefslogtreecommitdiff
path: root/src/util/os_installation.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-06-17 21:12:09 +0000
committerChristian Grothoff <christian@grothoff.org>2010-06-17 21:12:09 +0000
commitbed39036b47e1b820ee40d645f743e18520c4f8c (patch)
tree6218facf7c12448327e82780896a609ac000e128 /src/util/os_installation.c
parenta6d3a7a355634ef0396f009f9286962cdc4c6077 (diff)
downloadgnunet-bed39036b47e1b820ee40d645f743e18520c4f8c.tar.gz
gnunet-bed39036b47e1b820ee40d645f743e18520c4f8c.zip
fixes
Diffstat (limited to 'src/util/os_installation.c')
-rw-r--r--src/util/os_installation.c62
1 files changed, 30 insertions, 32 deletions
diff --git a/src/util/os_installation.c b/src/util/os_installation.c
index 7079e2fef..54ac001f9 100644
--- a/src/util/os_installation.c
+++ b/src/util/os_installation.c
@@ -55,32 +55,31 @@ static char *
55get_path_from_proc_maps () 55get_path_from_proc_maps ()
56{ 56{
57 char fn[64]; 57 char fn[64];
58 char *line; 58 char line[1024];
59 char *dir; 59 char dir[1024];
60 FILE *f; 60 FILE *f;
61 char *lgu;
61 62
62 GNUNET_snprintf (fn, 64, "/proc/%u/maps", getpid ()); 63 GNUNET_snprintf (fn,
63 line = GNUNET_malloc (1024); 64 sizeof(fn),
64 dir = GNUNET_malloc (1024); 65 "/proc/%u/maps",
66 getpid ());
65 f = fopen (fn, "r"); 67 f = fopen (fn, "r");
66 if (f != NULL) 68 if (f == NULL)
69 return NULL;
70 while (NULL != fgets (line, sizeof(line), f))
67 { 71 {
68 while (NULL != fgets (line, 1024, f)) 72 if ((1 == sscanf (line,
69 { 73 "%*x-%*x %*c%*c%*c%*c %*x %*2u:%*2u %*u%*[ ]%s",
70 if ((1 == sscanf (line, 74 dir)) &&
71 "%*x-%*x %*c%*c%*c%*c %*x %*2u:%*2u %*u%*[ ]%s", 75 (NULL != (lgu = strstr (dir, "libgnunetutil"))))
72 dir)) && (NULL != strstr (dir, "libgnunetutil"))) 76 {
73 { 77 lgu[0] = '\0';
74 strstr (dir, "libgnunetutil")[0] = '\0'; 78 fclose (f);
75 fclose (f); 79 return GNUNET_strdup (dir);
76 GNUNET_free (line); 80 }
77 return dir;
78 }
79 }
80 fclose (f);
81 } 81 }
82 GNUNET_free (dir); 82 fclose (f);
83 GNUNET_free (line);
84 return NULL; 83 return NULL;
85} 84}
86 85
@@ -91,13 +90,13 @@ static char *
91get_path_from_proc_exe () 90get_path_from_proc_exe ()
92{ 91{
93 char fn[64]; 92 char fn[64];
94 char *lnk; 93 char lnk[1024];
95 size_t size; 94 ssize_t size;
96 95
97 GNUNET_snprintf (fn, 64, "/proc/%u/exe", getpid ()); 96 GNUNET_snprintf (fn,
98 lnk = GNUNET_malloc (1024); 97 sizeof(fn), "/proc/%u/exe", getpid ());
99 size = readlink (fn, lnk, 1023); 98 size = readlink (fn, lnk, sizeof (lnk)-1);
100 if ((size == 0) || (size >= 1024)) 99 if ((size == 0) || (size >= sizeof(lnk)-1))
101 { 100 {
102 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "readlink", fn); 101 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "readlink", fn);
103 GNUNET_free (lnk); 102 GNUNET_free (lnk);
@@ -113,7 +112,7 @@ get_path_from_proc_exe ()
113 return NULL; 112 return NULL;
114 } 113 }
115 lnk[size] = '\0'; 114 lnk[size] = '\0';
116 return lnk; 115 return GNUNET_strdup (lnk);
117} 116}
118#endif 117#endif
119 118
@@ -124,16 +123,15 @@ get_path_from_proc_exe ()
124static char * 123static char *
125get_path_from_module_filename () 124get_path_from_module_filename ()
126{ 125{
127 char *path; 126 char path[4097];
128 char *idx; 127 char *idx;
129 128
130 path = GNUNET_malloc (4097); 129 GetModuleFileName (NULL, path, sizeof(path)-1);
131 GetModuleFileName (NULL, path, 4096);
132 idx = path + strlen (path); 130 idx = path + strlen (path);
133 while ((idx > path) && (*idx != '\\') && (*idx != '/')) 131 while ((idx > path) && (*idx != '\\') && (*idx != '/'))
134 idx--; 132 idx--;
135 *idx = '\0'; 133 *idx = '\0';
136 return path; 134 return GNUNET_strdup (path);
137} 135}
138#endif 136#endif
139 137