curl tool: use configuration files from lib directory
[platform/upstream/curl.git] / src / tool_main.c
1 /***************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
9  *
10  * This software is licensed as described in the file COPYING, which
11  * you should have received as part of this distribution. The terms
12  * are also available at http://curl.haxx.se/docs/copyright.html.
13  *
14  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15  * copies of the Software, and permit persons to whom the Software is
16  * furnished to do so, under the terms of the COPYING file.
17  *
18  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19  * KIND, either express or implied.
20  *
21  ***************************************************************************/
22 #include "tool_setup.h"
23
24 #include <curl/curl.h>
25
26 #include <sys/stat.h>
27
28 #ifdef HAVE_UNISTD_H
29 #  include <unistd.h>
30 #endif
31
32 #define ENABLE_CURLX_PRINTF
33 /* use our own printf() functions */
34 #include "curlx.h"
35
36 #include "tool_cfgable.h"
37 #include "tool_convert.h"
38 #include "tool_operate.h"
39 #include "tool_panykey.h"
40 #include "tool_vms.h"
41 #include "tool_main.h"
42
43 /*
44  * This is low-level hard-hacking memory leak tracking and similar. Using
45  * the library level code from this client-side is ugly, but we do this
46  * anyway for convenience.
47  */
48 #include "memdebug.h" /* keep this as LAST include */
49
50 #ifdef __VMS
51 static int vms_show = 0;
52 #endif
53
54 /*
55  * Ensure that file descriptors 0, 1 and 2 (stdin, stdout, stderr) are
56  * open before starting to run.  Otherwise, the first three network
57  * sockets opened by curl could be used for input sources, downloaded data
58  * or error logs as they will effectively be stdin, stdout and/or stderr.
59  */
60 static void main_checkfds(void)
61 {
62 #ifdef HAVE_PIPE
63   int fd[2] = { STDIN_FILENO, STDIN_FILENO };
64   while(fd[0] == STDIN_FILENO ||
65         fd[0] == STDOUT_FILENO ||
66         fd[0] == STDERR_FILENO ||
67         fd[1] == STDIN_FILENO ||
68         fd[1] == STDOUT_FILENO ||
69         fd[1] == STDERR_FILENO)
70     if(pipe(fd) < 0)
71       return;   /* Out of handles. This isn't really a big problem now, but
72                    will be when we try to create a socket later. */
73   close(fd[0]);
74   close(fd[1]);
75 #endif
76 }
77
78 /*
79 ** curl tool main function.
80 */
81 int main(int argc, char *argv[])
82 {
83   int res;
84   struct Configurable config;
85
86   memset(&config, 0, sizeof(struct Configurable));
87
88   config.errors = stderr; /* default errors to stderr */
89
90   main_checkfds();
91
92   res = operate(&config, argc, argv);
93
94 #ifdef __SYMBIAN32__
95   if(config.showerror)
96     tool_pressanykey();
97 #endif
98
99   free_config_fields(&config);
100
101 #ifdef __NOVELL_LIBC__
102   if(getenv("_IN_NETWARE_BASH_") == NULL)
103     tool_pressanykey();
104 #endif
105
106 #ifdef __VMS
107   vms_special_exit(res, vms_show);
108 #else
109   return res;
110 #endif
111 }
112