1 /* |
1 /* |
2 * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
5164 errstrm = stdout; |
5164 errstrm = stdout; |
5165 return; |
5165 return; |
5166 } else if (log_file[0] != '\0' && (errstrm = fopen(log_file,"a+")) != NULL) { |
5166 } else if (log_file[0] != '\0' && (errstrm = fopen(log_file,"a+")) != NULL) { |
5167 return; |
5167 return; |
5168 } else { |
5168 } else { |
5169 char log_file_name[PATH_MAX+100]; |
5169 fprintf(stderr, "Can not open log file %s\n", log_file); |
5170 char tmpdir[PATH_MAX]; |
|
5171 #ifdef WIN32 |
|
5172 int n = GetTempPath(PATH_MAX,tmpdir); //API returns with trailing '\' |
|
5173 if (n < 1 || n > PATH_MAX) { |
|
5174 sprintf(tmpdir,"C:\\"); |
|
5175 } |
|
5176 sprintf(log_file_name, "%sunpack.log", tmpdir); |
|
5177 #else |
|
5178 sprintf(tmpdir,"/tmp"); |
|
5179 sprintf(log_file_name, "/tmp/unpack.log"); |
|
5180 #endif |
|
5181 if ((errstrm = fopen(log_file_name, "a+")) != NULL) { |
|
5182 log_file = errstrm_name = saveStr(log_file_name); |
|
5183 return ; |
|
5184 } |
|
5185 |
|
5186 char *tname = tempnam(tmpdir,"#upkg"); |
|
5187 if (tname == NULL) return; |
|
5188 sprintf(log_file_name, "%s", tname); |
|
5189 ::free(tname); |
|
5190 if ((errstrm = fopen(log_file_name, "a+")) != NULL) { |
|
5191 log_file = errstrm_name = saveStr(log_file_name); |
|
5192 return ; |
|
5193 } |
|
5194 #ifndef WIN32 |
|
5195 sprintf(log_file_name, "/dev/null"); |
|
5196 // On windows most likely it will fail. |
|
5197 if ( (errstrm = fopen(log_file_name, "a+")) != NULL) { |
|
5198 log_file = errstrm_name = saveStr(log_file_name); |
|
5199 return ; |
|
5200 } |
|
5201 #endif |
|
5202 // Last resort |
5170 // Last resort |
5203 // (Do not use stdout, since it might be jarout->jarfp.) |
5171 // (Do not use stdout, since it might be jarout->jarfp.) |
5204 errstrm = stderr; |
5172 errstrm = stderr; |
5205 log_file = errstrm_name = LOGFILE_STDERR; |
5173 log_file = errstrm_name = LOGFILE_STDERR; |
5206 } |
5174 } |