From 5733cc4bcb436bbb7c676173c72db182ae00fab9 Mon Sep 17 00:00:00 2001 From: Raghavendra Bhat Date: Fri, 29 Jul 2011 12:56:59 +0530 Subject: programs to truncate a file based on path as well as fd. Can be enhanced to write some truncate based application. --- c_pgms/truncate/truncate_file.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 c_pgms/truncate/truncate_file.c (limited to 'c_pgms/truncate/truncate_file.c') 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 +#include +#include +#include +#include +#include +#include +#include + +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)); + } +} -- cgit