/* * Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
// Prepend filename with the temp directory and pid and return the result as a // resource allocated string. staticinlinechar* prepend_temp_dir(constchar* filename) {
size_t temp_file_len = strlen(tmp_dir) + strlen(file_sep) + strlen(filename) + 28; char* temp_file = NEW_RESOURCE_ARRAY(char, temp_file_len); int ret = jio_snprintf(temp_file, temp_file_len, "%s%spid%d.%s",
tmp_dir, file_sep,
os::current_process_id(), filename); return temp_file;
}
// Prepend filename with specified prefix and the temp directory and return the // result as a malloc allocated string. This is used by test_logFileOutput.cpp. staticinlinechar* prepend_prefix_temp_dir(constchar* prefix, constchar* filename) {
size_t temp_file_len = strlen(prefix) + strlen(tmp_dir) + strlen(file_sep) + strlen(filename) + 1; char* temp_file = (char*)os::malloc(temp_file_len, mtLogging); int ret = jio_snprintf(temp_file, temp_file_len, "%s%s%s%s",
prefix, tmp_dir, file_sep, filename); return temp_file;
}
// Read a complete line from fp and return it as a resource allocated string. // Returns NULL on EOF. staticinlinechar* read_line(FILE* fp) {
assert(fp != NULL, "invalid fp"); int buflen = 512; char* buf = NEW_RESOURCE_ARRAY(char, buflen); long pos = ftell(fp); if (pos < 0) return NULL;
char* ret = fgets(buf, buflen, fp); while (ret != NULL && buf[strlen(buf) - 1] != '\n' && !feof(fp)) { // retry with a larger buffer
buf = REALLOC_RESOURCE_ARRAY(char, buf, buflen, buflen * 2);
buflen *= 2; // rewind to beginning of line
fseek(fp, pos, SEEK_SET); // retry read with new buffer
ret = fgets(buf, buflen, fp);
} return ret;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.