Debian Codegraph @

libsrc/os/unix/osfdate.c

raw
1 /*===========================================================================
2 Copyright (C) 1988-2009 European Southern Observatory (ESO)
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2 of
7 the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public
15 License along with this program; if not, write to the Free
16 Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
17 MA 02139, USA.
18
19 Correspondence concerning ESO-MIDAS should be addressed as follows:
20 Internet e-mail: [email protected]
21 Postal address: European Southern Observatory
22 Data Management Division
23 Karl-Schwarzschild-Strasse 2
24 D 85748 Garching bei Muenchen
25 GERMANY
26 ===========================================================================*/
27
28 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29 .TYPE Module
30 .NAME osfdate.c
31 .LANGUAGE C
32 .AUTHOR IPG-ESO Garching
33 .CATEGORY Host operating system interfaces. File management.
34 .ENVIRONMENT UNIX (BSD / SYSV)
35 .COMMENTS
36 Date of last modification of a file.
37 .VERSION 1.0 04-Oct-1988 F. Ochsenbein
38
39 090324 last modif
40 -----------------------------------------------*/
41
42 #define DEBUG 0 /* Set to 1 for Debugging Option */
43
44 #include <osdefos.h> /* OS Midas definitions */
45 #include <errno.h> /* System error definitions */
46 #include <oserror.h> /* Midas error definitions */
47 #include <unistd.h> /* Midas error definitions */
48 #include <sys/types.h>
49 #include <sys/stat.h>
50 #include <proto_os.h> /* ANSI-C prototyping */
51
52 #ifndef F_OK
53 #define F_OK 0
54 #endif
55
56 #define RETURN(x) FIN: return(oserror ? -1 : x)
57 #define FINISH goto FIN
58
59 static struct stat buf;
60
61
62 /*======================================================================*/
63 /* ARGSUSED */
64 #ifdef __STDC__
65 int osfop(char fmt, int length)
66 #else
67 int osfop(fmt, length)
68 /*++++++++
69 .PURPOSE Initializes the Format for the next Open / Create
70 .RETURNS 0
71 .REMARKS Only for VMS (useless in Unix context)
72 ------------------------------------------------------------*/
73 char fmt; /* IN : 'f' for Fixed, 'v' for Variable */
74 int length; /* IN : Length of longest record */
75 #endif
76 {
77 return(0);
78 }
79
80 /*======================================================================*/
81 int osfunix(/*filename*/)
82 /*++++++++
83 .PURPOSE Tells if a file is Unix--compatible
84 .RETURNS 1 (always valid)
85 .REMARKS Only for VMS compatibility
86 ------------------------------------------------------------*/
87 /*char *filename;*/ /* IN : File to Check */
88 {
89 return(1);
90 }
91
92 /*==========================================================================*/
93 long int osfdate(phname)
94 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
95 .PURPOSE Retrieve last modification date of a file.
96 .RETURNS The date in seconds
97 .REMARKS
98 ------------------------------------------------------------*/
99 char *phname; /* IN : physical filename */
100 {
101 oserror = 0;
102
103 if (access(phname,F_OK) != 0) { oserror = ENOENT; FINISH; }
104 /* Check for accessibility of file first */
105
106 if (stat(phname,&buf) != 0) { oserror = errno; FINISH; }
107
108 FIN:
109 #if DEBUG
110 printf("Date of file %s = %d(oserror=%d)\n", phname, buf.st_mtime,oserror);
111 #endif
112 return(oserror ? -1L : buf.st_mtime);
113 }
114
115 /*==========================================================================*/
116 long int osfsize(phname)
117 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
118 .PURPOSE Get the size of a file.
119 .RETURNS Size of file in bytes (-1 if file does not exist).
120 .REMARKS
121 ------------------------------------------------------------*/
122 char *phname; /* IN : physical filename */
123 {
124
125 oserror = 0;
126
127 if (access(phname,F_OK) != 0) { oserror = ENOENT; FINISH; }
128 /* Check for accessibility of file first */
129
130 if (stat(phname,&buf) != 0) { oserror = errno; FINISH; }
131
132 FIN:
133 return(oserror ? -1L : buf.st_size);
134 }
135