310 |
return buf; |
return buf; |
311 |
} |
} |
312 |
|
|
313 |
char *makepath(char *buf, int buf_size, const char *path, const char *filename) |
char *makepath(char *buf, int buf_size, const char *path, |
314 |
|
const char *filename) |
315 |
{ |
{ |
316 |
int len; |
int len; |
317 |
|
|
324 |
return pstrcat(buf, buf_size, filename); |
return pstrcat(buf, buf_size, filename); |
325 |
} |
} |
326 |
|
|
327 |
/* copy the nth first char of a string and truncate it. */ |
void splitpath(char *dirname, int dirname_size, |
328 |
|
char *filename, int filename_size, const char *pathname) |
329 |
|
{ |
330 |
|
const char *base; |
331 |
|
|
332 |
|
base = basename(pathname); |
333 |
|
pstrncpy(dirname, dirname_size, pathname, base - pathname); |
334 |
|
pstrcpy(filename, filename_size, base); |
335 |
|
} |
336 |
|
|
337 |
|
/* copy the n first char of a string and truncate it. */ |
338 |
char *pstrncpy(char *buf, int buf_size, const char *s, int len) |
char *pstrncpy(char *buf, int buf_size, const char *s, int len) |
339 |
{ |
{ |
340 |
char *q, *q_end; |
char *q; |
341 |
int c; |
int c; |
342 |
|
|
343 |
if (buf_size > 0) { |
if (buf_size > 0) { |
344 |
q = buf; |
q = buf; |
345 |
q_end = buf + buf_size - 1; |
if (len >= buf_size) |
346 |
while (q < q_end && len > 0) { |
len = buf_size - 1; |
347 |
|
while (len > 0) { |
348 |
c = *s++; |
c = *s++; |
349 |
if (c == '\0') |
if (c == '\0') |
350 |
break; |
break; |