summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaghavendra Bhat <raghavendrabhat@gluster.com>2011-07-29 12:56:59 +0530
committerRaghavendra Bhat <raghavendrabhat@gluster.com>2011-07-29 12:56:59 +0530
commit5733cc4bcb436bbb7c676173c72db182ae00fab9 (patch)
treee652125d7e7346bdbce6896524b660f36b7832e0
parentbb3a674ba1965a71e31d40f1ae41eb833de53a31 (diff)
programs to truncate a file based on path as well as fd.
Can be enhanced to write some truncate based application.
-rw-r--r--INFO2
-rw-r--r--c_pgms/truncate/fd_truncate.c30
-rw-r--r--c_pgms/truncate/truncate_file.c26
3 files changed, 58 insertions, 0 deletions
diff --git a/INFO b/INFO
index 0da07cb..0120f94 100644
--- a/INFO
+++ b/INFO
@@ -21,6 +21,8 @@ c_pgms/threaded_io ---> program for opening a file from multiple threads and eac
c_pgms/create_bench(create.c) ---> benchmarking application for taking average time duration needed for the creation of different types of files such as regular file, directory, FIFO, character and block device special files
c_pgms/inotify.c ---> program which monitors a directory and sends mail whenever some files are created under it. Used for sending nightly sanity results.
+
+c_pgms/trucate ---> programs which truncates a file based on both path as well as fd on a file. Can be enhanced in future to write some truncate based applications. Used to verify bug 3077.
============================================================================================================================================
legacy/performance ---> legacy scripts (not currently in use) for getting performance statistics
diff --git a/c_pgms/truncate/fd_truncate.c b/c_pgms/truncate/fd_truncate.c
new file mode 100644
index 0000000..1425ed0
--- /dev/null
+++ b/c_pgms/truncate/fd_truncate.c
@@ -0,0 +1,30 @@
+#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, };
+
+ fd = open ("test_file", O_RDWR);
+ if (fd == -1) {
+ fprintf (stderr, "ERROR: open failed on the file test_file (%s)",
+ strerror (errno));
+ }
+ ret = ftruncate (fd, 10);
+ if (ret == -1) {
+ fprintf (stderr, "ERROR: truncate failed on the file %s (%s)",
+ pwd, strerror (errno));
+ }
+
+ if (fd > 0)
+ close (fd);
+}
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));
+ }
+}