db

os_stat.c

Go to the documentation of this file.
00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1997, 1998, 1999, 2000
00005  * Sleepycat Software. All rights reserved.
00006  */
00007 
00008 #include "config.h"
00009 
00010 #ifndef lint
00011 static const char revid[] = "$Id: os__stat_8c-source.html,v 1.1 2008年06月08日 10:21:32 sebdiaz Exp $";
00012 #endif /* not lint */
00013 
00014 #ifndef NO_SYSTEM_INCLUDES
00015 #include <sys/types.h>
00016 #include <sys/stat.h>
00017 #include <string.h>
00018 #endif
00019 
00020 #include "db_int.h"
00021 #include "os_jump.h"
00022 
00023 /*
00024  * CDB___os_exists --
00025  * Return if the file exists.
00026  *
00027  * PUBLIC: int CDB___os_exists __P((const char *, int *));
00028  */
00029 int
00030 CDB___os_exists(path, isdirp)
00031 const char *path;
00032 int *isdirp;
00033 {
00034 struct stat sb;
00035 
00036 if (CDB___db_jump.j_exists != NULL)
00037 return (CDB___db_jump.j_exists(path, isdirp));
00038 
00039 if (stat(path, &sb) != 0)
00040 return (CDB___os_get_errno());
00041 
00042 #if !defined(S_ISDIR) || defined(STAT_MACROS_BROKEN)
00043 #if defined(_WIN32) || defined(WIN16)
00044 #define S_ISDIR(m) (_S_IFDIR & (m))
00045 #else
00046 #define S_ISDIR(m) (((m) & 0170000) == 0040000)
00047 #endif
00048 #endif
00049 if (isdirp != NULL)
00050 *isdirp = S_ISDIR(sb.st_mode);
00051 
00052 return (0);
00053 }
00054 
00055 /*
00056  * CDB___os_ioinfo --
00057  * Return file size and I/O size; abstracted to make it easier
00058  * to replace.
00059  *
00060  * PUBLIC: int CDB___os_ioinfo __P((DB_ENV *, const char *,
00061  * PUBLIC: DB_FH *, u_int32_t *, u_int32_t *, u_int32_t *));
00062  */
00063 int
00064 CDB___os_ioinfo(dbenv, path, fhp, mbytesp, bytesp, iosizep)
00065 DB_ENV *dbenv;
00066 const char *path;
00067 DB_FH *fhp;
00068 u_int32_t *mbytesp, *bytesp, *iosizep;
00069 {
00070 int ret;
00071 struct stat sb;
00072 
00073 if (CDB___db_jump.j_ioinfo != NULL)
00074 return (CDB___db_jump.j_ioinfo(path,
00075 fhp->fd, mbytesp, bytesp, iosizep));
00076 
00077 if (fstat(fhp->fd, &sb) == -1) {
00078 ret = CDB___os_get_errno();
00079 CDB___db_err(dbenv, "fstat: %s", strerror(ret));
00080 return (ret);
00081 }
00082 
00083 /* Return the size of the file. */
00084 if (mbytesp != NULL)
00085 *mbytesp = sb.st_size / MEGABYTE;
00086 if (bytesp != NULL)
00087 *bytesp = sb.st_size % MEGABYTE;
00088 
00089 /*
00090  * Return the underlying filesystem blocksize, if available.
00091  *
00092  * XXX
00093  * Check for a 0 size -- the HP MPE/iX architecture has st_blksize,
00094  * but it's always 0.
00095  */
00096 #ifdef HAVE_ST_BLKSIZE
00097 if (iosizep != NULL && (*iosizep = sb.st_blksize) == 0)
00098 *iosizep = DB_DEF_IOSIZE;
00099 #else
00100 if (iosizep != NULL)
00101 *iosizep = DB_DEF_IOSIZE;
00102 #endif
00103 return (0);
00104 }

Generated on Sun Jun 8 10:56:38 2008 for GNUmifluz by doxygen 1.5.5

AltStyle によって変換されたページ (->オリジナル) /