[gimp/gimp-2-10] plug-ins: Add 'dir-make' procedure to Script-fu.
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/gimp-2-10] plug-ins: Add 'dir-make' procedure to Script-fu.
- Date: Sat, 24 Apr 2021 13:27:05 +0000 (UTC)
commit c447c7e7b542424bc08610284721cb505b13e6fc
Author: saul <saul crazyauntgail com>
Date: Mon Mar 3 15:34:54 2014 -0500
plug-ins: Add 'dir-make' procedure to Script-fu.
Closes: GNOME/gimp#541
Reviewer note: thanks to Stanislav Grinkov for cleaning up and reworking
a bit the patch, such as renaming the procedure to dir-make, as per
Kevin Cozens' review.
(cherry picked from commit 11906fa82cd982287ff391968b09b0ac02b40b9a)
plug-ins/script-fu/ftx/ftx-functions.txt | 11 +++++++++
plug-ins/script-fu/ftx/ftx.c | 40 ++++++++++++++++++++++++++++++++
2 files changed, 51 insertions(+)
---
diff --git a/plug-ins/script-fu/ftx/ftx-functions.txt b/plug-ins/script-fu/ftx/ftx-functions.txt
index e681261a1e..5365bc52c3 100644
--- a/plug-ins/script-fu/ftx/ftx-functions.txt
+++ b/plug-ins/script-fu/ftx/ftx-functions.txt
@@ -83,6 +83,17 @@ portable to different operating systems.
Close directory stream. No further calls to read-dir-entry should
be performed.
+(dir-make dirname . mode)
+ dirname: string
+ mode: integer representing permissions
+
+ Create the directory specified, setting the directory permissions based
+ upon the optional mode argument (taking into account the current
+ umask). If no mode is specified then use the default (umask)
+ permissions. Returns #t if the operation succeeds, otherwise #f.
+ Possible reasons for failure are that the directory already exists,
+ the user is not authorized to create it, or the mode is incorrectly
+ specified).
*Time (available if HAVE_TIME is defined in tsx.h)
diff --git a/plug-ins/script-fu/ftx/ftx.c b/plug-ins/script-fu/ftx/ftx.c
index 346a90a92c..b1c1aa745e 100644
--- a/plug-ins/script-fu/ftx/ftx.c
+++ b/plug-ins/script-fu/ftx/ftx.c
@@ -8,6 +8,7 @@
#include "config.h"
+#include <sys/types.h>
#include <sys/stat.h>
#if HAVE_UNISTD_H
#include <unistd.h>
@@ -48,6 +49,7 @@ pointer foreign_diropenstream(scheme *sc, pointer args);
pointer foreign_dirreadentry(scheme *sc, pointer args);
pointer foreign_dirrewind(scheme *sc, pointer args);
pointer foreign_dirclosestream(scheme *sc, pointer args);
+pointer foreign_mkdir(scheme *sc, pointer args);
pointer foreign_getenv(scheme *sc, pointer args);
pointer foreign_time(scheme *sc, pointer args);
@@ -243,6 +245,41 @@ pointer foreign_dirclosestream(scheme *sc, pointer args)
return sc->T;
}
+pointer foreign_mkdir(scheme *sc, pointer args)
+{
+ pointer first_arg;
+ pointer rest;
+ pointer second_arg;
+ char *dirname;
+ mode_t mode;
+ int retcode;
+
+ if (args == sc->NIL)
+ return sc->F;
+
+ first_arg = sc->vptr->pair_car(args);
+ if (!sc->vptr->is_string(first_arg))
+ return sc->F;
+ dirname = sc->vptr->string_value(first_arg);
+ dirname = g_filename_from_utf8 (dirname, -1, NULL, NULL, NULL);
+
+ rest = sc->vptr->pair_cdr(args);
+ if (sc->vptr->is_pair(rest)) /* optional mode argument */
+ {
+ second_arg = sc->vptr->pair_car(rest);
+ if (!sc->vptr->is_integer(second_arg))
+ return sc->F;
+ mode = sc->vptr->ivalue(second_arg);
+ }
+ else
+ mode = 0777;
+
+ retcode = mkdir(dirname, (mode_t)mode);
+ if (retcode == 0)
+ return sc->T;
+ else
+ return sc->F;
+}
pointer foreign_getenv(scheme *sc, pointer args)
{
@@ -365,6 +402,9 @@ void init_ftx (scheme *sc)
sc->vptr->scheme_define(sc, sc->global_env,
sc->vptr->mk_symbol(sc,"dir-close-stream"),
sc->vptr->mk_foreign_func(sc, foreign_dirclosestream));
+ sc->vptr->scheme_define(sc, sc->global_env,
+ sc->vptr->mk_symbol(sc,"dir-make"),
+ sc->vptr->mk_foreign_func(sc, foreign_mkdir));
for (i = 0; file_type_constants[i].name != NULL; ++i)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]