2 * ========================================================================
3 * Copyright 2013-2022 Eduardo Chappa
4 * Copyright 2006 University of Washington
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * ========================================================================
16 #include "../charconv/utf8.h"
17 #include "../charconv/filesys.h"
21 /*----------------------------------------------------------------------
22 Return the number of bytes in given file
24 Args: file -- file name
26 Result: the number of bytes in the file is returned or
27 -1 on error, in which case errno is valid
30 name_file_size(char *file
)
34 if(our_stat(file
, &buffer
) != 0)
37 return((long)buffer
.st_size
);
41 /*----------------------------------------------------------------------
42 Return the number of bytes in given file
44 Args: fp -- FILE * for open file
46 Result: the number of bytes in the file is returned or
47 -1 on error, in which case errno is valid
50 fp_file_size(FILE *fp
)
54 if(fstat(fileno(fp
), &buffer
) != 0)
57 return((long)buffer
.st_size
);
61 /*----------------------------------------------------------------------
62 Return the modification time of given file
64 Args: file -- file name
66 Result: the time of last modification (mtime) of the file is returned or
67 -1 on error, in which case errno is valid
70 name_file_mtime(char *file
)
74 if(our_stat(file
, &buffer
) != 0)
77 return(buffer
.st_mtime
);
81 /*----------------------------------------------------------------------
82 Return the modification time of given file
84 Args: fp -- FILE * for open file
86 Result: the time of last modification (mtime) of the file is returned or
87 -1 on error, in which case errno is valid
90 fp_file_mtime(FILE *fp
)
94 if(fstat(fileno(fp
), &buffer
) != 0)
97 return(buffer
.st_mtime
);
101 /*----------------------------------------------------------------------
102 Copy the mode, owner, and group of sourcefile to targetfile.
107 We don't bother keeping track of success or failure because we don't care.
110 file_attrib_copy(char *targetfile
, char *sourcefile
)
114 if(our_stat(sourcefile
, &buffer
) == 0){
115 our_chmod(targetfile
, buffer
.st_mode
);
117 our_chown(targetfile
, buffer
.st_uid
, buffer
.st_gid
);