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 232
 	if (file->s[0] == '/') {
233 233
 		/* This is an absolute pathname, make a zero terminated
234 234
 		 * 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");
235
+		if ((res = malloc(file->len+1)) == NULL) {
236
+			ERR("get_abs_pathname: No memory left (malloc failed)\n");
237 237
 		}
238
+		memcpy(res, file->s, file->len);
239
+		res[file->len]=0;
238 240
 	} else {
239 241
 		/* This is not an absolute pathname, make it relative
240 242
 		 * to the location of the base file
241 243
 		 */
242 244
 		/* 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");
245
+		if ((buf = malloc(base->len+1)) == NULL) {
246
+			ERR("get_abs_pathname: No memory left (malloc failed)\n");
245 247
 			return NULL;
246 248
 		}
249
+		memcpy(buf, base->s, base->len);
250
+		buf[base->len]=0;
247 251
 		dir = dirname(buf);
248 252
 		
249 253
 		len = strlen(dir);