mirror of
https://github.com/gryf/wmaker.git
synced 2026-01-08 06:44:11 +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;
|
FILE *src, *dst;
|
||||||
size_t nread, nwritten;
|
size_t nread, nwritten;
|
||||||
char *dstpath;
|
char *dstpath;
|
||||||
|
struct stat st;
|
||||||
char buf[BUFSIZE];
|
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") )
|
RETRY( src = fopen(srcFile, "rb") )
|
||||||
if (src == NULL) {
|
if (src == NULL) {
|
||||||
werror(_("Could not open %s"), srcFile);
|
werror(_("Could not open %s"), srcFile);
|
||||||
@@ -3374,10 +3382,11 @@ static int fetchFile(char *toPath, char *srcFile, char *destFile)
|
|||||||
unlink(dstpath);
|
unlink(dstpath);
|
||||||
|
|
||||||
RETRY( fclose(src) )
|
RETRY( fclose(src) )
|
||||||
|
fchmod(fileno(dst), st.st_mode);
|
||||||
fsync(fileno(dst));
|
fsync(fileno(dst));
|
||||||
RETRY( fclose(dst) )
|
RETRY( fclose(dst) )
|
||||||
|
|
||||||
wfree(dstpath);
|
wfree(dstpath);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user