Add a copy file routine
Add io_file_cp() which can be used to copy an existing source file to another location. We will need this for our new hash-based note file names. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
parent
9dcb377a64
commit
c7b56ca556
@ -693,6 +693,7 @@ void io_set_lock (void);
|
|||||||
unsigned io_dump_pid (char *);
|
unsigned io_dump_pid (char *);
|
||||||
unsigned io_get_pid (char *);
|
unsigned io_get_pid (char *);
|
||||||
int io_file_is_empty (char *);
|
int io_file_is_empty (char *);
|
||||||
|
int io_file_cp (const char *, const char *);
|
||||||
|
|
||||||
/* keys.c */
|
/* keys.c */
|
||||||
void keys_init (void);
|
void keys_init (void);
|
||||||
|
33
src/io.c
33
src/io.c
@ -3050,3 +3050,36 @@ io_file_is_empty (char *file)
|
|||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copy an existing file to a new location.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
io_file_cp (const char *src, const char *dst)
|
||||||
|
{
|
||||||
|
FILE *fp_src, *fp_dst;
|
||||||
|
char *buffer[BUFSIZ];
|
||||||
|
unsigned int bytes_read;
|
||||||
|
|
||||||
|
if (!(fp_src = fopen (src, "rb")))
|
||||||
|
return 0;
|
||||||
|
if (!(fp_dst = fopen (dst, "wb")))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
while (!feof (fp_src))
|
||||||
|
{
|
||||||
|
bytes_read = fread (buffer, 1, BUFSIZ, fp_src);
|
||||||
|
if (bytes_read > 0)
|
||||||
|
{
|
||||||
|
if (fwrite (buffer, 1, bytes_read, fp_dst) != bytes_read)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose (fp_dst);
|
||||||
|
fclose (fp_src);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user