1 #if !defined(lint) && !defined(DOS)
2 static char rcsid
[] = "$Id: filesize.c 761 2007-10-23 22:35:18Z hubert@u.washington.edu $";
6 * ========================================================================
7 * Copyright 2013-2018 Eduardo Chappa
8 * Copyright 2006 University of Washington
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * ========================================================================
20 #include "../charconv/utf8.h"
21 #include "../charconv/filesys.h"
25 /*----------------------------------------------------------------------
26 Return the number of bytes in given file
28 Args: file -- file name
30 Result: the number of bytes in the file is returned or
31 -1 on error, in which case errno is valid
34 name_file_size(char *file
)
38 if(our_stat(file
, &buffer
) != 0)
41 return((long)buffer
.st_size
);
45 /*----------------------------------------------------------------------
46 Return the number of bytes in given file
48 Args: fp -- FILE * for open file
50 Result: the number of bytes in the file is returned or
51 -1 on error, in which case errno is valid
54 fp_file_size(FILE *fp
)
58 if(fstat(fileno(fp
), &buffer
) != 0)
61 return((long)buffer
.st_size
);
65 /*----------------------------------------------------------------------
66 Return the modification time of given file
68 Args: file -- file name
70 Result: the time of last modification (mtime) of the file is returned or
71 -1 on error, in which case errno is valid
74 name_file_mtime(char *file
)
78 if(our_stat(file
, &buffer
) != 0)
81 return(buffer
.st_mtime
);
85 /*----------------------------------------------------------------------
86 Return the modification time of given file
88 Args: fp -- FILE * for open file
90 Result: the time of last modification (mtime) of the file is returned or
91 -1 on error, in which case errno is valid
94 fp_file_mtime(FILE *fp
)
98 if(fstat(fileno(fp
), &buffer
) != 0)
101 return(buffer
.st_mtime
);
105 /*----------------------------------------------------------------------
106 Copy the mode, owner, and group of sourcefile to targetfile.
111 We don't bother keeping track of success or failure because we don't care.
114 file_attrib_copy(char *targetfile
, char *sourcefile
)
118 if(our_stat(sourcefile
, &buffer
) == 0){
119 our_chmod(targetfile
, buffer
.st_mode
);
121 our_chown(targetfile
, buffer
.st_uid
, buffer
.st_gid
);