diff options
Diffstat (limited to 'c_pgms/truncate/truncate_file.c')
-rw-r--r-- | c_pgms/truncate/truncate_file.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/c_pgms/truncate/truncate_file.c b/c_pgms/truncate/truncate_file.c new file mode 100644 index 0000000..d6f0b60 --- /dev/null +++ b/c_pgms/truncate/truncate_file.c @@ -0,0 +1,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)); + } +} |