11#define copystring(s) (s) ? s : NULL;
18 buff=realloc(buff,strlen(buff)+strlen(s)+1);
20 buff=calloc(strlen(s)+1,1);
30split_base_dir(
char *fullpath,
char *path,
unsigned int max)
32 char *post = strrchr(fullpath,
'/');
33 int pos = (post ? post-fullpath+1 : 0);
36 if (fullpath[pos] ==
'/') pos++;
37 if (pos) strncat(path, fullpath, pos);
38 return fullpath + pos;
46int main(
int argc,
char **argv)
49 const char *paths[] = {
"/abc/def",
"hij/klm"};
52 char *fullpath = strdup(paths[i]);
53 char *base = split_base_dir(fullpath, path,
sizeof(path));
54 printf(
"dirname of %s is %s; basename is %s\n", fullpath, path, base);
55 if (fullpath) free(fullpath);
int main(int argc, char *argv[])
Definition: cd-paranoia.c:704
#define NULL
Definition: getopt1.c:58
#define max(x, y)
Definition: p_block.h:37
char * catstring(char *buff, const char *s)
Definition: utils.c:160