From 7e0f021a9aec35fd8e6725e87e3313b101d26f5e Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sun, 27 Jan 2008 11:37:44 +0100 Subject: Initial import (2.0.2-6) --- reference/C/CONTRIB/SNIP/doscopy.c | 58 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 reference/C/CONTRIB/SNIP/doscopy.c (limited to 'reference/C/CONTRIB/SNIP/doscopy.c') diff --git a/reference/C/CONTRIB/SNIP/doscopy.c b/reference/C/CONTRIB/SNIP/doscopy.c new file mode 100755 index 0000000..2725c60 --- /dev/null +++ b/reference/C/CONTRIB/SNIP/doscopy.c @@ -0,0 +1,58 @@ +/*************************************************** + * function : copy * + * purpose : copy one file * + * * + * arguments: path to source 'fromDir', * + * path to target 'toDir', * + * filename to copy 'fname' * + * * + * returns : nothing * + * * + * By : Peter Yard (29 May 1991) * + ***************************************************/ + +#include +#include +#include +#include + +void pmerge(char *path, char *drive, char *dir, char *fname, char *ext); + +#define STDOUT fileno(stdout) + +void copy(char *fromDir, char *fname, char *toDir) +{ + FILE *nul; /* nul will redirect stdout to DOS 'nul' */ + char from[FILENAME_MAX], to[FILENAME_MAX], comd[128]; + int bytesRead, oldStdout; + + /* Create the strings to describe the paths */ + + pmerge(from, NULL, fromDir, fname, NULL); + pmerge(to, NULL, toDir, fname, NULL); + + /* Construct 'comd' string which is a dos command for a copy */ + + strcpy(comd, "copy "); + strcat(comd, from); strcat(comd, " "); + strcat(comd, to); + + /* Redirect stdout to a nul file, kills output to the screen */ + + nul = fopen("NUL", "w"); + oldStdout = dup(STDOUT); + dup2(fileno(nul), STDOUT); + fclose(nul); + + system(comd); /* COPY file */ + + /* Restore stdout and close nul file */ + + dup2(oldStdout, STDOUT); + close(oldStdout); + + /* Display file source and target, */ + /* otherwise comment out the next line. */ + + printf("\n%s copied to %s",from,to); +} -- cgit v1.2.3-54-g00ecf