Re-do the patch-png.c "by the book" -- following the examples in

libpng(3) to be able to use  the new libpng, which disabled some
deprecated interfaces.

Modify file.c to  use mkstemp instead of tmpnam. Fix  an old bug
-- when the new server's  configuration is created from scratch,
we  write a  file and  then  read it  -- use  O_RDWR instead  of
O_WRONLY.

I  could not  reproduce  Andreas'  complaint regarding  compface
related crashes and plan to re-enable them in the Makefile.

Too bad this program is no longer in development :(
This commit is contained in:
Mikhail Teterin 2001-07-13 17:23:57 +00:00
parent 1db38b3dd7
commit 6bcb0919aa
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=45109
3 changed files with 160 additions and 20 deletions

View File

@ -0,0 +1,28 @@
Use mkstemp instead of tmpnam. Copied from the tmpnam implementation :)
-mi
--- src/file.c Fri Jan 9 12:16:19 1998
+++ src/file.c Fri Jul 13 10:41:01 2001
@@ -187,13 +187,12 @@
int fd;
+ static unsigned long tmpcount;
+ static char buf[L_tmpnam];
- *name = tmpnam(NULL);
- if (!*name)
- fd = -1;
- else {
+ (void)snprintf(buf, L_tmpnam, "%stmp.%lu.XXXXXX", P_tmpdir, tmpcount++);
+ *name = buf;
+ fd = mkstemp(buf);
+ if (fd < 0)
+ *name = NULL;
+ else
unlink(*name);
- fd = open(*name, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR);
- if (fd < 0)
- *name = NULL;
- }
-
return fd;

View File

