new: working on the gen command
This commit is contained in:
38
src/util.c
38
src/util.c
@ -8,6 +8,8 @@
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "error.h"
|
||||
#include "intl.h"
|
||||
#include "util.h"
|
||||
|
||||
bool eq(char *s1, char *s2) {
|
||||
@ -109,16 +111,22 @@ bool mksubdirsp(char *path, int perms) {
|
||||
for (char *c = path; *c != '\0'; c++) {
|
||||
if (*c == '/' && indx != 0) {
|
||||
cur[indx] = '\0';
|
||||
if (!exists(cur) && mkdir(cur, perms) < 0)
|
||||
if (!exists(cur) && mkdir(cur, perms) < 0){
|
||||
error_set(_("Failed to create directory: %s"), cur);
|
||||
errno = MkdirFail;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
cur[indx] = *c;
|
||||
indx++;
|
||||
}
|
||||
|
||||
if (!exists(cur) && mkdir(cur, perms) < 0)
|
||||
if (!exists(cur) && mkdir(cur, perms) < 0){
|
||||
error_set(_("Failed to create directory: %s"), cur);
|
||||
errno = MkdirFail;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -187,3 +195,29 @@ void clist_add(clist_t *l, char *en) {
|
||||
l->c[l->s] = en;
|
||||
l->s++;
|
||||
}
|
||||
|
||||
bool copyfile(char *src, char *dst){
|
||||
FILE *srcf = fopen(src, "r");
|
||||
FILE *dstf = fopen(dst, "w");
|
||||
|
||||
if(NULL == srcf || NULL == dstf){
|
||||
if(NULL == srcf)
|
||||
error_set(_("Failed to open \"%s\" for reading"), srcf);
|
||||
else
|
||||
error_set(_("Failed to open \"%s\" for writing"), dstf);
|
||||
errno = OpenFail;
|
||||
return false;
|
||||
}
|
||||
|
||||
char buffer[32];
|
||||
int read = -1;
|
||||
|
||||
bzero(buffer, 32);
|
||||
|
||||
while((read = fread(buffer, 1, 32, srcf)) > 0)
|
||||
fwrite(buffer, 1, read, dstf);
|
||||
|
||||
fclose(srcf);
|
||||
fclose(dstf);
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user