1*1789df15SXin Li /*
2*1789df15SXin Li * Copyright (C) 2012 The Android Open Source Project
3*1789df15SXin Li *
4*1789df15SXin Li * Licensed under the Apache License, Version 2.0 (the "License");
5*1789df15SXin Li * you may not use this file except in compliance with the License.
6*1789df15SXin Li * You may obtain a copy of the License at
7*1789df15SXin Li *
8*1789df15SXin Li * http://www.apache.org/licenses/LICENSE-2.0
9*1789df15SXin Li *
10*1789df15SXin Li * Unless required by applicable law or agreed to in writing, software
11*1789df15SXin Li * distributed under the License is distributed on an "AS IS" BASIS,
12*1789df15SXin Li * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*1789df15SXin Li * See the License for the specific language governing permissions and
14*1789df15SXin Li * limitations under the License.
15*1789df15SXin Li */
16*1789df15SXin Li
17*1789df15SXin Li /*
18*1789df15SXin Li * "find_lock.exe", for Windows only.
19*1789df15SXin Li */
20*1789df15SXin Li
21*1789df15SXin Li #ifdef _WIN32
22*1789df15SXin Li
23*1789df15SXin Li #include "utils.h"
24*1789df15SXin Li #include "find_lock.h"
25*1789df15SXin Li #include <io.h>
26*1789df15SXin Li #include <fcntl.h>
27*1789df15SXin Li
main(int argc,char * argv[])28*1789df15SXin Li int main(int argc, char* argv[]) {
29*1789df15SXin Li
30*1789df15SXin Li gIsConsole = true; // tell utils to to print errors to stderr
31*1789df15SXin Li gIsDebug = (getenv("ANDROID_SDKMAN_DEBUG") != NULL);
32*1789df15SXin Li CPath dirPath;
33*1789df15SXin Li bool doPrintUsage = false;
34*1789df15SXin Li
35*1789df15SXin Li for (int i = 1; i < argc; i++) {
36*1789df15SXin Li if (strncmp(argv[i], "-d", 2) == 0) {
37*1789df15SXin Li gIsDebug = true;
38*1789df15SXin Li
39*1789df15SXin Li } else if (dirPath.isEmpty()) {
40*1789df15SXin Li dirPath.set(argv[i]);
41*1789df15SXin Li
42*1789df15SXin Li } else {
43*1789df15SXin Li doPrintUsage = true;
44*1789df15SXin Li }
45*1789df15SXin Li }
46*1789df15SXin Li
47*1789df15SXin Li if (dirPath.isEmpty()) {
48*1789df15SXin Li fprintf(stderr, "Error: Missing directory path\n");
49*1789df15SXin Li doPrintUsage = true;
50*1789df15SXin Li
51*1789df15SXin Li } else if (!dirPath.dirExists()) {
52*1789df15SXin Li fprintf(stderr, "Error: '%s' is not a valid directory.\n", dirPath.cstr());
53*1789df15SXin Li return 1;
54*1789df15SXin Li }
55*1789df15SXin Li
56*1789df15SXin Li if (doPrintUsage) {
57*1789df15SXin Li printf(
58*1789df15SXin Li "Usage: find_lock.exe [options] sdk_directory_path\n"
59*1789df15SXin Li "\n"
60*1789df15SXin Li "Outputs the names of modules that are locking the given directory.\n"
61*1789df15SXin Li "Returns code 0 when found, 1 when not found.\n"
62*1789df15SXin Li "\n"
63*1789df15SXin Li "Options:\n"
64*1789df15SXin Li "-h / -help : This help.\n"
65*1789df15SXin Li "-t / -test : Internal test.\n"
66*1789df15SXin Li );
67*1789df15SXin Li return 2;
68*1789df15SXin Li }
69*1789df15SXin Li
70*1789df15SXin Li CString result;
71*1789df15SXin Li if (findLock(dirPath, &result)) {
72*1789df15SXin Li fflush(stdout);
73*1789df15SXin Li fflush(stderr);
74*1789df15SXin Li printf("%s", result.cstr());
75*1789df15SXin Li return 0;
76*1789df15SXin Li }
77*1789df15SXin Li return 1;
78*1789df15SXin Li }
79*1789df15SXin Li
80*1789df15SXin Li #endif /* _WIN32 */
81