comparison src/util.c @ 206:eb2589384836 noffle

[svn] * TODO: Update the TODO list. * src/util.c: When updating timestamp files, write new stamp to temp file and rename, so failure with e.g. full disc doesn't leave an empty stamp file.
author bears
date Wed, 14 Nov 2001 10:56:42 +0000
parents 027608dbd16b
children ffb1848a39db
comparison
equal deleted inserted replaced
205:a47b47cc1e9d 206:eb2589384836
1 /* 1 /*
2 util.c 2 util.c
3 3
4 $Id: util.c 321 2001-11-11 03:53:07Z mirkol $ 4 $Id: util.c 325 2001-11-14 10:56:42Z bears $
5 */ 5 */
6 6
7 #if HAVE_CONFIG_H 7 #if HAVE_CONFIG_H
8 #include <config.h> 8 #include <config.h>
9 #endif 9 #endif
241 void 241 void
242 Utl_stamp( Str file ) 242 Utl_stamp( Str file )
243 { 243 {
244 FILE *f; 244 FILE *f;
245 time_t t; 245 time_t t;
246 246 Str tmpfname;
247
248 snprintf( tmpfname, MAXCHAR, "%s/.#%d.stamp.update",
249 Cfg_spoolDir(), (int) getpid() );
247 time( &t ); 250 time( &t );
248 if ( ! ( f = fopen( file, "w" ) ) ) 251 if ( ! ( f = fopen( tmpfname, "w" ) ) )
249 { 252 {
250 Log_err( "Could not open %s for writing (%s)", 253 Log_err( "Could not open %s for writing (%s)",
251 file, strerror( errno ) ); 254 tmpfname, strerror( errno ) );
252 return; 255 return;
253 } 256 }
254 fprintf( f, "%lu\n", t ); 257 fprintf( f, "%lu\n", t );
255 fclose( f ); 258 fclose( f );
259 if ( ferror( f ) )
260 {
261 Log_err( "Error stamping into file %s: %s",
262 tmpfname, strerror( errno ) );
263
264 }
265 else
266 {
267 if ( rename( tmpfname, file ) < 0 )
268 Log_err( "Rename of stamp file %s to %s failed: %s",
269 tmpfname, file, strerror( errno ) );
270 }
256 } 271 }
257 272
258 Bool 273 Bool
259 Utl_getStamp( time_t *result, Str file ) 274 Utl_getStamp( time_t *result, Str file )
260 { 275 {