Mercurial > hg > toybox
comparison lib/lib.c @ 216:5697a3f7c8cf
Make patch's file add actually work, including directory creating and
understanding zero-context hunks.
author | Rob Landley <rob@landley.net> |
---|---|
date | Thu, 27 Dec 2007 21:36:33 -0600 |
parents | 98820d1eaa79 |
children | 104792581cc9 |
comparison
equal
deleted
inserted
replaced
215:34e36dffd47a | 216:5697a3f7c8cf |
---|---|
320 *to = 0; | 320 *to = 0; |
321 | 321 |
322 return path; | 322 return path; |
323 } | 323 } |
324 | 324 |
325 // Ensure entire path exists. | |
326 // If mode != -1 set permissions on newly created dirs. | |
327 // Requires that path string be writable (for temporary null terminators). | |
328 void xmkpath(char *path, int mode) | |
329 { | |
330 char *p, old; | |
331 mode_t mask; | |
332 int rc; | |
333 struct stat st; | |
334 | |
335 for (p = path; ; p++) { | |
336 if (!*p || *p == '/') { | |
337 old = *p; | |
338 *p = rc = 0; | |
339 if (stat(path, &st) || !S_ISDIR(st.st_mode)) { | |
340 if (mode != -1) { | |
341 mask=umask(0); | |
342 rc = mkdir(path, mode); | |
343 umask(mask); | |
344 } else rc = mkdir(path, 0777); | |
345 } | |
346 *p = old; | |
347 if(rc) perror_exit("mkpath '%s'",path); | |
348 } | |
349 if (!*p) break; | |
350 } | |
351 } | |
325 // Find all file in a colon-separated path with access type "type" (generally | 352 // Find all file in a colon-separated path with access type "type" (generally |
326 // X_OK or R_OK). Returns a list of absolute paths to each file found, in | 353 // X_OK or R_OK). Returns a list of absolute paths to each file found, in |
327 // order. | 354 // order. |
328 | 355 |
329 struct string_list *find_in_path(char *path, char *filename) | 356 struct string_list *find_in_path(char *path, char *filename) |