VirtualBox

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

Last change on this file since 32970 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.4 KB
Line 
1/* $Id: tstMove.cpp 28800 2010-04-27 08:22:32Z vboxsync $ */
2/** @file
3 * IPRT - RTFileMove & RTDirMove test program.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Oracle Corporation
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 (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27/*******************************************************************************
28* Header Files *
29*******************************************************************************/
30#include <iprt/file.h>
31#include <iprt/path.h>
32#include <iprt/dir.h>
33#include <iprt/err.h>
34#include <iprt/initterm.h>
35#include <iprt/stream.h>
36
37
38/**
39 * Checks if there is one of the typical help options in the argument list.
40 */
41static bool HasHelpOption(int argc, char **argv)
42{
43 for (int argi = 1; argi < argc; argi++)
44 if ( argv[argi][0] == '-'
45 && ( argv[argi][1] == 'h'
46 || argv[argi][1] == 'H'
47 || argv[argi][1] == '?'
48 || argv[argi][1] == '-')
49 )
50 return true;
51 return false;
52}
53
54
55int main(int argc, char **argv)
56{
57 RTR3Init();
58
59 /*
60 * Arguments or any -? or --help?
61 */
62 if (argc <= 1 || HasHelpOption(argc, argv))
63 {
64 RTPrintf("usage: tstMove [-efdr] <src> <dst>\n"
65 "\n"
66 " -f File only.\n"
67 " -d Directory only.\n"
68 " -m Use move operation instead of rename. (implies -f)\n"
69 " -r Replace existing destination.\n"
70 );
71 return 1;
72 }
73
74 /*
75 * Parse args.
76 */
77 const char *pszNew = NULL;
78 const char *pszOld = NULL;
79 bool fDir = false;
80 bool fFile = false;
81 bool fReplace = false;
82 bool fMoveFile = false;
83 for (int argi = 1; argi < argc; argi++)
84 {
85 if (argv[argi][0] == '-')
86 {
87 const char *psz = &argv[argi][1];
88 do
89 {
90 switch (*psz)
91 {
92 case 'd':
93 fDir = true;
94 fMoveFile = false;
95 break;
96 case 'f':
97 fFile = true;
98 break;
99 case 'm':
100 fMoveFile = true;
101 fDir = false;
102 fFile = true;
103 break;
104 case 'r':
105 fReplace = true;
106 break;
107 default:
108 RTPrintf("tstRTFileMove: syntax error: Unknown option '%c' in '%s'!\n", *psz, argv[argi]);
109 return 1;
110 }
111 } while (*++psz);
112 }
113 else if (!pszOld)
114 pszOld = argv[argi];
115 else if (!pszNew)
116 pszNew = argv[argi];
117 else
118 {
119 RTPrintf("tstRTFileMove: syntax error: too many filenames!\n");
120 return 1;
121 }
122 }
123 if (!pszNew || !pszOld)
124 {
125 RTPrintf("tstRTFileMove: syntax error: too few filenames!\n");
126 return 1;
127 }
128
129 /*
130 * Do the operation.
131 */
132 int rc;
133 if (!fDir && !fFile)
134 rc = RTPathRename(pszOld, pszNew, fReplace ? RTPATHRENAME_FLAGS_REPLACE : 0);
135 else if (fDir)
136 rc = RTDirRename( pszOld, pszNew, fReplace ? RTPATHRENAME_FLAGS_REPLACE : 0);
137 else if (!fMoveFile)
138 rc = RTFileRename(pszOld, pszNew, fReplace ? RTPATHRENAME_FLAGS_REPLACE : 0);
139 else
140 rc = RTFileMove( pszOld, pszNew, fReplace ? RTFILEMOVE_FLAGS_REPLACE : 0);
141
142 RTPrintf("The API returned %Rrc\n", rc);
143 return !RT_SUCCESS(rc);
144}
145
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