1 | /* $Id: tstDir-2.cpp 4071 2007-08-07 17:07:59Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * innotek Portable Runtime Testcase - Directory listing & filtering .
|
---|
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 |
|
---|
18 | #include <iprt/dir.h>
|
---|
19 | #include <iprt/stream.h>
|
---|
20 | #include <iprt/err.h>
|
---|
21 | #include <iprt/runtime.h>
|
---|
22 |
|
---|
23 | int main(int argc, char **argv)
|
---|
24 | {
|
---|
25 | int rcRet = 0;
|
---|
26 | RTR3Init();
|
---|
27 |
|
---|
28 | /*
|
---|
29 | * Iterate arguments.
|
---|
30 | */
|
---|
31 | for (int i = 1; i < argc; i++)
|
---|
32 | {
|
---|
33 | /* open */
|
---|
34 | PRTDIR pDir;
|
---|
35 | int rc = RTDirOpenFiltered(&pDir, argv[i], RTDIRFILTER_WINNT);
|
---|
36 | if (RT_SUCCESS(rc))
|
---|
37 | {
|
---|
38 | for (;;)
|
---|
39 | {
|
---|
40 | RTDIRENTRY DirEntry;
|
---|
41 | rc = RTDirRead(pDir, &DirEntry, NULL);
|
---|
42 | if (RT_FAILURE(rc))
|
---|
43 | break;
|
---|
44 | switch (DirEntry.enmType)
|
---|
45 | {
|
---|
46 | case RTDIRENTRYTYPE_UNKNOWN: RTPrintf("u"); break;
|
---|
47 | case RTDIRENTRYTYPE_FIFO: RTPrintf("f"); break;
|
---|
48 | case RTDIRENTRYTYPE_DEV_CHAR: RTPrintf("c"); break;
|
---|
49 | case RTDIRENTRYTYPE_DIRECTORY: RTPrintf("d"); break;
|
---|
50 | case RTDIRENTRYTYPE_DEV_BLOCK: RTPrintf("b"); break;
|
---|
51 | case RTDIRENTRYTYPE_FILE: RTPrintf("-"); break;
|
---|
52 | case RTDIRENTRYTYPE_SYMLINK: RTPrintf("l"); break;
|
---|
53 | case RTDIRENTRYTYPE_SOCKET: RTPrintf("s"); break;
|
---|
54 | case RTDIRENTRYTYPE_WHITEOUT: RTPrintf("w"); break;
|
---|
55 | default:
|
---|
56 | rcRet = 1;
|
---|
57 | RTPrintf("?");
|
---|
58 | break;
|
---|
59 | }
|
---|
60 | RTPrintf(" %#18llx %3d %s\n", (uint64_t)DirEntry.INodeId,
|
---|
61 | DirEntry.cbName, DirEntry.szName);
|
---|
62 | }
|
---|
63 |
|
---|
64 | if (rc != VERR_NO_MORE_FILES)
|
---|
65 | {
|
---|
66 | RTPrintf("tstDir: Enumeration failed! rc=%Rrc\n", rc);
|
---|
67 | rcRet = 1;
|
---|
68 | }
|
---|
69 |
|
---|
70 | /* close up */
|
---|
71 | rc = RTDirClose(pDir);
|
---|
72 | if (RT_FAILURE(rc))
|
---|
73 | {
|
---|
74 | RTPrintf("tstDir: Failed to close dir! rc=%Rrc\n", rc);
|
---|
75 | rcRet = 1;
|
---|
76 | }
|
---|
77 | }
|
---|
78 | else
|
---|
79 | {
|
---|
80 | RTPrintf("tstDir: Failed to open '%s', rc=%Rrc\n", argv[i], rc);
|
---|
81 | rcRet = 1;
|
---|
82 | }
|
---|
83 | }
|
---|
84 |
|
---|
85 | return rcRet;
|
---|
86 | }
|
---|
87 |
|
---|