static void add_url(char *url) { static struct connection *tail; char *e; struct connection *conn = must_alloc(sizeof(struct connection)); /* Hack for BME files. */ e = strchr(url, ' '); if (e) *e = '\0'; conn->out = -1; conn->url = must_strdup(url); /* isolate the host from original url */ e = is_http(url); if (e) e = strchr(e, '/'); else e = strchr(url + 1, '/'); if (e) *e = '\0'; conn->host = must_strdup(url); if (comics) tail->next = conn; else comics = head = conn; tail = conn; ++n_comics; }
static void cd_comics_dir(int clean) { if (!comics_dir) { #ifdef WIN32 char *homedrive = getenv("HOMEDRIVE"); char *homepath = getenv("HOMEPATH"); char home[64]; snprintf(home, sizeof(home), "%s%s", homedrive, homepath); #else char *home = getenv("HOME"); #endif if (home) { comics_dir = must_alloc(strlen(home) + 10); sprintf(comics_dir, "%s/comics", home); } else comics_dir = must_strdup("comics"); } if (chdir(comics_dir)) { my_perror(comics_dir); exit(1); } if (clean) clean_dir(); }
/* * This is a special case - return a copy of @entry * prepending 'name='. I.e. turn systemd into name=systemd. * Do not fail. */ static char *must_prefix_named(char *entry) { char *ret; size_t len = strlen(entry); ret = must_alloc(len + 6); snprintf(ret, len + 6, "name=%s", entry); return ret; }
void *m_malloc(size_t amount) { #ifdef MDEBUG unsigned short *r2, x; #endif void *r; r = must_alloc(malloc(amount)); #ifdef MDEBUG r2= r; x= (unsigned short)amount ^ 0xf000; while (amount >= 2) { *r2++= x; amount -= 2; } #endif return r; }
/* make_symbol -- create a symbol, but don't put it in the hash table */ symbol make_symbol(const char *name) { symbol s = (symbol) must_alloc(sizeof(struct _symbol), "symbol table entry"); s->s_name = must_strdup(name); s->s_seg = UNDEFINED; s->s_kind = X_NONE; s->s_value = -1; s->s_next = NULL; s->s_index = 0; s->s_uchain = -1; s->s_check = s->s_nlines = 0; s->s_file = NULL; buf_grow(dict); dict[ndict++] = s; return s; }
void *m_malloc(size_t amount) { #ifdef MDEBUG unsigned short *ptr_canary, canary; #endif void *ptr; ptr = must_alloc(malloc(amount)); #ifdef MDEBUG ptr_canary = ptr; canary = (unsigned short)amount ^ 0xf000; while (amount >= 2) { *ptr_canary++ = canary; amount -= 2; } #endif return ptr; }
char * m_strndup(const char *str, size_t n) { return must_alloc(strndup(str, n)); }
char * m_strdup(const char *str) { return must_alloc(strdup(str)); }
void *m_realloc(void *r, size_t amount) { return must_alloc(realloc(r, amount)); }
void * m_calloc(size_t size) { return must_alloc(calloc(1, size)); }
void * m_calloc(size_t nmemb, size_t size) { return must_alloc(calloc(nmemb, size)); }
int uundo_put(GEM_WINDOW *gwnd) { VXIMAGE *vimage ; long taille ; int xy[8] ; int type_alloc ; if ( gwnd == NULL) return( -1 ) ; if ( config.use_redo == 0 ) return( 0 ) ; vimage = (VXIMAGE *) gwnd->Extension ; FreeUUndoBuffer( gwnd ) ; vimage->Redo = AllocateUUndoBuffer( gwnd ) ; if ( vimage->Redo == NULL ) return( -3 ) ; vimage->Redo->w = vimage->raster.fd_w ; vimage->Redo->h = vimage->raster.fd_h ; vimage->Redo->mitem = REDO ; if ( !Truecolor && vimage->inf_img.nb_cpal && vimage->inf_img.palette ) { size_t size ; vimage->Redo->nb_cpal = (int) vimage->inf_img.nb_cpal ; size = vimage->Redo->nb_cpal * 3 * sizeof(int) ; vimage->Redo->palette = (int *) malloc( size ) ; if ( vimage->Redo->palette == NULL ) { FreeUndoBuffer( vimage->Redo ) ; vimage->Redo = NULL ; return( -1 ) ; } memcpy( vimage->Redo->palette, vimage->inf_img.palette, size ) ; } taille = img_size( vimage->Redo->w, vimage->Redo->h, nb_plane ) ; vimage->Redo->original_width = vimage->raster.fd_w ; vimage->Redo->original_height = vimage->raster.fd_h ; type_alloc = must_alloc( vimage->Redo->mitem, taille, vimage->Redo->spec ) ; if ( type_alloc ) { xy[0] = vimage->Redo->x ; xy[1] = vimage->Redo->y ; xy[2] = vimage->Redo->x + vimage->Redo->w-1 ; xy[3] = vimage->Redo->y + vimage->Redo->h-1 ; xy[4] = 0 ; xy[5] = 0 ; xy[6] = vimage->Redo->w-1 ; xy[7] = vimage->Redo->h-1 ; if ( type_alloc == 1 ) { vimage->Redo->img.fd_w = vimage->Redo->w ; vimage->Redo->img.fd_w = vimage->Redo->h ; vimage->Redo->img.fd_wdwidth = vimage->Redo->w / 16 ; if ( vimage->Redo->w % 16 ) vimage->Redo->img.fd_wdwidth++ ; vimage->Redo->img.fd_nplanes = nb_plane ; vimage->Redo->img.fd_addr = malloc( taille ) ; if ( vimage->Redo->img.fd_addr == NULL ) return( -1 ) ; vro_cpyfm( handle, S_ONLY, xy, &vimage->raster, &vimage->Redo->img ) ; } else undo_disk( gwnd, vimage->Redo, xy, &vimage->raster ) ; } return( 0 ) ; }
int undo_put(GEM_WINDOW *gwnd, int x1, int y1, int x2, int y2, int type_modif, XUNDO *xundo) { VXIMAGE *vimage ; UNDO_DEF *undo_buf ; void *spec = NULL ; long taille = 0 ; int xy[8] ; int wx, wy ; int larg, temp ; int type_alloc ; /* int redo = 0 ;*/ int err = 0 ; if ( config.nb_undo == 0 ) return( -1 ) ; if ( !GWIsWindowValid( gwnd ) ) return( -1 ) ; undo_buf = AllocateNewUndoBuffer( gwnd ) ; if ( undo_buf == NULL ) return( -3 ) ; vimage = (VXIMAGE *) gwnd->Extension ; /* if ( type_modif & REDO ) redo = 1 ; type_modif &= ~REDO ; */ if ( xundo ) { if ( xundo->nb_bytes_to_allocate_and_copy > 0 ) { spec = malloc( xundo->nb_bytes_to_allocate_and_copy ) ; if ( spec ) memcpy( spec, xundo->spec, xundo->nb_bytes_to_allocate_and_copy ) ; else return( -3 ) ; } } if ( x1 > x2 ) { temp = x1 ; x1 = x2 ; x2 = temp ; } if ( y1 > y2 ) { temp = y1 ; y1 = y2 ; y2 = temp ; } wx = x2 - x1 + 1 ; wy = y2 - y1 + 1 ; larg = ALIGN16( wx ) ; if ( need_palette( type_modif, spec ) ) { size_t size ; undo_buf->nb_cpal = (int) vimage->inf_img.nb_cpal ; size = undo_buf->nb_cpal * 3 * sizeof(int) ; undo_buf->palette = (int *) malloc( size ) ; if ( undo_buf->palette == NULL ) return( -3 ) ; else memcpy( undo_buf->palette, vimage->inf_img.palette, size ) ; } if ( x1 < 0 ) taille = 0 ; /* Pas de modif sur l'image (palette sans doute) */ else taille = img_size( larg, wy, nb_plane ) ; undo_buf->original_width = vimage->raster.fd_w ; undo_buf->original_height = vimage->raster.fd_h ; type_alloc = must_alloc( type_modif, taille, spec ) ; if ( type_alloc == 0 ) /* Est-il n‚cessaire d'allouer de la m‚moire ? */ { undo_buf->img.fd_addr = NULL ; undo_buf->x = x1 ; undo_buf->y = y1 ; undo_buf->w = wx ; undo_buf->h = wy ; undo_buf->mitem = type_modif ; undo_buf->spec = spec ; } else { if ( type_alloc == 2 ) undo_buf->disk = 1 ; else undo_buf->img.fd_addr = malloc( taille ) ; if ( undo_buf->disk || ( undo_buf->img.fd_addr != NULL ) ) { undo_buf->img.fd_w = larg ; /* Si possible, on m‚morise */ undo_buf->img.fd_h = wy ; /* Les nouvelles donn‚es */ undo_buf->img.fd_wdwidth = larg/16 ; undo_buf->img.fd_nplanes = nb_plane ; undo_buf->img.fd_stand = 0 ; undo_buf->gwindow = gwnd ; undo_buf->x = x1 ; undo_buf->y = y1 ; undo_buf->w = wx ; undo_buf->h = wy ; undo_buf->mitem = type_modif ; undo_buf->spec = spec ; xy[0] = x1 ; xy[1] = y1 ; xy[2] = x2 ; xy[3] = y2 ; xy[4] = 0 ; xy[5] = 0 ; xy[6] = wx-1 ; xy[7] = wy-1 ; if ( undo_buf->disk ) undo_disk( gwnd, undo_buf, xy, &vimage->raster ) ; else vro_cpyfm( handle, S_ONLY, xy, &vimage->raster, &undo_buf->img ) ; } } if ( !err ) { LIST_ENTRY* entry = GET_LIST_ENTRY_FROM_UNDO_DEF( undo_buf ) ; InsertHeadList( &vimage->UndoListHead, entry ) ; if ( type_modif != REDO ) FreeUUndoBuffer( gwnd ) ; } else { FreeUndoBuffer( undo_buf ) ; form_stop( 1, msg[MSG_UNDOERROR] ) ; } return( err ) ; }