Update.
[glibc.git] / db2 / os / os_stat.c
blobe7d3f241746306bd422c9472d7fce76d9a2cfbe0
1 /*-
2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 1997, 1998
5 * Sleepycat Software. All rights reserved.
6 */
8 #include "config.h"
10 #ifndef lint
11 static const char sccsid[] = "@(#)os_stat.c 10.15 (Sleepycat) 4/27/98";
12 #endif /* not lint */
14 #ifndef NO_SYSTEM_INCLUDES
15 #include <sys/types.h>
16 #include <sys/stat.h>
18 #include <errno.h>
19 #endif
21 #include "db_int.h"
24 * __os_exists --
25 * Return if the file exists.
27 * PUBLIC: int __os_exists __P((const char *, int *));
29 int
30 __os_exists(path, isdirp)
31 const char *path;
32 int *isdirp;
34 struct stat sb;
36 if (stat(path, &sb) != 0)
37 return (errno);
39 #if !defined(S_ISDIR) || defined(STAT_MACROS_BROKEN)
40 #if defined(_WIN32) || defined(WIN16)
41 #define S_ISDIR(m) (_S_IFDIR & (m))
42 #else
43 #define S_ISDIR(m) (((m) & 0170000) == 0040000)
44 #endif
45 #endif
46 if (isdirp != NULL)
47 *isdirp = S_ISDIR(sb.st_mode);
49 return (0);
53 * __os_ioinfo --
54 * Return file size and I/O size; abstracted to make it easier
55 * to replace.
57 * PUBLIC: int __os_ioinfo
58 * PUBLIC: __P((const char *, int, u_int32_t *, u_int32_t *, u_int32_t *));
60 int
61 __os_ioinfo(path, fd, mbytesp, bytesp, iosizep)
62 const char *path;
63 int fd;
64 u_int32_t *mbytesp, *bytesp, *iosizep;
66 struct stat sb;
68 COMPQUIET(path, NULL);
70 if (fstat(fd, &sb) == -1)
71 return (errno);
73 /* Return the size of the file. */
74 if (mbytesp != NULL)
75 *mbytesp = sb.st_size / MEGABYTE;
76 if (bytesp != NULL)
77 *bytesp = sb.st_size % MEGABYTE;
80 * Return the underlying filesystem blocksize, if available.
82 * XXX
83 * Check for a 0 size -- HP's MPE architecture has st_blksize,
84 * but it's always 0.
86 #ifdef HAVE_ST_BLKSIZE
87 if (iosizep != NULL && (*iosizep = sb.st_blksize) == 0)
88 *iosizep = DB_DEF_IOSIZE;
89 #else
90 if (iosizep != NULL)
91 *iosizep = DB_DEF_IOSIZE;
92 #endif
93 return (0);