-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
yaml --- r: 182324 b: refs/heads/master c: 4cf4013 h: refs/heads/master v: v3
- Loading branch information
Arnaldo Carvalho de Melo
authored and
Ingo Molnar
committed
Dec 28, 2009
1 parent
536b54d
commit d415611
Showing
7 changed files
with
166 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
--- | ||
refs/heads/master: 55aa640f54280da25046acd2075842d464f451e6 | ||
refs/heads/master: 4cf40131a5cf4918e83b3756e58a1fc9e984f8ef |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#include <sys/mman.h> | ||
#include <sys/stat.h> | ||
#include <sys/types.h> | ||
#include <fcntl.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
#include "util.h" | ||
|
||
int mkdir_p(char *path, mode_t mode) | ||
{ | ||
struct stat st; | ||
int err; | ||
char *d = path; | ||
|
||
if (*d != '/') | ||
return -1; | ||
|
||
if (stat(path, &st) == 0) | ||
return 0; | ||
|
||
while (*++d == '/'); | ||
|
||
while ((d = strchr(d, '/'))) { | ||
*d = '\0'; | ||
err = stat(path, &st) && mkdir(path, mode); | ||
*d++ = '/'; | ||
if (err) | ||
return -1; | ||
while (*d == '/') | ||
++d; | ||
} | ||
return (stat(path, &st) && mkdir(path, mode)) ? -1 : 0; | ||
} | ||
|
||
int copyfile(const char *from, const char *to) | ||
{ | ||
int fromfd, tofd; | ||
struct stat st; | ||
void *addr; | ||
int err = -1; | ||
|
||
if (stat(from, &st)) | ||
goto out; | ||
|
||
fromfd = open(from, O_RDONLY); | ||
if (fromfd < 0) | ||
goto out; | ||
|
||
tofd = creat(to, 0755); | ||
if (tofd < 0) | ||
goto out_close_from; | ||
|
||
addr = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fromfd, 0); | ||
if (addr == MAP_FAILED) | ||
goto out_close_to; | ||
|
||
if (write(tofd, addr, st.st_size) == st.st_size) | ||
err = 0; | ||
|
||
munmap(addr, st.st_size); | ||
out_close_to: | ||
close(tofd); | ||
if (err) | ||
unlink(to); | ||
out_close_from: | ||
close(fromfd); | ||
out: | ||
return err; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters