mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-29 09:52:29 +01:00
WINGs: Make fetchFile() more similar to copyFile() from getstyle.c
The idea is to use the fetchFile() in getstyle.c and in wcolorpanel.c instead of using two very similar functions. In order to do that, let's move the most generic one (fetchFile()) to libWUtils, and this is the first step.
This commit is contained in:
@@ -3342,8 +3342,16 @@ static int fetchFile(char *toPath, char *srcFile, char *destFile)
|
||||
FILE *src, *dst;
|
||||
size_t nread, nwritten;
|
||||
char *dstpath;
|
||||
struct stat st;
|
||||
char buf[BUFSIZE];
|
||||
|
||||
/* only to a directory */
|
||||
if (stat(toPath, &st) != 0 || !S_ISDIR(st.st_mode))
|
||||
return -1;
|
||||
/* only copy files */
|
||||
if (stat(srcFile, &st) != 0 || !S_ISREG(st.st_mode))
|
||||
return -1;
|
||||
|
||||
RETRY( src = fopen(srcFile, "rb") )
|
||||
if (src == NULL) {
|
||||
werror(_("Could not open %s"), srcFile);
|
||||
@@ -3374,10 +3382,11 @@ static int fetchFile(char *toPath, char *srcFile, char *destFile)
|
||||
unlink(dstpath);
|
||||
|
||||
RETRY( fclose(src) )
|
||||
fchmod(fileno(dst), st.st_mode);
|
||||
fsync(fileno(dst));
|
||||
RETRY( fclose(dst) )
|
||||
|
||||
wfree(dstpath);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user