41 lines
982 B
C
41 lines
982 B
C
|
|
char* path_last(const char* path) {
|
|
char buffer[1024];
|
|
size_t psize = strlen(path);
|
|
strcpy(buffer, path);
|
|
buffer[psize] = '\0';
|
|
if (buffer[psize - 1] == '/') {
|
|
buffer[--psize] = '\0';
|
|
}
|
|
size_t pos = psize;
|
|
for (size_t i = 1; i < psize; i++) {
|
|
if (buffer[i] == '/') pos = i;
|
|
}
|
|
char* b = &buffer[++pos];
|
|
int bsize = strlen(b);
|
|
char* res = malloc(bsize + 1);
|
|
strcpy(res, b);
|
|
//printf("\n%s\n", res);
|
|
return res;
|
|
}
|
|
|
|
char* path_file(const char* path) {
|
|
char buffer[1024];
|
|
size_t psize = strlen(path);
|
|
strcpy(buffer, path);
|
|
buffer[psize] = '\0';
|
|
//if (buffer[psize - 1] == '/') {
|
|
// buffer[--psize] = '\0';
|
|
//}
|
|
size_t pos = psize;
|
|
for (size_t i = 1; i < psize; i++) {
|
|
if (buffer[i] == '/') pos = i;
|
|
}
|
|
char* b = &buffer[++pos];
|
|
int bsize = strlen(b);
|
|
char* res = malloc(bsize + 1);
|
|
strcpy(res, b);
|
|
//printf("\n%s\n", res);
|
|
return res;
|
|
}
|