move checked FILE functions to util.c
while they are used only in sync.c, they are conceptually low-level.
This commit is contained in:
		
							parent
							
								
									6f023376a1
								
							
						
					
					
						commit
						7d02d6c1fe
					
				
					 3 changed files with 39 additions and 35 deletions
				
			
		| 
						 | 
					@ -141,6 +141,14 @@ void ATTR_PRINTFLIKE(1, 0) vsys_error( const char *, va_list va );
 | 
				
			||||||
void ATTR_PRINTFLIKE(1, 2) sys_error( const char *, ... );
 | 
					void ATTR_PRINTFLIKE(1, 2) sys_error( const char *, ... );
 | 
				
			||||||
void flushn( void );
 | 
					void flushn( void );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if !defined(_POSIX_SYNCHRONIZED_IO) || _POSIX_SYNCHRONIZED_IO <= 0
 | 
				
			||||||
 | 
					# define fdatasync fsync
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void ATTR_PRINTFLIKE(2, 0) vFprintf( FILE *f, const char *msg, va_list va );
 | 
				
			||||||
 | 
					void ATTR_PRINTFLIKE(2, 3) Fprintf( FILE *f, const char *msg, ... );
 | 
				
			||||||
 | 
					void Fclose( FILE *f, int safe );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef struct string_list {
 | 
					typedef struct string_list {
 | 
				
			||||||
	struct string_list *next;
 | 
						struct string_list *next;
 | 
				
			||||||
	char string[1];
 | 
						char string[1];
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										35
									
								
								src/sync.c
									
										
									
									
									
								
							
							
						
						
									
										35
									
								
								src/sync.c
									
										
									
									
									
								
							| 
						 | 
					@ -14,10 +14,6 @@
 | 
				
			||||||
#include <errno.h>
 | 
					#include <errno.h>
 | 
				
			||||||
#include <sys/stat.h>
 | 
					#include <sys/stat.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if !defined(_POSIX_SYNCHRONIZED_IO) || _POSIX_SYNCHRONIZED_IO <= 0
 | 
					 | 
				
			||||||
# define fdatasync fsync
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define JOURNAL_VERSION "4"
 | 
					#define JOURNAL_VERSION "4"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
channel_conf_t global_conf;
 | 
					channel_conf_t global_conf;
 | 
				
			||||||
| 
						 | 
					@ -32,37 +28,6 @@ int trash_total[2], trash_done[2];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const char *str_fn[] = { "far side", "near side" }, *str_hl[] = { "push", "pull" };
 | 
					const char *str_fn[] = { "far side", "near side" }, *str_hl[] = { "push", "pull" };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					 | 
				
			||||||
Fclose( FILE *f, int safe )
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	if ((safe && (fflush( f ) || (UseFSync && fdatasync( fileno( f ) )))) || fclose( f ) == EOF) {
 | 
					 | 
				
			||||||
		sys_error( "Error: cannot close file" );
 | 
					 | 
				
			||||||
		exit( 1 );
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static void ATTR_PRINTFLIKE(2, 0)
 | 
					 | 
				
			||||||
vFprintf( FILE *f, const char *msg, va_list va )
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	int r;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	r = vfprintf( f, msg, va );
 | 
					 | 
				
			||||||
	if (r < 0) {
 | 
					 | 
				
			||||||
		sys_error( "Error: cannot write file" );
 | 
					 | 
				
			||||||
		exit( 1 );
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static void ATTR_PRINTFLIKE(2, 3)
 | 
					 | 
				
			||||||
Fprintf( FILE *f, const char *msg, ... )
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	va_list va;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	va_start( va, msg );
 | 
					 | 
				
			||||||
	vFprintf( f, msg, va );
 | 
					 | 
				
			||||||
	va_end( va );
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Keep the mailbox driver flag definitions in sync: */
 | 
					/* Keep the mailbox driver flag definitions in sync: */
 | 
				
			||||||
/* grep for MAILBOX_DRIVER_FLAG */
 | 
					/* grep for MAILBOX_DRIVER_FLAG */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										31
									
								
								src/util.c
									
										
									
									
									
								
							
							
						
						
									
										31
									
								
								src/util.c
									
										
									
									
									
								
							| 
						 | 
					@ -173,6 +173,37 @@ sys_error( const char *msg, ... )
 | 
				
			||||||
	va_end( va );
 | 
						va_end( va );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					vFprintf( FILE *f, const char *msg, va_list va )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int r;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						r = vfprintf( f, msg, va );
 | 
				
			||||||
 | 
						if (r < 0) {
 | 
				
			||||||
 | 
							sys_error( "Error: cannot write file" );
 | 
				
			||||||
 | 
							exit( 1 );
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					Fprintf( FILE *f, const char *msg, ... )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						va_list va;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						va_start( va, msg );
 | 
				
			||||||
 | 
						vFprintf( f, msg, va );
 | 
				
			||||||
 | 
						va_end( va );
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					Fclose( FILE *f, int safe )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if ((safe && (fflush( f ) || (UseFSync && fdatasync( fileno( f ) )))) || fclose( f ) == EOF) {
 | 
				
			||||||
 | 
							sys_error( "Error: cannot close file" );
 | 
				
			||||||
 | 
							exit( 1 );
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
add_string_list_n( string_list_t **list, const char *str, uint len )
 | 
					add_string_list_n( string_list_t **list, const char *str, uint len )
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue