summaryrefslogtreecommitdiffstats
path: root/c_pgms/truncate/truncate_file.c
blob: d6f0b6008296c3b3711eecd17c3f1f235932f00b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
#include <fcntl.h>

int main ()
{
        int     ret = -1;
        int     fd  = -1;
        char   *str = "This is a string";
        char    pwd[255] = {0, };

        getcwd (pwd, sizeof (pwd));

        strcat (pwd, "/test_file");

        ret = truncate (pwd, 10);
        if (ret == -1) {
                fprintf (stderr, "ERROR: truncate failed on the file %s (%s)",
                         pwd, strerror (errno));
        }
}