Universität Ulm,
SAI,
Übungen zu
Systemnahe Software I
Lösungsbeispiel zu Blatt 9 (Aufgabe 13): files
Systemabhängige Dateioperationen (Status).
/*
* files.h - Headerfile for SAM system dependent file status functions.
*
* Martin Hasch, University of Ulm, January 1997.
*/
#include "sam.h"
#define FILES_SUCCESS 0
#define FILES_FAILURE (-1)
/*
* Update header according to status of given file.
* On success return FILES_SUCCESS, otherwise FILES_FAILURE.
*/
int files_getinfo(char *filename, sam_Header *header);
/*
* files.c - SAM system dependent file status functions.
*
* Martin Hasch, University of Ulm, January 1997.
*/
#include <sys/types.h>
#include <sys/stat.h>
#include "sam.h"
#include "files.h"
/*
* Update header according to status of given file.
* On success return FILES_SUCCESS, otherwise FILES_FAILURE.
*/
int files_getinfo(char *filename, sam_Header *header)
{
struct stat statbuf;
if ( stat(filename, &statbuf) )
return FILES_FAILURE;
header->sam_size = (size_t) statbuf.st_size;
header->sam_time = statbuf.st_mtime;
return FILES_SUCCESS;
}
<- Alle Module
Martin Hasch, Februar 1997