/* * trunctest(): * Test file truncation. Verify that file truncates to expected size * and that the data in the file is as expected. */ int trunctest(char *fname, char *data) { int tfd, err, size; TFILE *tfp; /* Copy incoming file name to a tempoary file... */ cp(TMPFILE,fname); /* Open the temporary file and truncate it. * First verify that a truncation size too big will fail, then * do a real truncation. Close the file then verify that the * file has been trunated. */ tfd = mon_tfsopen(TMPFILE,TFS_APPEND,buffer1); if (tfd < 0) tfsdie(tfd); err = mon_tfstruncate(tfd,9999999); if (err != TFSERR_BADARG) tfsdie(err); err = mon_tfstruncate(tfd,TRUNCATE_SIZE); if (err != TFS_OKAY) tfsdie(err); err = mon_tfsclose(tfd,0); if (err < 0) tfsdie(err); /* Make sure that the file was truncated to the proper size. */ tfp = mon_tfsstat(TMPFILE); if (!tfp) die(); if (TFS_SIZE(tfp) != TRUNCATE_SIZE) die(); /* Now reopen the file and verify that the data is correct... */ tfd = mon_tfsopen(TMPFILE,TFS_RDONLY,0); if (tfd < 0) tfsdie(tfd); size = mon_tfsread(tfd,buffer1,TFS_SIZE(tfp)); if (size != TFS_SIZE(tfp)) tfsdie(size); if (memcmp(buffer1,data,TRUNCATE_SIZE)) die(); /* Close and remove the temporary file. */ mon_tfsclose(tfd,0); err = mon_tfsunlink(TMPFILE); if (err != TFS_OKAY) tfsdie(err); return(0); }
static int rtems_tfs_ftruncate( rtems_libio_t *iop, off_t count ) { int ret, fd; fd = (int) iop->data0; ret = mon_tfstruncate(tfdtable[fd].tfd,count); if (ret != TFS_OKAY) return(-1); return(0); }