1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
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.
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.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 * $Id: writeenv.c,v 1.1.1.1 2008-09-23 16:32:06 hoffman Exp $
22 ***************************************************************************/
26 #ifdef USE_ENVIRONMENT
28 #include <curl/curl.h>
47 {"curl_url_effective", CURLINFO_EFFECTIVE_URL
, writeenv_STRING
},
48 {"curl_http_code", CURLINFO_RESPONSE_CODE
, writeenv_LONG
},
49 {"curl_time_total", CURLINFO_TOTAL_TIME
, writeenv_DOUBLE
},
50 {"curl_time_namelookup", CURLINFO_NAMELOOKUP_TIME
, writeenv_DOUBLE
},
51 {"curl_time_connect", CURLINFO_CONNECT_TIME
, writeenv_DOUBLE
},
52 {"curl_time_pretransfer", CURLINFO_PRETRANSFER_TIME
, writeenv_DOUBLE
},
53 {"curl_time_starttransfer", CURLINFO_STARTTRANSFER_TIME
, writeenv_DOUBLE
},
54 {"curl_size_header", CURLINFO_HEADER_SIZE
, writeenv_LONG
},
55 {"curl_size_request", CURLINFO_REQUEST_SIZE
, writeenv_LONG
},
56 {"curl_size_download", CURLINFO_SIZE_DOWNLOAD
, writeenv_DOUBLE
},
57 {"curl_size_upload", CURLINFO_SIZE_UPLOAD
, writeenv_DOUBLE
},
58 {"curl_speed_download", CURLINFO_SPEED_DOWNLOAD
, writeenv_DOUBLE
},
59 {"curl_speed_upload", CURLINFO_SPEED_UPLOAD
, writeenv_DOUBLE
},
60 {NULL
, 0, writeenv_NONE
}
63 static void internalSetEnv(const char * name
, char * value
)
65 /* Add your OS-specific code here. */
67 _kernel_setenv(name
, value
);
68 #elif defined (CURLDEBUG)
69 extern FILE *curl_debuglogfile
;
70 if (curl_debuglogfile
)
71 fprintf (curl_debuglogfile
, "ENV %s = %s\n", name
, value
);
76 void ourWriteEnv(CURL
*curl
)
79 char *string
, numtext
[10];
83 for (i
=0; variables
[i
].name
; i
++) {
84 switch (variables
[i
].type
) {
86 if (curl_easy_getinfo(curl
, variables
[i
].id
, &string
) == CURLE_OK
)
87 internalSetEnv(variables
[i
].name
, string
);
89 internalSetEnv(variables
[i
].name
, NULL
);
93 if (curl_easy_getinfo(curl
, variables
[i
].id
, &longinfo
) == CURLE_OK
) {
94 sprintf(numtext
, "%5ld", longinfo
);
95 internalSetEnv(variables
[i
].name
, numtext
);
98 internalSetEnv(variables
[i
].name
, NULL
);
100 case writeenv_DOUBLE
:
101 if (curl_easy_getinfo(curl
, variables
[i
].id
, &doubleinfo
) == CURLE_OK
) {
102 sprintf(numtext
, "%6.2f", doubleinfo
);
103 internalSetEnv(variables
[i
].name
, numtext
);
106 internalSetEnv(variables
[i
].name
, NULL
);