Mercurial > dwindows
comparison gtk3/dw.c @ 2201:ae6626a4331f
GTK: Same change from tmpnam() to mkstemp() for GTK2 plus extra safety
checks on both GTK2 and GTK3.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 27 Oct 2020 00:52:13 +0000 |
parents | 319eeecb411e |
children | c677d728e143 |
comparison
equal
deleted
inserted
replaced
2200:319eeecb411e | 2201:ae6626a4331f |
---|---|
4552 /* | 4552 /* |
4553 * A real hack; create a temporary file and write the contents | 4553 * A real hack; create a temporary file and write the contents |
4554 * of the data to the file | 4554 * of the data to the file |
4555 */ | 4555 */ |
4556 char template[] = "/tmp/dwpixmapXXXXXX"; | 4556 char template[] = "/tmp/dwpixmapXXXXXX"; |
4557 int fd = mkstemp(template); | 4557 int written = -1, fd = mkstemp(template); |
4558 | 4558 |
4559 if(fd) | 4559 if(fd != -1) |
4560 { | 4560 { |
4561 write(fd, data, len); | 4561 written = write(fd, data, len); |
4562 close(fd); | 4562 close(fd); |
4563 } | 4563 } |
4564 else | 4564 /* Bail if we couldn't write full file */ |
4565 if(fd == -1 || written != len) | |
4565 { | 4566 { |
4566 DW_MUTEX_UNLOCK; | 4567 DW_MUTEX_UNLOCK; |
4567 return; | 4568 return; |
4568 } | 4569 } |
4569 | 4570 |
6024 * data: Source of data for image. | 6025 * data: Source of data for image. |
6025 * len: length of data | 6026 * len: length of data |
6026 */ | 6027 */ |
6027 HICN API dw_icon_load_from_data(const char *data, int len) | 6028 HICN API dw_icon_load_from_data(const char *data, int len) |
6028 { | 6029 { |
6029 int fd, _locked_by_me = FALSE; | 6030 int fd, written = -1, _locked_by_me = FALSE; |
6030 char template[] = "/tmp/dwiconXXXXXX"; | 6031 char template[] = "/tmp/dwiconXXXXXX"; |
6031 HICN ret = 0; | 6032 HICN ret = 0; |
6032 | 6033 |
6033 /* | 6034 /* |
6034 * A real hack; create a temporary file and write the contents | 6035 * A real hack; create a temporary file and write the contents |
6035 * of the data to the file | 6036 * of the data to the file |
6036 */ | 6037 */ |
6037 if((fd = mkstemp(template))) | 6038 if((fd = mkstemp(template)) != -1) |
6038 { | 6039 { |
6039 write(fd, data, len); | 6040 written = write(fd, data, len); |
6040 close(fd); | 6041 close(fd); |
6041 } | 6042 } |
6042 else | 6043 /* Bail if we couldn't write full file */ |
6044 if(fd == -1 || written != len) | |
6043 return 0; | 6045 return 0; |
6044 DW_MUTEX_LOCK; | 6046 DW_MUTEX_LOCK; |
6045 ret = _icon_resize(gdk_pixbuf_new_from_file(template, NULL)); | 6047 ret = _icon_resize(gdk_pixbuf_new_from_file(template, NULL)); |
6046 DW_MUTEX_UNLOCK; | 6048 DW_MUTEX_UNLOCK; |
6047 unlink(template); | 6049 unlink(template); |
7835 * Returns: | 7837 * Returns: |
7836 * A handle to a pixmap or NULL on failure. | 7838 * A handle to a pixmap or NULL on failure. |
7837 */ | 7839 */ |
7838 HPIXMAP dw_pixmap_new_from_data(HWND handle, const char *data, int len) | 7840 HPIXMAP dw_pixmap_new_from_data(HWND handle, const char *data, int len) |
7839 { | 7841 { |
7840 int fd, _locked_by_me = FALSE; | 7842 int fd, written = -1, _locked_by_me = FALSE; |
7841 HPIXMAP pixmap; | 7843 HPIXMAP pixmap; |
7842 char template[] = "/tmp/dwpixmapXXXXXX"; | 7844 char template[] = "/tmp/dwpixmapXXXXXX"; |
7843 | 7845 |
7844 if(!data || !(pixmap = calloc(1,sizeof(struct _hpixmap)))) | 7846 if(!data || !(pixmap = calloc(1,sizeof(struct _hpixmap)))) |
7845 return NULL; | 7847 return NULL; |
7847 DW_MUTEX_LOCK; | 7849 DW_MUTEX_LOCK; |
7848 /* | 7850 /* |
7849 * A real hack; create a temporary file and write the contents | 7851 * A real hack; create a temporary file and write the contents |
7850 * of the data to the file | 7852 * of the data to the file |
7851 */ | 7853 */ |
7852 if((fd = mkstemp(template))) | 7854 if((fd = mkstemp(template)) != -1) |
7853 { | 7855 { |
7854 write(fd, data, len); | 7856 written = write(fd, data, len); |
7855 close(fd); | 7857 close(fd); |
7856 } | 7858 } |
7857 else | 7859 /* Bail if we couldn't write full file */ |
7860 if(fd == -1 || written != len) | |
7858 { | 7861 { |
7859 DW_MUTEX_UNLOCK; | 7862 DW_MUTEX_UNLOCK; |
7860 return 0; | 7863 return 0; |
7861 } | 7864 } |
7862 pixmap->pixbuf = gdk_pixbuf_new_from_file(template, NULL); | 7865 pixmap->pixbuf = gdk_pixbuf_new_from_file(template, NULL); |