// 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 und die Messung sind noch experimentell.