X-Git-Url: http://git.tuebingen.mpg.de/?p=osl.git;a=blobdiff_plain;f=osl.c;h=44e09d07ad20a179c111f06503ec4415c534e61e;hp=f0506a50821f1d095ec543a655022d46ece212bf;hb=3c96f3b4f7bb1be1c630085981e83eb0260b99a7;hpb=da40398fa79dc25801e7d276fd86da7439bd3e41 diff --git a/osl.c b/osl.c index f0506a5..44e09d0 100644 --- a/osl.c +++ b/osl.c @@ -44,7 +44,7 @@ __export const char *osl_strerror(int num) return msgstr.str + errmsgidx[num]; } -static int loglevel; +int loglevel = 0; static void __attribute ((constructor)) init_loglevel(void) { @@ -658,11 +658,12 @@ static int map_column(struct osl_table *t, unsigned col_num) { struct stat statbuf; char *filename = column_filename(t, col_num); - int ret = -E_OSL_STAT; + int ret; if (!filename) return -ERRNO_TO_ERROR(ENOMEM); - if (stat(filename, &statbuf) < 0) { + ret = osl_stat(filename, &statbuf); + if (ret < 0) { free(filename); return ret; } @@ -1178,37 +1179,6 @@ static int append_row_index(const struct osl_table *t, char *row_index) return ret; } -/** - * A wrapper for truncate(2) - * - * \param path Name of the regular file to truncate - * \param size Number of bytes to \b shave \b off - * - * Truncate the regular file named by \a path by \a size bytes. - * - * \return Standard. - * - * \sa truncate(2) - */ -int para_truncate(const char *path, off_t size) -{ - int ret; - struct stat statbuf; - - ret = -E_OSL_STAT; - if (stat(path, &statbuf) < 0) - goto out; - ret = -E_OSL_BAD_SIZE; - if (statbuf.st_size < size) - goto out; - ret = -E_OSL_TRUNC; - if (truncate(path, statbuf.st_size - size) < 0) - goto out; - ret = 1; -out: - return ret; -} - static int truncate_mapped_file(const struct osl_table *t, unsigned col_num, off_t size) { @@ -1217,7 +1187,7 @@ static int truncate_mapped_file(const struct osl_table *t, unsigned col_num, if (!filename) return -ERRNO_TO_ERROR(ENOMEM); - ret = para_truncate(filename, size); + ret = truncate_file(filename, size); free(filename); return ret; } @@ -1343,7 +1313,7 @@ __export int osl_add_and_get_row(struct osl_table *t, struct osl_object *objects if (ret < 0) { /* truncate index and rollback changes */ char *filename = index_filename(t->desc); if (filename) - para_truncate(filename, t->row_index_size); + truncate_file(filename, t->row_index_size); free(filename); goto rollback; }