• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <cstdio>
17 #include <cstdlib>
18 #include <iostream>
19 #include <string>
20 #include <unistd.h>
21 #include <vector>
22 
23 enum EXIT_CODES {
24     EXIT_INVALID_ARGS = EXIT_SUCCESS + 1,
25     EXIT_READ_PACKAGE_ERROR = 2,
26     EXIT_FOUND_SCRIPT_ERROR = 3,
27     EXIT_PARSE_SCRIPT_ERROR = 4,
28     EXIT_EXEC_SCRIPT_ERROR = 5,
29 };
30 
main(int argc,char ** argv)31 int main(int argc, char **argv)
32 {
33     constexpr int lessArgIndex = 2;
34     constexpr int decimal = 10;
35     if (argc < lessArgIndex) {
36         std::cout << "Invalid arguments\n";
37         return EXIT_INVALID_ARGS;
38     }
39 
40     int pipeFd = static_cast<int>(std::strtol(argv[1], nullptr, decimal));
41     FILE *pipeWrite = fdopen(pipeFd, "w");
42     if (pipeWrite == nullptr) {
43         std::cout << "Failed to fdopen\n";
44         return EXIT_INVALID_ARGS;
45     }
46 
47     setlinebuf(pipeWrite);
48     fclose(pipeWrite);
49     // Return failure directly.
50     return EXIT_PARSE_SCRIPT_ERROR;
51 }
52 
53