VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstMove.cpp@ 3672

Last change on this file since 3672 was 2981, checked in by vboxsync, 17 years ago

InnoTek -> innotek: all the headers and comments.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.2 KB
Line 
1/* $Id: tstMove.cpp 2981 2007-06-01 16:01:28Z vboxsync $ */
2/** @file
3 * innotek Portable Runtime - RTFileMove & RTDirMove test program.
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek GmbH
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22/*******************************************************************************
23* Header Files *
24*******************************************************************************/
25#include <iprt/file.h>
26#include <iprt/path.h>
27#include <iprt/dir.h>
28#include <iprt/err.h>
29#include <iprt/runtime.h>
30#include <iprt/stream.h>
31
32
33/**
34 * Checks if there is one of the typical help options in the argument list.
35 */
36static bool HasHelpOption(int argc, char **argv)
37{
38 for (int argi = 1; argi < argc; argi++)
39 if ( argv[argi][0] == '-'
40 && ( argv[argi][1] == 'h'
41 || argv[argi][1] == 'H'
42 || argv[argi][1] == '?'
43 || argv[argi][1] == '-')
44 )
45 return true;
46 return false;
47}
48
49
50int main(int argc, char **argv)
51{
52 RTR3Init();
53
54 /*
55 * Arguments or any -? or --help?
56 */
57 if (argc <= 1 || HasHelpOption(argc, argv))
58 {
59 RTPrintf("usage: tstMove [-efdr] <src> <dst>\n"
60 "\n"
61 " -f File only.\n"
62 " -d Directory only.\n"
63 " -m Use move operation instead of rename. (implies -f)\n"
64 " -r Replace existing destination.\n"
65 );
66 return 1;
67 }
68
69 /*
70 * Parse args.
71 */
72 const char *pszNew = NULL;
73 const char *pszOld = NULL;
74 bool fDir = false;
75 bool fFile = false;
76 bool fReplace = false;
77 bool fMoveFile = false;
78 for (int argi = 1; argi < argc; argi++)
79 {
80 if (argv[argi][0] == '-')
81 {
82 const char *psz = &argv[argi][1];
83 do
84 {
85 switch (*psz)
86 {
87 case 'd':
88 fDir = true;
89 fMoveFile = false;
90 break;
91 case 'f':
92 fFile = true;
93 break;
94 case 'm':
95 fMoveFile = true;
96 fDir = false;
97 fFile = true;
98 break;
99 case 'r':
100 fReplace = true;
101 break;
102 default:
103 RTPrintf("tstRTFileMove: syntax error: Unknown option '%c' in '%s'!\n", *psz, argv[argi]);
104 return 1;
105 }
106 } while (*++psz);
107 }
108 else if (!pszOld)
109 pszOld = argv[argi];
110 else if (!pszNew)
111 pszNew = argv[argi];
112 else
113 {
114 RTPrintf("tstRTFileMove: syntax error: too many filenames!\n");
115 return 1;
116 }
117 }
118 if (!pszNew || !pszOld)
119 {
120 RTPrintf("tstRTFileMove: syntax error: too few filenames!\n");
121 return 1;
122 }
123
124 /*
125 * Do the operation.
126 */
127 int rc;
128 if (!fDir && !fFile)
129 rc = RTPathRename(pszOld, pszNew, fReplace ? RTPATHRENAME_FLAGS_REPLACE : 0);
130 else if (fDir)
131 rc = RTDirRename( pszOld, pszNew, fReplace ? RTPATHRENAME_FLAGS_REPLACE : 0);
132 else if (!fMoveFile)
133 rc = RTFileRename(pszOld, pszNew, fReplace ? RTPATHRENAME_FLAGS_REPLACE : 0);
134 else
135 rc = RTFileMove( pszOld, pszNew, fReplace ? RTFILEMOVE_FLAGS_REPLACE : 0);
136
137 RTPrintf("The API returned %Rrc\n", rc);
138 return !RT_SUCCESS(rc);
139}
140
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette