ReactOS  0.4.14-dev-384-g5b37caa
rcopy.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4 
5 #if defined (__DJGPP__) || defined (__WIN32__)
6 #define DOS_PATHS
7 #else
8 #define UNIX_PATHS
9 #endif
10 
11 char* convert_path(char* origpath)
12 {
13  char* newpath;
14  int i;
15 
16  newpath = strdup(origpath);
17 
18  i = 0;
19  while (newpath[i] != 0)
20  {
21 #ifdef UNIX_PATHS
22  if (newpath[i] == '\\')
23  {
24  newpath[i] = '/';
25  }
26 #else
27 #ifdef DOS_PATHS
28  if (newpath[i] == '/')
29  {
30  newpath[i] = '\\';
31  }
32 #endif
33 #endif
34  i++;
35  }
36  return(newpath);
37 }
38 
39 #define TRANSFER_SIZE (65536)
40 
41 int main(int argc, char* argv[])
42 {
43  char* path1;
44  char* path2;
45  FILE* in;
46  FILE* out;
47  char* buf;
48  int n_in;
49  int n_out;
50 
51  if (argc != 3)
52  {
53  fprintf(stderr, "Too many arguments\n");
54  exit(1);
55  }
56 
57  path1 = convert_path(argv[1]);
58  path2 = convert_path(argv[2]);
59 
60  in = fopen(path1, "rb");
61  if (in == NULL)
62  {
63  perror("Cannot open input file");
64  exit(1);
65  }
66 
67 
68 
69  out = fopen(path2, "wb");
70  if (out == NULL)
71  {
72  perror("Cannot open output file");
73  fclose(in);
74  exit(1);
75  }
76 
78 
79  while (!feof(in))
80  {
81  n_in = fread(buf, 1, TRANSFER_SIZE, in);
82  n_out = fwrite(buf, 1, n_in, out);
83  if (n_in != n_out)
84  {
85  perror("Failed to write to output file\n");
86  free(buf);
87  fclose(in);
88  fclose(out);
89  exit(1);
90  }
91  }
92  exit(0);
93 }
static const WCHAR path2[]
Definition: path.c:29
static int argc
Definition: ServiceArgs.c:12
#define TRANSFER_SIZE
Definition: rcopy.c:39
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define free
Definition: debug_ros.c:5
_Check_return_opt_ _CRTIMP size_t __cdecl fwrite(_In_reads_bytes_(_Size *_Count) const void *_Str, _In_ size_t _Size, _In_ size_t _Count, _Inout_ FILE *_File)
#define argv
Definition: mplay32.c:18
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_Check_return_opt_ _CRTIMP size_t __cdecl fread(_Out_writes_bytes_(_ElementSize *_Count) void *_DstBuf, _In_ size_t _ElementSize, _In_ size_t _Count, _Inout_ FILE *_File)
_CRTIMP void __cdecl perror(_In_opt_z_ const char *_ErrMsg)
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
_Check_return_ _CRTIMP char *__cdecl strdup(_In_opt_z_ const char *_Src)
smooth NULL
Definition: ftsmooth.c:416
static const WCHAR path1[]
Definition: path.c:28
_Check_return_ _CRTIMP int __cdecl feof(_In_ FILE *_File)
static FILE * out
Definition: regtests2xml.c:44
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
GLuint in
Definition: glext.h:9616
int main(int argc, char *argv[])
Definition: rcopy.c:41
char * convert_path(char *origpath)
Definition: rcopy.c:11
FILE * stderr
#define malloc
Definition: debug_ros.c:4
void exit(int exitcode)
Definition: _exit.c:33