Ticket #2085: 2085-edit.c-replacing-g_string_sprintf-by-g_strdup_printf.patch

File 2085-edit.c-replacing-g_string_sprintf-by-g_strdup_printf.patch, 3.1 KB (added by vit_r, 15 years ago)

edit.c-replacing-g_string_sprintf-by-g_strdup_printf

  • src/editor/edit.c

    From 24ad244ee52ed76b609a1c3236edc3da73439ee1 Mon Sep 17 00:00:00 2001
    From: Vit Rosin <vit_r@list.ru>
    Date: Thu, 4 Mar 2010 11:34:56 +0000
    Subject: [PATCH]  edit.c replacing g_string_sprintf by g_strdup_printf
    
    ---
     src/editor/edit.c |   32 ++++++++++++++------------------
     1 files changed, 14 insertions(+), 18 deletions(-)
    
    diff --git a/src/editor/edit.c b/src/editor/edit.c
    index b88e294..c805737 100644
    a b edit_load_file_fast (WEdit *edit, const char *filename) 
    296296    buf2 = edit->curs2 >> S_EDIT_BUF_SIZE; 
    297297    edit->utf8 = 0; 
    298298    if ((file = mc_open (filename, O_RDONLY | O_BINARY)) == -1) { 
    299         GString *errmsg = g_string_new(NULL); 
    300         g_string_sprintf(errmsg, _(" Cannot open %s for reading "), filename); 
    301         edit_error_dialog (_("Error"), get_sys_error (errmsg->str)); 
    302         g_string_free (errmsg, TRUE); 
     299        gchar *errmsg; 
     300 
     301        errmsg = g_strdup_printf (_(" Cannot open %s for reading "), filename); 
     302        edit_error_dialog (_("Error"), errmsg); 
     303        g_free (errmsg); 
    303304        return 1; 
    304305    } 
    305306 
    static int 
    555556check_file_access (WEdit *edit, const char *filename, struct stat *st) 
    556557{ 
    557558    int file; 
    558     GString *errmsg = (GString *) 0; 
     559    gchar *errmsg = NULL; 
    559560 
    560561    /* Try opening an existing file */ 
    561562    file = mc_open (filename, O_NONBLOCK | O_RDONLY | O_BINARY, 0666); 
    check_file_access (WEdit *edit, const char *filename, struct stat *st) 
    570571                     O_NONBLOCK | O_RDONLY | O_BINARY | O_CREAT | O_EXCL, 
    571572                     0666); 
    572573        if (file < 0) { 
    573             g_string_sprintf (errmsg = g_string_new (NULL), 
    574                 _(" Cannot open %s for reading "), filename); 
     574            errmsg = g_strdup_printf (_(" Cannot open %s for reading "), filename); 
    575575            goto cleanup; 
    576576        } else { 
    577577            /* New file, delete it if it's not modified or saved */ 
    check_file_access (WEdit *edit, const char *filename, struct stat *st) 
    581581 
    582582    /* Check what we have opened */ 
    583583    if (mc_fstat (file, st) < 0) { 
    584         g_string_sprintf (errmsg = g_string_new (NULL), 
    585             _(" Cannot get size/permissions for %s "), filename); 
     584        errmsg = g_strdup_printf (_(" Cannot get size/permissions for %s "), filename); 
    586585        goto cleanup; 
    587586    } 
    588587 
    589588    /* We want to open regular files only */ 
    590589    if (!S_ISREG (st->st_mode)) { 
    591         g_string_sprintf (errmsg = g_string_new (NULL), 
    592             _(" %s is not a regular file "), filename); 
     590        errmsg = g_strdup_printf (_(" %s is not a regular file "), filename); 
    593591        goto cleanup; 
    594592    } 
    595593 
    check_file_access (WEdit *edit, const char *filename, struct stat *st) 
    601599        edit->delete_file = 0; 
    602600    } 
    603601 
    604     if (st->st_size >= SIZE_LIMIT) { 
    605         g_string_sprintf (errmsg = g_string_new (NULL), 
    606             _(" File %s is too large "), filename); 
    607     } 
     602    if (st->st_size >= SIZE_LIMIT) 
     603        errmsg = g_strdup_printf (_(" File %s is too large "), filename); 
    608604 
    609605cleanup: 
    610606    (void) mc_close (file); 
    611     if (errmsg) { 
    612         edit_error_dialog (_("Error"), errmsg->str); 
    613         g_string_free (errmsg, TRUE); 
     607    if (errmsg != NULL) { 
     608        edit_error_dialog (_("Error"), errmsg); 
     609        g_free (errmsg); 
    614610        return 1; 
    615611    } 
    616612    return 0;