# HG changeset patch # User mhessling@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1309304339 0 # Node ID b905fd8e7fd16fca4d28163fbc9f3311aaba0691 # Parent b58032a619b9ab71fbd85ff8c32777e19c11a3fe Use _tempnam() on Windows instead of tmpnam() for dw_*_from_data() functions. This overcomes bug in Windows tmpnam() which does not always generate a temporary file name in a directory that can written to. Modified dwtest.c to handle file errors more gracefully. diff -r b58032a619b9 -r b905fd8e7fd1 dwtest.c --- a/dwtest.c Tue Jun 28 20:30:29 2011 +0000 +++ b/dwtest.c Tue Jun 28 23:38:59 2011 +0000 @@ -37,6 +37,27 @@ int iteration = 0; void create_button( int); +static char folder_ico[1718] = { + 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x01, 0x00, 0x00, 0x26, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x68, 0x05, 0x00, 0x00, 0x4E, 0x01, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, + 0x80, 0x00, 0x80, 0x80, 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x30, 0x03, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x3B, 0x37, 0x77, 0x77, 0x77, 0x77, 0xB7, 0x33, 0x3B, 0x37, 0x77, 0x77, 0x77, 0x77, 0xB7, 0x33, 0x3B, 0x37, 0x77, 0x77, 0x77, 0x77, 0xB7, 0x33, 0x3B, 0x37, + 0x77, 0x77, 0x77, 0x77, 0xB7, 0x33, 0x37, 0x37, 0x77, 0x77, 0x77, 0x77, 0xB7, 0x33, 0x37, 0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x33, 0x37, 0x73, 0x33, 0x33, 0x33, 0x33, 0x33, 0x30, 0x37, 0x77, 0x77, 0x7F, 0xFF, 0xFF, 0x30, 0x00, 0x3F, 0x77, 0x77, 0xF3, 0x33, 0x33, 0x30, 0x00, 0x03, 0xFF, 0xFF, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x33, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x81, 0xFF, 0x00, 0x00, 0xC3, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x80, + 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0x00, 0xC0, 0xDC, 0xC0, 0x00, 0xF0, 0xCA, 0xA6, 0x00, 0x04, 0x04, 0x04, 0x00, 0x08, 0x08, 0x08, 0x00, 0x0C, 0x0C, 0x0C, 0x00, 0x11, 0x11, 0x11, 0x00, 0x16, 0x16, 0x16, 0x00, 0x1C, 0x1C, 0x1C, 0x00, 0x22, 0x22, 0x22, 0x00, 0x29, 0x29, 0x29, 0x00, 0x55, 0x55, 0x55, 0x00, 0x4D, 0x4D, 0x4D, 0x00, 0x42, 0x42, 0x42, 0x00, 0x39, 0x39, 0x39, 0x00, 0x80, 0x7C, 0xFF, 0x00, 0x50, 0x50, 0xFF, 0x00, 0x93, 0x00, 0xD6, 0x00, 0xFF, 0xEC, 0xCC, 0x00, 0xC6, 0xD6, 0xEF, 0x00, 0xD6, 0xE7, 0xE7, 0x00, 0x90, 0xA9, 0xAD, 0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x66, 0x00, 0x00, 0x00, + 0x99, 0x00, 0x00, 0x00, 0xCC, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x33, 0x33, 0x00, 0x00, 0x33, 0x66, 0x00, 0x00, 0x33, 0x99, 0x00, 0x00, 0x33, 0xCC, 0x00, 0x00, 0x33, 0xFF, 0x00, 0x00, 0x66, 0x00, 0x00, 0x00, 0x66, 0x33, 0x00, 0x00, 0x66, 0x66, 0x00, 0x00, 0x66, 0x99, 0x00, 0x00, 0x66, 0xCC, 0x00, 0x00, 0x66, 0xFF, 0x00, 0x00, 0x99, 0x00, 0x00, 0x00, 0x99, 0x33, 0x00, 0x00, 0x99, 0x66, 0x00, 0x00, 0x99, 0x99, 0x00, 0x00, 0x99, 0xCC, 0x00, 0x00, 0x99, 0xFF, 0x00, 0x00, 0xCC, 0x00, 0x00, 0x00, 0xCC, 0x33, 0x00, 0x00, 0xCC, 0x66, 0x00, 0x00, 0xCC, 0x99, 0x00, 0x00, 0xCC, 0xCC, 0x00, 0x00, 0xCC, + 0xFF, 0x00, 0x00, 0xFF, 0x66, 0x00, 0x00, 0xFF, 0x99, 0x00, 0x00, 0xFF, 0xCC, 0x00, 0x33, 0x00, 0x00, 0x00, 0x33, 0x00, 0x33, 0x00, 0x33, 0x00, 0x66, 0x00, 0x33, 0x00, 0x99, 0x00, 0x33, 0x00, 0xCC, 0x00, 0x33, 0x00, 0xFF, 0x00, 0x33, 0x33, 0x00, 0x00, 0x33, 0x33, 0x33, 0x00, 0x33, 0x33, 0x66, 0x00, 0x33, 0x33, 0x99, 0x00, 0x33, 0x33, 0xCC, 0x00, 0x33, 0x33, 0xFF, 0x00, 0x33, 0x66, 0x00, 0x00, 0x33, 0x66, 0x33, 0x00, 0x33, 0x66, 0x66, 0x00, 0x33, 0x66, 0x99, 0x00, 0x33, 0x66, 0xCC, 0x00, 0x33, 0x66, 0xFF, 0x00, 0x33, 0x99, 0x00, 0x00, 0x33, 0x99, 0x33, 0x00, 0x33, 0x99, 0x66, 0x00, 0x33, 0x99, + 0x99, 0x00, 0x33, 0x99, 0xCC, 0x00, 0x33, 0x99, 0xFF, 0x00, 0x33, 0xCC, 0x00, 0x00, 0x33, 0xCC, 0x33, 0x00, 0x33, 0xCC, 0x66, 0x00, 0x33, 0xCC, 0x99, 0x00, 0x33, 0xCC, 0xCC, 0x00, 0x33, 0xCC, 0xFF, 0x00, 0x33, 0xFF, 0x33, 0x00, 0x33, 0xFF, 0x66, 0x00, 0x33, 0xFF, 0x99, 0x00, 0x33, 0xFF, 0xCC, 0x00, 0x33, 0xFF, 0xFF, 0x00, 0x66, 0x00, 0x00, 0x00, 0x66, 0x00, 0x33, 0x00, 0x66, 0x00, 0x66, 0x00, 0x66, 0x00, 0x99, 0x00, 0x66, 0x00, 0xCC, 0x00, 0x66, 0x00, 0xFF, 0x00, 0x66, 0x33, 0x00, 0x00, 0x66, 0x33, 0x33, 0x00, 0x66, 0x33, 0x66, 0x00, 0x66, 0x33, 0x99, 0x00, 0x66, 0x33, 0xCC, 0x00, 0x66, 0x33, + 0xFF, 0x00, 0x66, 0x66, 0x00, 0x00, 0x66, 0x66, 0x33, 0x00, 0x66, 0x66, 0x66, 0x00, 0x66, 0x66, 0x99, 0x00, 0x66, 0x66, 0xCC, 0x00, 0x66, 0x99, 0x00, 0x00, 0x66, 0x99, 0x33, 0x00, 0x66, 0x99, 0x66, 0x00, 0x66, 0x99, 0x99, 0x00, 0x66, 0x99, 0xCC, 0x00, 0x66, 0x99, 0xFF, 0x00, 0x66, 0xCC, 0x00, 0x00, 0x66, 0xCC, 0x33, 0x00, 0x66, 0xCC, 0x99, 0x00, 0x66, 0xCC, 0xCC, 0x00, 0x66, 0xCC, 0xFF, 0x00, 0x66, 0xFF, 0x00, 0x00, 0x66, 0xFF, 0x33, 0x00, 0x66, 0xFF, 0x99, 0x00, 0x66, 0xFF, 0xCC, 0x00, 0xCC, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xCC, 0x00, 0x99, 0x99, 0x00, 0x00, 0x99, 0x33, 0x99, 0x00, 0x99, 0x00, + 0x99, 0x00, 0x99, 0x00, 0xCC, 0x00, 0x99, 0x00, 0x00, 0x00, 0x99, 0x33, 0x33, 0x00, 0x99, 0x00, 0x66, 0x00, 0x99, 0x33, 0xCC, 0x00, 0x99, 0x00, 0xFF, 0x00, 0x99, 0x66, 0x00, 0x00, 0x99, 0x66, 0x33, 0x00, 0x99, 0x33, 0x66, 0x00, 0x99, 0x66, 0x99, 0x00, 0x99, 0x66, 0xCC, 0x00, 0x99, 0x33, 0xFF, 0x00, 0x99, 0x99, 0x33, 0x00, 0x99, 0x99, 0x66, 0x00, 0x99, 0x99, 0x99, 0x00, 0x99, 0x99, 0xCC, 0x00, 0x99, 0x99, 0xFF, 0x00, 0x99, 0xCC, 0x00, 0x00, 0x99, 0xCC, 0x33, 0x00, 0x66, 0xCC, 0x66, 0x00, 0x99, 0xCC, 0x99, 0x00, 0x99, 0xCC, 0xCC, 0x00, 0x99, 0xCC, 0xFF, 0x00, 0x99, 0xFF, 0x00, 0x00, 0x99, 0xFF, + 0x33, 0x00, 0x99, 0xCC, 0x66, 0x00, 0x99, 0xFF, 0x99, 0x00, 0x99, 0xFF, 0xCC, 0x00, 0x99, 0xFF, 0xFF, 0x00, 0xCC, 0x00, 0x00, 0x00, 0x99, 0x00, 0x33, 0x00, 0xCC, 0x00, 0x66, 0x00, 0xCC, 0x00, 0x99, 0x00, 0xCC, 0x00, 0xCC, 0x00, 0x99, 0x33, 0x00, 0x00, 0xCC, 0x33, 0x33, 0x00, 0xCC, 0x33, 0x66, 0x00, 0xCC, 0x33, 0x99, 0x00, 0xCC, 0x33, 0xCC, 0x00, 0xCC, 0x33, 0xFF, 0x00, 0xCC, 0x66, 0x00, 0x00, 0xCC, 0x66, 0x33, 0x00, 0x99, 0x66, 0x66, 0x00, 0xCC, 0x66, 0x99, 0x00, 0xCC, 0x66, 0xCC, 0x00, 0x99, 0x66, 0xFF, 0x00, 0xCC, 0x99, 0x00, 0x00, 0xCC, 0x99, 0x33, 0x00, 0xCC, 0x99, 0x66, 0x00, 0xCC, 0x99, + 0x99, 0x00, 0xCC, 0x99, 0xCC, 0x00, 0xCC, 0x99, 0xFF, 0x00, 0xCC, 0xCC, 0x00, 0x00, 0xCC, 0xCC, 0x33, 0x00, 0xCC, 0xCC, 0x66, 0x00, 0xCC, 0xCC, 0x99, 0x00, 0xCC, 0xCC, 0xCC, 0x00, 0xCC, 0xCC, 0xFF, 0x00, 0xCC, 0xFF, 0x00, 0x00, 0xCC, 0xFF, 0x33, 0x00, 0x99, 0xFF, 0x66, 0x00, 0xCC, 0xFF, 0x99, 0x00, 0xCC, 0xFF, 0xCC, 0x00, 0xCC, 0xFF, 0xFF, 0x00, 0xCC, 0x00, 0x33, 0x00, 0xFF, 0x00, 0x66, 0x00, 0xFF, 0x00, 0x99, 0x00, 0xCC, 0x33, 0x00, 0x00, 0xFF, 0x33, 0x33, 0x00, 0xFF, 0x33, 0x66, 0x00, 0xFF, 0x33, 0x99, 0x00, 0xFF, 0x33, 0xCC, 0x00, 0xFF, 0x33, 0xFF, 0x00, 0xFF, 0x66, 0x00, 0x00, 0xFF, 0x66, + 0x33, 0x00, 0xCC, 0x66, 0x66, 0x00, 0xFF, 0x66, 0x99, 0x00, 0xFF, 0x66, 0xCC, 0x00, 0xCC, 0x66, 0xFF, 0x00, 0xFF, 0x99, 0x00, 0x00, 0xFF, 0x99, 0x33, 0x00, 0xFF, 0x99, 0x66, 0x00, 0xFF, 0x99, 0x99, 0x00, 0xFF, 0x99, 0xCC, 0x00, 0xFF, 0x99, 0xFF, 0x00, 0xFF, 0xCC, 0x00, 0x00, 0xFF, 0xCC, 0x33, 0x00, 0xFF, 0xCC, 0x66, 0x00, 0xFF, 0xCC, 0x99, 0x00, 0xFF, 0xCC, 0xCC, 0x00, 0xFF, 0xCC, 0xFF, 0x00, 0xFF, 0xFF, 0x33, 0x00, 0xCC, 0xFF, 0x66, 0x00, 0xFF, 0xFF, 0x99, 0x00, 0xFF, 0xFF, 0xCC, 0x00, 0x66, 0x66, 0xFF, 0x00, 0x66, 0xFF, 0x66, 0x00, 0x66, 0xFF, 0xFF, 0x00, 0xFF, 0x66, 0x66, 0x00, 0xFF, 0x66, + 0xFF, 0x00, 0xFF, 0xFF, 0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x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x07, + 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x81, 0xFF, 0x00, 0x00, 0xC3, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, +}; + HWND mainwindow, entryfield, checkable_menuitem, @@ -259,26 +280,29 @@ { int i,len; fp = fopen( current_file, "r" ); - lp = (char **)calloc( 1000,sizeof(char *)); - /* should test for out of memory */ - max_linewidth=0; - for ( i = 0; i < 1000; i++ ) + if ( fp ) { - lp[i] = (char *)calloc(1, 1025); - if ( fgets( lp[i], 1024, fp ) == NULL ) - break; - len = (int)strlen( lp[i] ); - if ( len > max_linewidth ) - max_linewidth = len; - if ( lp[i][len - 1] == '\n' ) - lp[i][len - 1] = '\0'; + lp = (char **)calloc( 1000,sizeof(char *)); + /* should test for out of memory */ + max_linewidth=0; + for ( i = 0; i < 1000; i++ ) + { + lp[i] = (char *)calloc(1, 1025); + if ( fgets( lp[i], 1024, fp ) == NULL ) + break; + len = (int)strlen( lp[i] ); + if ( len > max_linewidth ) + max_linewidth = len; + if ( lp[i][len - 1] == '\n' ) + lp[i][len - 1] = '\0'; + } + num_lines = i; + fclose( fp ); + dw_scrollbar_set_range(hscrollbar, max_linewidth, cols); + dw_scrollbar_set_pos(hscrollbar, 0); + dw_scrollbar_set_range(vscrollbar, num_lines, rows); + dw_scrollbar_set_pos(vscrollbar, 0); } - num_lines = i; - fclose( fp ); - dw_scrollbar_set_range(hscrollbar, max_linewidth, cols); - dw_scrollbar_set_pos(hscrollbar, 0); - dw_scrollbar_set_range(vscrollbar, num_lines, rows); - dw_scrollbar_set_pos(vscrollbar, 0); } void draw_file( int row, int col ) @@ -691,8 +715,11 @@ int DWSIGNAL switch_page_cb( HWND window, unsigned long page_num, void *itemdata ) { FILE *fp=fopen("log","a"); - fprintf(fp,"DW_SIGNAL_SWITCH_PAGE: Window: %x PageNum: %u Itemdata: %x\n", (unsigned int)window, (unsigned int)page_num, (unsigned int)itemdata ); - fclose(fp); + if ( fp ) + { + fprintf(fp,"DW_SIGNAL_SWITCH_PAGE: Window: %x PageNum: %u Itemdata: %x\n", (unsigned int)window, (unsigned int)page_num, (unsigned int)itemdata ); + fclose(fp); + } return 0; } @@ -1161,7 +1188,7 @@ dw_signal_connect( abutton1, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(change_color_yellow_callback), NULL ); dw_box_pack_start( filetoolbarbox, 0, 25, 5, FALSE, FALSE, 0 ); - abutton1 = dw_bitmapbutton_new_from_file( "Should be under Top button", 0, "junk" ); + abutton1 = dw_bitmapbutton_new_from_data( "A button from data", 0, folder_ico, 1718 ); dw_box_pack_start( filetoolbarbox, abutton1, 25, 25, FALSE, FALSE, 0); dw_signal_connect( abutton1, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(redraw_button_box_callback), NULL ); dw_box_pack_start( filetoolbarbox, 0, 25, 5, FALSE, FALSE, 0 ); diff -r b58032a619b9 -r b905fd8e7fd1 win/dw.c --- a/win/dw.c Tue Jun 28 20:30:29 2011 +0000 +++ b/win/dw.c Tue Jun 28 23:38:59 2011 +0000 @@ -47,6 +47,15 @@ #define MIN(a, b) (((a) < (b)) ? (a) : (b)) #endif +/* + * For the dw*from_data() functions, a temporary file is required to write + * the contents of the image to so it can be loaded by the Win32 API + * We use _tempnam() which uses TMP env variable by default. It can be passed + * an alternate temporary directory if TMP is not set, so we get the value + * of TEMP and store it here. + */ +static char _dw_alternate_temp_dir[MAX_PATH]; + FILE *dbgfp = NULL; int main(int argc, char *argv[]); @@ -3540,7 +3549,7 @@ WNDCLASS wc; int z; INITCOMMONCONTROLSEX icc; - char *fname; + char *fname, *alttmpdir; HFONT oldfont; /* Initialize our thread local storage */ @@ -3666,6 +3675,17 @@ dbgfp = fopen( fname, "w" ); } /* + * Get an alternate temporary directory in case TMP doesn't exist + */ + if ( (alttmpdir = getenv( "TEMP" ) ) == NULL ) + { + strcpy( _dw_alternate_temp_dir, "c:\\tmp" ); + } + else + { + strcpy( _dw_alternate_temp_dir, alttmpdir ); + } + /* * Get screen size. Used to make calls to dw_screen_width() * and dw_screen-height() quicker, but to alos limit the * default size of windows. @@ -4003,7 +4023,7 @@ int z, size = 9; LOGFONT lf; HDC hdc = GetDC(handle); - + for(z=0;zgrouphwnd; } } - + /* This needs to be after we get the correct handle */ oldfont = (HFONT)SendMessage(handle, WM_GETFONT, 0, 0); hfont = _acquire_font(handle, fontname); - + if (fontname) { if(cinfo) @@ -4151,14 +4171,14 @@ char *str = NULL; char *bold = ""; char *italic = ""; - + if(currfont && *currfont) lf = _get_logfont(NULL, currfont); - + cf.lStructSize = sizeof(cf); cf.Flags = CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT; - cf.lpLogFont = &lf; - + cf.lpLogFont = &lf; + if(ChooseFont(&cf)) { str = (char *)malloc( 100 ); @@ -4166,7 +4186,7 @@ { int height; HDC hdc = GetDC(NULL); - + if ( lf.lfWeight > FW_MEDIUM ) bold = " Bold"; if ( lf.lfItalic ) @@ -4213,7 +4233,7 @@ { int height; HDC hdc = GetDC(handle); - + if ( lf.lfWeight > FW_MEDIUM ) bold = " Bold"; if ( lf.lfItalic ) @@ -5406,7 +5426,7 @@ if ( !(bubble = calloc(1, sizeof(BubbleButton))) ) return 0; - file = tmpnam( NULL ); + file = _tempnam( _dw_alternate_temp_dir, "dw" ); if ( file != NULL ) { fp = fopen( file, "wb" ); @@ -5428,9 +5448,11 @@ else { unlink( file ); + free( file ); return 0; } unlink( file ); + free( file ); } tmp = CreateWindow( BUTTONCLASSNAME, @@ -5769,7 +5791,7 @@ } else if (data) { - file = tmpnam( NULL ); + file = _tempnam( _dw_alternate_temp_dir, "dw" ); if ( file != NULL ) { fp = fopen( file, "wb" ); @@ -5785,9 +5807,11 @@ else { unlink( file ); + free( file ); return; } unlink( file ); + free( file ); } if (icon == 0 && hbitmap == 0) return; @@ -5963,7 +5987,7 @@ { int z, x = 0; Item *tmpitem, *thisitem = thisbox->items; - + /* Do some sanity bounds checking */ if(index < 0) index = 0; @@ -6048,7 +6072,7 @@ * Parameters: * box: Window handle of the box to be packed into. * item: Window handle of the item to be back. - * index: 0 based index of packed items. + * index: 0 based index of packed items. * width: Width in pixels of the item or -1 to be self determined. * height: Height in pixels of the item or -1 to be self determined. * hsize: TRUE if the window (widget) should expand horizontally to fill space given. @@ -6073,7 +6097,7 @@ */ void API dw_box_pack_start(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad) { - /* 65536 is the table limit on GTK... + /* 65536 is the table limit on GTK... * seems like a high enough value we will never hit it here either. */ _dw_box_pack(box, item, 65536, width, height, hsize, vsize, pad, "dw_box_pack_start()"); @@ -7638,7 +7662,7 @@ if ( !data ) return 0; - file = tmpnam( NULL ); + file = _tempnam( _dw_alternate_temp_dir, "dw" ); if ( file != NULL ) { fp = fopen( file, "wb" ); @@ -7651,9 +7675,11 @@ else { unlink( file ); + free( file ); return 0; } unlink( file ); + free( file ); } return (HICN)icon; } @@ -8887,7 +8913,7 @@ pixmap->handle = handle; - file = tmpnam( NULL ); + file = _tempnam( _dw_alternate_temp_dir, "dw" ); if ( file != NULL ) { fp = fopen( file, "wb" ); @@ -8901,10 +8927,12 @@ else { unlink( file ); + free( file ); free( pixmap ); return NULL; } unlink( file ); + free( file ); } if ( !pixmap->hbm )