build: Enable -fno-strict-aliasing
[glib.git] / gio / gio-tool-mkdir.c
blob3d7b50a0298c587a929e82f7e0b05eee10e27bd7
1 /*
2 * Copyright 2015 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
17 * Author: Matthias Clasen <mclasen@redhat.com>
20 #include "config.h"
22 #include <gio/gio.h>
23 #include <gi18n.h>
25 #include "gio-tool.h"
28 static gboolean parent = FALSE;
30 static const GOptionEntry entries[] = {
31 { "parent", 'p', 0, G_OPTION_ARG_NONE, &parent, N_("Create parent directories"), NULL },
32 { NULL }
35 int
36 handle_mkdir (int argc, char *argv[], gboolean do_help)
38 GOptionContext *context;
39 gchar *param;
40 GError *error = NULL;
41 GFile *file;
42 int retval = 0;
43 int i;
45 g_set_prgname ("gio mkdir");
47 /* Translators: commandline placeholder */
48 param = g_strdup_printf ("%s...", _("LOCATION"));
49 context = g_option_context_new (param);
50 g_free (param);
51 g_option_context_set_help_enabled (context, FALSE);
52 g_option_context_set_summary (context, _("Create directories."));
53 g_option_context_set_description (context,
54 _("gio mkdir is similar to the traditional mkdir utility, but using GIO\n"
55 "locations instead of local files: for example, you can use something\n"
56 "like smb://server/resource/mydir as location."));
57 g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
59 if (do_help)
61 show_help (context, NULL);
62 g_option_context_free (context);
63 return 0;
66 if (!g_option_context_parse (context, &argc, &argv, &error))
68 show_help (context, error->message);
69 g_error_free (error);
70 g_option_context_free (context);
71 return 1;
74 if (argc < 2)
76 show_help (context, _("No locations given"));
77 g_option_context_free (context);
78 return 1;
81 g_option_context_free (context);
83 for (i = 1; i < argc; i++)
85 file = g_file_new_for_commandline_arg (argv[i]);
86 error = NULL;
87 if (parent)
89 if (!g_file_make_directory_with_parents (file, NULL, &error))
91 print_file_error (file, error->message);
92 g_error_free (error);
93 retval = 1;
96 else
98 if (!g_file_make_directory (file, NULL, &error))
100 print_file_error (file, error->message);
101 g_error_free (error);
102 retval = 1;
104 g_object_unref (file);
108 return retval;