@ -1,29 +1,130 @@
--- src/png.c.orig Sat Nov 21 15:55:13 1998
+++ src/png.c Sun Jun 17 19:58:21 2001
@@ -80,6 +80,7 @@
--- src/png.c Sat Nov 21 09:55:13 1998
+++ src/png.c Fri Jul 13 11:29:00 2001
@@ -78,6 +78,12 @@
+static Pixmap rep_fail(const char *e) {
+ ArtTextAddLine(main_widgets.text, e, ascii_font->body_font,
+ global.alert_pixel);
+ return None;
+}
+
Pixmap do_png(char *data, long len, long *wp, long *hp)
{
png_struct p_str;
png_info p_info;
+ png_info * p_info_ptr;
- png_struct p_str;
- png_info p_info;
+ png_structp png_ptr;
+ png_infop info_ptr;
Pixmap pixmap;
FILE *volatile vol_fp = NULL;
void *volatile vol_pic = NULL;
@@ -109,7 +110,8 @@
unsigned int i, j, pass;
@@ -94,9 +100,6 @@
png_read_init(&p_str);
- if (!(vol_fp = dump_for_png(data, len))) {
- ArtTextAddLine(main_widgets.text, "[knews: temp file error.]",
- ascii_font->body_font, global.alert_pixel);
- return None;
- }
+ if (!(vol_fp = dump_for_png(data, len)))
+ return rep_fail("[knews: temp file error.]");
- if (setjmp(p_str.jmpbuf))
+ if (setjmp(png_jmpbuf(png_ptr)))
ArtTextAddLine(main_widgets.text, "[knews: png error.]",
@@ -110,18 +113,26 @@
- png_read_init(&p_str);
- png_info_init(&p_info);
+ p_info_ptr = &p_info;
+ png_info_init_3(&p_info_ptr, sizeof(png_info));
+ png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
+ NULL, NULL, NULL);
+ if (!png_ptr)
+ return rep_fail("[knews: can't allocate PNG structure.]");
+ info_ptr = png_create_info_struct(png_ptr);
+ if (!info_ptr) {
+ png_destroy_read_struct(&png_ptr,
+ (png_infopp)NULL, (png_infopp)NULL);
+ return rep_fail("[knews: can't PNG info structure.]");
+ }
png_init_io(&p_str, vol_fp);
png_read_info(&p_str, &p_info);
@@ -204,7 +206,7 @@
}
- png_init_io(&p_str, vol_fp);
- png_read_info(&p_str, &p_info);
+ png_init_io(png_ptr, vol_fp);
+ png_read_info(png_ptr, info_ptr);
- vol_w = w = p_info.width;
- vol_h = h = p_info.height;
+ vol_w = w = info_ptr->width;
+ vol_h = h = info_ptr->height;
- if (p_info.bit_depth == 16)
- png_set_strip_16(&p_str);
- else if (p_info.bit_depth < 8)
- png_set_packing(&p_str);
+ if (info_ptr->bit_depth == 16)
+ png_set_strip_16(png_ptr);
+ else if (info_ptr->bit_depth < 8)
+ png_set_packing(png_ptr);
- if (p_info.valid & PNG_INFO_bKGD)
- png_set_background(&p_str, &p_info.background,
+ if (info_ptr->valid & PNG_INFO_bKGD)
+ png_set_background(png_ptr, &info_ptr->background,
PNG_BACKGROUND_GAMMA_FILE, True, 1.0);
@@ -129,3 +140,3 @@
static png_color_16 bg = {0, };
- png_set_background(&p_str, &bg,
+ png_set_background(png_ptr, &bg,
PNG_BACKGROUND_GAMMA_SCREEN, False, 1.0);
@@ -135,10 +146,10 @@
- if (!(p_info.color_type & PNG_COLOR_MASK_COLOR)) { /* grey image */
+ if (!(info_ptr->color_type & PNG_COLOR_MASK_COLOR)) { /* grey image */
grey = True;
- png_set_expand(&p_str);
+ png_set_expand(png_ptr);
} else if (!p_cmap) { /* true color visual */
- if (p_info.color_type == PNG_COLOR_TYPE_PALETTE)
- png_set_expand(&p_str);
+ if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
+ png_set_expand(png_ptr);
per_line *= 3;
- } else if (p_info.color_type & PNG_COLOR_MASK_PALETTE) {
+ } else if (info_ptr->color_type & PNG_COLOR_MASK_PALETTE) {
CMAP_ENTRY *pal;
@@ -146,8 +157,8 @@
- pn = p_info.num_palette;
+ pn = info_ptr->num_palette;
pal = (CMAP_ENTRY *)XtMalloc(pn * sizeof *pal);
for (i = 0 ; i < pn ; i++) {
- pal[i].r = p_info.palette[i].red;
- pal[i].g = p_info.palette[i].green;
- pal[i].b = p_info.palette[i].blue;
+ pal[i].r = info_ptr->palette[i].red;
+ pal[i].g = info_ptr->palette[i].green;
+ pal[i].b = info_ptr->palette[i].blue;
}
@@ -156,3 +167,3 @@
} else {
- png_set_dither(&p_str, p_cmap, cmap_size,
+ png_set_dither(png_ptr, p_cmap, cmap_size,
cmap_size, NULL, True);
@@ -160,4 +171,4 @@
- pass = png_set_interlace_handling(&p_str);
- png_start_read_image(&p_str);
+ pass = png_set_interlace_handling(png_ptr);
+ png_start_read_image(png_ptr);
@@ -169,3 +180,3 @@
for (j = 0 ; j < h ; j++) {
- png_read_row(&p_str, NULL, row);
+ png_read_row(png_ptr, NULL, row);
if (!did)
@@ -176,3 +187,3 @@
- png_read_end(&p_str, NULL);
+ png_read_end(png_ptr, NULL);
}
@@ -206,3 +217,3 @@
- png_read_destroy(&p_str, &p_info, NULL);
+ png_read_destroy(&p_str, &p_info_ptr, NULL);
+ png_read_destroy(png_ptr, info_ptr, NULL);
fclose((FILE *)vol_fp);
XtFree((char *)vol_pic);
XtFree((char *)vol_pal);

View File

@ -0,0 +1,11 @@
Do not use O_WRONLY, if we plan on reading from this file again!
-mi
--- src/resource.c Fri Jan 9 12:16:21 1998
+++ src/resource.c Fri Jul 13 12:21:46 2001
@@ -556,3 +556,3 @@
fprintf(stderr, "Knews: creating config file %s\n", path);
- fd = open_mkdir(path, O_WRONLY|O_TRUNC|O_EXCL|O_CREAT, True);
+ fd = open_mkdir(path, O_RDWR|O_TRUNC|O_EXCL|O_CREAT, True);
if (fd < 0) {