Changeset 7 for trunk/gtk/util.c


Ignore:
Timestamp:
Jan 12, 2006, 6:40:47 PM (16 years ago)
Author:
root
Message:

Update 2005-11-24

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/util.c

    r5 r7  
    2525*/
    2626
     27#include <sys/types.h>
     28#include <sys/stat.h>
     29#include <errno.h>
    2730#include <stdarg.h>
     31#include <string.h>
     32
    2833#include <gtk/gtk.h>
    2934
     
    3136
    3237static void
    33 errcb(GtkWidget *widget, int resp, gpointer data);
     38errcb(GtkWidget *wind, int resp, gpointer data);
    3439
    3540gboolean
     
    5156}
    5257
     58gboolean
     59mkdir_p(const char *name, mode_t mode) {
     60  struct stat sb;
     61  char *parent;
     62  gboolean ret;
     63  int oerrno;
     64
     65  if(0 != stat(name, &sb)) {
     66    if(ENOENT != errno)
     67      return FALSE;
     68    parent = g_path_get_dirname(name);
     69    ret = mkdir_p(parent, mode);
     70    oerrno = errno;
     71    g_free(parent);
     72    errno = oerrno;
     73    return (ret ? (0 == mkdir(name, mode)) : FALSE);
     74  }
     75
     76  if(!S_ISDIR(sb.st_mode)) {
     77    errno = ENOTDIR;
     78    return FALSE;
     79  }
     80
     81  return TRUE;
     82}
     83
    5384GtkWidget *
    54 errmsg(GtkWidget *wind, const char *format, ...) {
     85errmsg(GtkWindow *wind, const char *format, ...) {
    5586  GtkWidget *dialog;
    5687  va_list ap;
     
    6495
    6596GtkWidget *
    66 errmsg_full(GtkWidget *wind, errfunc_t func, void *data,
     97errmsg_full(GtkWindow *wind, errfunc_t func, void *data,
    6798            const char *format, ...) {
    6899  GtkWidget *dialog;
     
    77108
    78109GtkWidget *
    79 verrmsg(GtkWidget *wind, errfunc_t func, void *data,
     110verrmsg(GtkWindow *wind, errfunc_t func, void *data,
    80111        const char *format, va_list ap) {
    81112  GtkWidget *dialog;
     
    89120      NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "%s", msg);
    90121  else
    91     dialog = gtk_message_dialog_new(
    92       GTK_WINDOW(wind), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
     122    dialog = gtk_message_dialog_new(wind,
     123      GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
    93124      GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "%s", msg);
    94125
     
    99130  g_signal_connect(dialog, "response", G_CALLBACK(errcb), funcdata);
    100131  if(NULL != wind)
    101     gtk_widget_show_all(dialog);
     132    gtk_widget_show(dialog);
    102133  g_free(msg);
    103134
Note: See TracChangeset for help on using the changeset viewer.