int errprintf(const gs_memory_t *mem, const char *fmt, ...) { int count; char buf[PRINTF_BUF_LENGTH]; va_list args; va_start(args, fmt); count = vsnprintf(buf, sizeof(buf), fmt, args); if (count >= sizeof(buf) || count < 0) { /* C99 || MSVC */ errwrite(mem, buf, sizeof(buf) - 1); errwrite(mem, msg_truncated, sizeof(msg_truncated) - 1); } else { errwrite(mem, buf, count); } va_end(args); return count; }
/* * Open a stream using a filename that can include a PS style IODevice prefix * If iodev_default is the '%os' device, then the file will be on the host * file system transparently to the caller. The "%os%" prefix can be used * to explicilty access the host file system. */ stream * sfopen(const char *path, const char *mode, gs_memory_t *memory) { gs_parsed_file_name_t pfn; stream *s; iodev_proc_open_file((*open_file)); gs_memory_t *mem = (memory == NULL) ? gs_lib_ctx_get_non_gc_memory_t() : memory; int code = gs_parse_file_name(&pfn, path, strlen(path)); if (code < 0) { # define EMSG "sfopen: gs_parse_file_name failed.\n" errwrite(EMSG, strlen(EMSG)); # undef EMSG return NULL; } if (pfn.fname == NULL) { /* just a device */ # define EMSG "sfopen: not allowed with %device only.\n" errwrite(EMSG, strlen(EMSG)); # undef EMSG return NULL; } if (pfn.iodev == NULL) pfn.iodev = iodev_default; open_file = pfn.iodev->procs.open_file; if (open_file == 0) code = file_open_stream(pfn.fname, pfn.len, mode, 2048, &s, pfn.iodev, pfn.iodev->procs.fopen, mem); else code = open_file(pfn.iodev, pfn.fname, pfn.len, mode, &s, mem); if (code < 0) return NULL; s->position = 0; code = ssetfilename(s, (const byte *)path, strlen(path)); if (code < 0) { /* Only error is e_VMerror */ sclose(s); gs_free_object(s->memory, s, "sfopen: allocation error"); # define EMSG "sfopen: allocation error setting path name into stream.\n" errwrite(EMSG, strlen(EMSG)); # undef EMSG return NULL; } return s; }
int main(int argc, char ** argv) { char * truename, * runtime_path; int fd; truename = searchpath(argv[0]); fd = open(truename, O_RDONLY | O_BINARY); if (fd == -1 || (runtime_path = read_runtime_path(fd)) == NULL) { errwrite(truename); errwrite(" not found or is not a bytecode executable file\n"); return 2; } argv[0] = truename; execv(runtime_path, argv); errwrite("Cannot exec "); errwrite(runtime_path); errwrite("\n"); return 2; }
int errprintf(const char *fmt, ...) { int count; char buf[PRINTF_BUF_LENGTH]; va_list args; va_start(args, fmt); count = vsprintf(buf, fmt, args); errwrite(buf, count); if (count >= PRINTF_BUF_LENGTH) { count = sprintf(buf, "PANIC: printf exceeded %d bytes. Stack has been corrupted.\n", PRINTF_BUF_LENGTH); errwrite(buf, count); } va_end(args); return count; }
static int DebugPrint(ttfFont *ttf, const char *fmt, ...) { char buf[500]; va_list args; int count; if (gs_debug_c('Y')) { va_start(args, fmt); count = vsnprintf(buf, sizeof(buf), fmt, args); /* NB: moved debug output from stdout to stderr */ errwrite(ttf->DebugMem, buf, count); va_end(args); } return 0; }
int outwrite(const gs_memory_t *mem, const char *str, int len) { int code; FILE *fout; gs_lib_ctx_t *pio = mem->gs_lib_ctx; if (len == 0) return 0; if (pio->stdout_is_redirected) { if (pio->stdout_to_stderr) return errwrite(str, len); fout = pio->fstdout2; } else if (pio->stdout_fn) { return (*pio->stdout_fn)(pio->caller_handle, str, len); } else { fout = pio->fstdout; } code = fwrite(str, 1, len, fout); fflush(fout); return code; }
int errwrite_nomem(const char *str, int len) { return errwrite(mem_err_print, str, len); }
int eprn_open_device(gx_device *device) { eprn_Eprn *eprn = &((eprn_Device *)device)->eprn; const char *epref = eprn->CUPS_messages? CUPS_ERRPREF: ""; int rc; #ifdef EPRN_TRACE if_debug0(EPRN_TRACE_CHAR, "! eprn_open_device()...\n"); #endif /* Checks on page size and determination of derived values */ if (eprn_set_page_layout((eprn_Device *)device) != 0) return_error(gs_error_rangecheck); /* Check the rendering parameters */ if (eprn_check_colour_info(eprn->cap->colour_info, &eprn->colour_model, &device->HWResolution[0], &device->HWResolution[1], &eprn->black_levels, &eprn->non_black_levels) != 0) { gs_param_string str; eprintf1("%s" ERRPREF "The requested combination of colour model (", epref); str.size = 0; if (eprn_get_string(eprn->colour_model, eprn_colour_model_list, &str) != 0) assert(0); /* Bug. No harm on NDEBUG because I've just set the size. */ errwrite(device->memory, (const char *)str.data, str.size * sizeof(str.data[0])); eprintf7("),\n" "%s resolution (%gx%g ppi) and intensity levels (%d, %d) is\n" "%s not supported by the %s.\n", epref, device->HWResolution[0], device->HWResolution[1], eprn->black_levels, eprn->non_black_levels, epref, eprn->cap->name); return_error(gs_error_rangecheck); } /* Initialization for colour rendering */ if (device->color_info.num_components == 4) { /* Native colour space is 'DeviceCMYK' */ set_dev_proc(device, map_rgb_color, NULL); if (eprn->intensity_rendering == eprn_IR_FloydSteinberg) set_dev_proc(device, map_cmyk_color, &eprn_map_cmyk_color_max); else if (device->color_info.max_gray > 1 || device->color_info.max_color > 1) set_dev_proc(device, map_cmyk_color, &eprn_map_cmyk_color_flex); else set_dev_proc(device, map_cmyk_color, &eprn_map_cmyk_color); if (eprn->intensity_rendering == eprn_IR_FloydSteinberg) set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_CMY_or_K_max); else if (device->color_info.max_gray > 1 || device->color_info.max_color > 1) set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_CMY_or_K_flex); else set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_CMY_or_K); } else { set_dev_proc(device, map_cmyk_color, NULL); if (eprn->colour_model == eprn_DeviceRGB) { if (eprn->intensity_rendering == eprn_IR_FloydSteinberg) set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_RGB_max); else if (device->color_info.max_color > 1) set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_RGB_flex); else set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_RGB); } else { if (eprn->intensity_rendering == eprn_IR_FloydSteinberg) set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_CMY_or_K_max); else if (device->color_info.max_gray > 1 || device->color_info.max_color > 1) set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_CMY_or_K_flex); else set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_CMY_or_K); } } eprn->output_planes = eprn_bits_for_levels(eprn->black_levels) + 3 * eprn_bits_for_levels(eprn->non_black_levels); #if !defined(GS_REVISION) || GS_REVISION >= 600 /* According to my understanding, the following call should be superfluous (because the colour mapping functions may not be called while the device is closed) and I am also not aware of any situation where it does make a difference. It shouldn't do any harm, though, and I feel safer with it :-) */ gx_device_decache_colors(device); #endif #ifndef EPRN_NO_PAGECOUNTFILE /* Read the page count value */ if (eprn->pagecount_file != NULL) { unsigned long count; if (pcf_getcount(eprn->pagecount_file, &count) == 0) device->PageCount = count; /* unsigned to signed. The C standard permits an implementation to generate an overflow indication if the value is too large. I consider this to mean that the type of 'PageCount' is inappropriate :-). Note that eprn does not use 'PageCount' for updating the file. */ else { /* pcf_getcount() has issued an error message. */ eprintf( " No further attempts will be made to access the page count file.\n"); gs_free(device->memory->non_gc_memory, eprn->pagecount_file, strlen(eprn->pagecount_file) + 1, sizeof(char), "eprn_open_device"); eprn->pagecount_file = NULL; } } #endif /* !EPRN_NO_PAGECOUNTFILE */ /* Open the "prn" device part */ if ((rc = gdev_prn_open(device)) != 0) return rc; /* Just in case a previous open call failed in a derived device (note that 'octets_per_line' is still the same as then): */ if (eprn->scan_line.str != NULL) gs_free(device->memory->non_gc_memory, eprn->scan_line.str, eprn->octets_per_line, sizeof(eprn_Octet), "eprn_open_device"); if (eprn->next_scan_line.str != NULL) { gs_free(device->memory->non_gc_memory, eprn->next_scan_line.str, eprn->octets_per_line, sizeof(eprn_Octet), "eprn_open_device"); eprn->next_scan_line.str = NULL; } /* Calls which might depend on prn having been initialized */ eprn->octets_per_line = gdev_prn_raster((gx_device_printer *)device); eprn->scan_line.str = (eprn_Octet *) gs_malloc(device->memory->non_gc_memory, eprn->octets_per_line, sizeof(eprn_Octet), "eprn_open_device"); if (eprn->intensity_rendering == eprn_IR_FloydSteinberg) { eprn->next_scan_line.str = (eprn_Octet *) gs_malloc(device->memory->non_gc_memory, eprn->octets_per_line, sizeof(eprn_Octet), "eprn_open_device"); if (eprn->next_scan_line.str == NULL && eprn->scan_line.str != NULL) { gs_free(device->memory->non_gc_memory, eprn->scan_line.str, eprn->octets_per_line, sizeof(eprn_Octet), "eprn_open_device"); eprn->scan_line.str = NULL; } } if (eprn->scan_line.str == NULL) { eprintf1("%s" ERRPREF "Memory allocation failure from gs_malloc() in eprn_open_device().\n", epref); return_error(gs_error_VMerror); } return rc; }