1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-10-27 01:55:10 +03:00

dm_fclose: new function

* lib/libdevmapper.h: Declare it.
* lib/libdm-file.c (dm_fclose): Define it.
* lib/.exported_symbols: Add dm_fclose.
This commit is contained in:
Jim Meyering 2007-07-24 14:15:45 +00:00
parent b07dabbe80
commit 0c3cd7e292
4 changed files with 31 additions and 0 deletions

View File

@ -1,5 +1,6 @@
Version 1.02.22 -
================================
dm_fclose: new function
Version 1.02.21 - 13th July 2007
================================

View File

@ -1,6 +1,7 @@
dm_lib_release
dm_lib_exit
dm_driver_version
dm_fclose
dm_get_library_version
dm_log
dm_log_init

View File

@ -27,6 +27,7 @@
#include <limits.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
/*****************************************************************
* The first section of this file provides direct access to the
@ -623,6 +624,21 @@ int dm_snprintf(char *buf, size_t bufsize, const char *format, ...);
*/
char *dm_basename(const char *path);
/**************************
* file/stream manipulation
**************************/
/*
* Close a stream, with nicer error checking than fclose's.
* Derived from gnulib's close-stream.c.
*
* Close "stream". Return 0 if successful, and EOF (setting errno)
* otherwise. Upon failure, set errno to 0 if the error number
* cannot be determined. Useful mainly for writable streams.
*/
int dm_fclose(FILE *stream);
/*
* Returns size of a buffer which is allocated with dm_malloc.
* Pointer to the buffer is stored in *buf.

View File

@ -72,3 +72,16 @@ int create_dir(const char *dir)
return 0;
}
int dm_fclose(FILE *stream)
{
int prev_fail = ferror(stream);
int fclose_fail = fclose(stream);
/* If there was a previous failure, but fclose succeeded,
clear errno, since ferror does not set it, and its value
may be unrelated to the ferror-reported failure. */
if (prev_fail && !fclose_fail)
errno = 0;
return prev_fail || fclose_fail ? EOF : 0;
}