- Timestamp:
- Nov 8, 2010 5:08:19 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceToolBox.cpp
r33763 r33863 23 23 24 24 #include <iprt/assert.h> 25 #include <iprt/dir.h> 25 26 #include <iprt/file.h> 26 27 #include <iprt/getopt.h> 27 28 #include <iprt/list.h> 28 29 #include <iprt/mem.h> 30 #include <iprt/path.h> 29 31 #include <iprt/string.h> 30 32 #include <iprt/stream.h> … … 81 83 rc = RTFileFromNative(&hInput, RTFILE_NATIVE_STDIN); 82 84 if (RT_FAILURE(rc)) 83 VBoxServiceError(" Cat: Could not translate input file to native handle, rc=%Rrc\n", rc);85 VBoxServiceError("cat: Could not translate input file to native handle, rc=%Rrc\n", rc); 84 86 } 85 87 … … 88 90 rc = RTFileFromNative(&hOutput, RTFILE_NATIVE_STDOUT); 89 91 if (RT_FAILURE(rc)) 90 VBoxServiceError(" Cat: Could not translate output file to native handle, rc=%Rrc\n", rc);92 VBoxServiceError("cat: Could not translate output file to native handle, rc=%Rrc\n", rc); 91 93 } 92 94 … … 126 128 * @param argv 127 129 */ 130 int VBoxServiceToolboxMkDir(int argc, char **argv) 131 { 132 static const RTGETOPTDEF s_aOptions[] = 133 { 134 { "--mode", 'm', RTGETOPT_REQ_STRING }, 135 { "--parents", 'p', RTGETOPT_REQ_NOTHING }, 136 { "--verbose", 'v', RTGETOPT_REQ_NOTHING } 137 }; 138 139 int ch; 140 RTGETOPTUNION ValueUnion; 141 RTGETOPTSTATE GetState; 142 RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1, 0); 143 144 int rc = VINF_SUCCESS; 145 bool fMakeParentDirs = false; 146 bool fVerbose = false; 147 148 char *pszDir = NULL; 149 RTFMODE fMode = 0; /** @todo Get standard mode from umask? */ 150 151 while ( (ch = RTGetOpt(&GetState, &ValueUnion)) 152 && RT_SUCCESS(rc)) 153 { 154 /* For options that require an argument, ValueUnion has received the value. */ 155 switch (ch) 156 { 157 case 'p': 158 fMakeParentDirs = true; 159 break; 160 161 case 'm': 162 /* Ignore by now. */ 163 break; 164 165 case 'v': 166 fVerbose = true; 167 break; 168 169 case VINF_GETOPT_NOT_OPTION: 170 { 171 pszDir = RTPathAbsDup(ValueUnion.psz); 172 if (!pszDir) 173 rc = VERR_NO_MEMORY; 174 break; 175 } 176 177 default: 178 return RTGetOptPrintError(ch, &ValueUnion); 179 } 180 } 181 182 if (RT_SUCCESS(rc)) 183 { 184 rc = fMakeParentDirs ? 185 RTDirCreateFullPath(pszDir, fMode) 186 : RTDirCreate(pszDir, fMode); 187 188 if (RT_SUCCESS(rc) && fVerbose) 189 VBoxServiceVerbose(0, "mkdir: Created directory '%s'\n", pszDir); 190 else if (RT_FAILURE(rc)) /** @todo Add a switch with more helpful error texts! */ 191 VBoxServiceError("mkdir: Could not create directory, rc=%Rrc\n", rc); 192 } 193 else 194 VBoxServiceError("mkdir: Failed with rc=%Rrc\n", rc); 195 if (pszDir) 196 RTStrFree(pszDir); 197 return rc; 198 } 199 200 201 /** 202 * 203 * 204 * @return int 205 * 206 * @param argc 207 * @param argv 208 */ 128 209 int VBoxServiceToolboxCat(int argc, char **argv) 129 210 { … … 156 237 RTFILE_O_DENY_WRITE); 157 238 if (RT_FAILURE(rc)) 158 VBoxServiceError(" Cat: Could not create output file \"%s\"! rc=%Rrc\n",239 VBoxServiceError("cat: Could not create output file \"%s\"! rc=%Rrc\n", 159 240 ValueUnion.psz, rc); 160 241 break; … … 166 247 RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE); 167 248 if (RT_FAILURE(rc)) 168 VBoxServiceError(" Cat: Could not open input file \"%s\"! rc=%Rrc\n",249 VBoxServiceError("cat: Could not open input file \"%s\"! rc=%Rrc\n", 169 250 ValueUnion.psz, rc); 170 251 break; … … 205 286 rc = VBoxServiceToolboxCat(argc, argv); 206 287 } 288 else if ( !strcmp(argv[0], "mkdir") 289 || !strcmp(argv[0], "vbox_mkdir")) 290 { 291 rc = VBoxServiceToolboxMkDir(argc, argv); 292 } 207 293 } 208 294
Note:
See TracChangeset
for help on using the changeset viewer.