Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

os_truncate.c

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 2004-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: os_truncate.c,v 12.2 2005/08/10 15:47:27 bostic Exp $
00008  */
00009 
00010 #include "db_config.h"
00011 
00012 #ifndef NO_SYSTEM_INCLUDES
00013 #include <sys/types.h>
00014 
00015 #include <string.h>
00016 #endif
00017 
00018 #include "db_int.h"
00019 
00020 /*
00021  * __os_truncate --
00022  *      Truncate the file.
00023  *
00024  * PUBLIC: int __os_truncate __P((DB_ENV *, DB_FH *, db_pgno_t, u_int32_t));
00025  */
00026 int
00027 __os_truncate(dbenv, fhp, pgno, pgsize)
00028         DB_ENV *dbenv;
00029         DB_FH *fhp;
00030         db_pgno_t pgno;
00031         u_int32_t pgsize;
00032 {
00033         off_t offset;
00034         int ret;
00035 
00036         /*
00037          * Truncate a file so that "pgno" is discarded from the end of the
00038          * file.
00039          */
00040         offset = (off_t)pgsize * pgno;
00041 
00042         if (DB_GLOBAL(j_ftruncate) != NULL)
00043                 ret = DB_GLOBAL(j_ftruncate)(fhp->fd, offset);
00044         else {
00045 #ifdef HAVE_FTRUNCATE
00046                 RETRY_CHK((ftruncate(fhp->fd, offset)), ret);
00047 #else
00048                 ret = DB_OPNOTSUP;
00049 #endif
00050         }
00051 
00052         if (ret != 0)
00053                 __db_err(dbenv,
00054                     "ftruncate: %lu: %s", (u_long)offset, strerror(ret));
00055 
00056         return (ret);
00057 }

Generated on Sun Dec 25 12:14:42 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2