Add support for tab-completion when selecting by rule
[alpine.git] / pith / osdep / filesize.c
blob231f903ff37d529e4815aebec503c6c97361d6aa
1 /*
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 * ========================================================================
15 #include <system.h>
16 #include "../charconv/utf8.h"
17 #include "../charconv/filesys.h"
18 #include "filesize.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
28 ----*/
29 long
30 name_file_size(char *file)
32 struct stat buffer;
34 if(our_stat(file, &buffer) != 0)
35 return(-1L);
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
48 ----*/
49 long
50 fp_file_size(FILE *fp)
52 struct stat buffer;
54 if(fstat(fileno(fp), &buffer) != 0)
55 return(-1L);
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
68 ----*/
69 time_t
70 name_file_mtime(char *file)
72 struct stat buffer;
74 if(our_stat(file, &buffer) != 0)
75 return((time_t)(-1));
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
88 ----*/
89 time_t
90 fp_file_mtime(FILE *fp)
92 struct stat buffer;
94 if(fstat(fileno(fp), &buffer) != 0)
95 return((time_t)(-1));
97 return(buffer.st_mtime);
101 /*----------------------------------------------------------------------
102 Copy the mode, owner, and group of sourcefile to targetfile.
104 Args: targetfile --
105 sourcefile --
107 We don't bother keeping track of success or failure because we don't care.
108 ----*/
109 void
110 file_attrib_copy(char *targetfile, char *sourcefile)
112 struct stat buffer;
114 if(our_stat(sourcefile, &buffer) == 0){
115 our_chmod(targetfile, buffer.st_mode);
116 #if HAVE_CHOWN
117 our_chown(targetfile, buffer.st_uid, buffer.st_gid);
118 #endif