Get rid of E_OSL_STAT.
[osl.git] / osl.c
diff --git a/osl.c b/osl.c
index f0506a50821f1d095ec543a655022d46ece212bf..44e09d07ad20a179c111f06503ec4415c534e61e 100644 (file)
--- 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;
        }