Browse code

- replaced strndup() in get_abs_pathname() since strndup is a GNU extensions not present in non glibc based OSes

Andrei Pelinescu-Onciul authored on 02/03/2008 15:11:59
Showing 1 changed files
... ...
@@ -28,7 +28,6 @@
28 28
  *
29 29
  */
30 30
 
31
-#define _GNU_SOURCE 1 /* strndup in get_abs_pathname */
32 31
 #include <string.h>
33 32
 #include <sys/types.h>
34 33
 #include <pwd.h>
... ...
@@ -232,18 +231,22 @@ char* get_abs_pathname(str* base, str* file)
232 231
 	if (file->s[0] == '/') {
233 232
 		/* This is an absolute pathname, make a zero terminated
234 233
 		 * copy and use it as it is */
235
-		if ((res = strndup(file->s, file->len)) == NULL) {
236
-			ERR("get_abs_pathname: No memory left (strndup failed)\n");
234
+		if ((res = malloc(file->len+1)) == NULL) {
235
+			ERR("get_abs_pathname: No memory left (malloc failed)\n");
237 236
 		}
237
+		memcpy(res, file->s, file->len);
238
+		res[file->len]=0;
238 239
 	} else {
239 240
 		/* This is not an absolute pathname, make it relative
240 241
 		 * to the location of the base file
241 242
 		 */
242 243
 		/* Make a copy, function dirname may modify the string */
243
-		if ((buf = strndup(base->s, base->len)) == NULL) {
244
-			ERR("get_abs_pathname: No memory left (strdup failed)\n");
244
+		if ((buf = malloc(base->len+1)) == NULL) {
245
+			ERR("get_abs_pathname: No memory left (malloc failed)\n");
245 246
 			return NULL;
246 247
 		}
248
+		memcpy(buf, base->s, base->len);
249
+		buf[base->len]=0;
247 250
 		dir = dirname(buf);
248 251
 		
249 252
 		len = strlen(dir);