Index: draw_ps.c =================================================================== --- draw_ps.c (revision 36265) +++ draw_ps.c (revision 36266) @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -267,6 +268,8 @@ int rnd_ps_new_file(rnd_ps_t *pctx, FILE *new_f, const char *fn) { + int ern = errno; + if (pctx->outf != NULL) { rnd_ps_end_file(pctx); fclose(pctx->outf); @@ -273,8 +276,7 @@ } pctx->outf = new_f; if (pctx->outf == NULL) { - TODO("use rnd_message() and strerror instead"); - perror(fn); + rnd_message(RND_MSG_ERROR, "rnd_ps_new_file(): failed to open %s: %s\n", fn, strerror(ern)); return -1; } return 0; Index: draw_ps.h =================================================================== --- draw_ps.h (revision 36265) +++ draw_ps.h (revision 36266) @@ -62,7 +62,8 @@ /* Call this in set_layer_group() to see if a new page needs to be stated */ int rnd_ps_is_new_page(rnd_ps_t *pctx, int group); -/* Announce a new file, check for file open error */ +/* Announce a new file, check for file open error. Call right after fopen() + because it depends on errno. */ int rnd_ps_new_file(rnd_ps_t *pctx, FILE *new_f, const char *fn); /* Render frame and background of a new page, depending on pctx settings: Index: ps.c =================================================================== --- ps.c (revision 36265) +++ ps.c (revision 36266) @@ -567,7 +567,7 @@ gds_init(&tmp); fn = ps_cam.active ? ps_cam.fn : pcb_layer_to_file_name(&tmp, layer, flags, purpose, purpi, PCB_FNS_fixed); - nr = rnd_ps_new_file(&global.ps, psopen(ps_cam.active ? fn : global.filename, fn), global.filename); + nr = rnd_ps_new_file(&global.ps, psopen(ps_cam.active ? fn : global.filename, fn), fn); gds_uninit(&tmp); if (nr != 0) return 0;