|
|
1.1 ! root 1: /* util.c - handy utility functions. ! 2: * part of uucheck. ! 3: */ ! 4: #include <stdio.h> ! 5: #include "checkperms.h" ! 6: ! 7: /* Return a pointer to the basename of a full path (everthing to the ! 8: * right of the rightmost '/'. ! 9: */ ! 10: char * ! 11: basename(path) ! 12: char *path; ! 13: { ! 14: char *retval; ! 15: ! 16: if ((retval = (char *) strrchr(path, '/')) == NULL) { ! 17: retval = path; ! 18: } /* if there ain't no slash */ ! 19: else { ! 20: ++retval; /* We want the first character AFTER '/'. */ ! 21: } ! 22: ! 23: return(retval); ! 24: } /* basename() */ ! 25: ! 26: /* Copy a string into a new block of memory, free'ing anything being ! 27: * overwritten. ! 28: */ ! 29: char * ! 30: copy_str(dest, src) ! 31: char **dest, *src; ! 32: { ! 33: if (*dest != NULL) { ! 34: free(*dest); ! 35: } /* if destination not already empty */ ! 36: ! 37: if ((*dest = malloc(strlen(src) + 1)) == NULL) { ! 38: FATAL("line %d: Insufficient memory.\n", lineno); ! 39: } /* if malloc failed */ ! 40: ! 41: return(strcpy(*dest, src)); ! 42: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.