home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
listings
/
v_10_11
/
1011088a
< prev
next >
Wrap
Text File
|
1992-10-05
|
1KB
|
47 lines
#define STS_OK 0
#define STS_BAD_LEN -10
#define STS_ERROR -1
extern int
truncate_file (char * path, long len)
{
int infile, tmp_file; /* input file */
int ret = STS_OK;
char tf_name [L_tmpnam];
do {
if (len < 0>
{
ret = STS_BAD_LENGTH;
break;
}
if (len == 0)
{
ret = truncate_to_zero (path);
break;
}
if ((infile = open (path, O_RDONLY, 0)) < 0)
{
ret = STS_ERROR;
break;
}
if (file_len (infile) <= len)
{
close (infile);
ret = STS_SMALL_FILE;
break;
}
/* after all error conditions are checked, we finally do
some real work here */
tmpnam (tf_name);
tmp_file = open (tf_name, O_RDWR | 0_CREAT, 0666);
ret = copy_file (infile, tmp_file, path, len);
unlink (tf_name);
} while (FALSE);
return (ret);
}