g_file_new_for_path
g_file_new_for_uri
g_file_new_for_commandline_arg
+g_file_new_for_commandline_arg_and_cwd
g_file_new_tmp
g_file_parse_name
g_file_dup
g_application_command_line_get_arguments
g_application_command_line_get_cwd
g_application_command_line_get_environ
+g_application_command_line_create_file_for_arg
g_application_command_line_getenv
g_application_command_line_get_is_remote
g_application_command_line_get_platform_data
#include "gapplicationcommandline.h"
#include "glibintl.h"
+#include "gfile.h"
#include <string.h>
#include <stdio.h>
else
return NULL;
}
+
+/**
+ * g_application_command_line_create_file_for_arg:
+ * @cmdline: a #GApplicationCommandLine
+ * @arg: an argument from @cmdline
+ *
+ * Creates a #GFile corresponding to a filename that was given as part
+ * of the invocation of @cmdline.
+ *
+ * This differs from g_file_new_for_commandline_arg() in that it
+ * resolves relative pathnames using the current working directory of
+ * the invoking process rather than the local process.
+ *
+ * Returns: (transfer full): a new #GFile
+ *
+ * Since: 2.36
+ **/
+GFile *
+g_application_command_line_create_file_for_arg (GApplicationCommandLine *cmdline,
+ const gchar *arg)
+{
+ g_return_val_if_fail (arg != NULL, NULL);
+
+ if (cmdline->priv->cwd)
+ return g_file_new_for_commandline_arg_and_cwd (arg, cmdline->priv->cwd);
+
+ g_warning ("Requested creation of GFile for commandline invocation that did not send cwd. "
+ "Using cwd of local process to resolve relative path names.");
+
+ return g_file_new_for_commandline_arg (arg);
+}
GVariant * g_application_command_line_get_platform_data (GApplicationCommandLine *cmdline);
+GLIB_AVAILABLE_IN_2_36
+GFile * g_application_command_line_create_file_for_arg (GApplicationCommandLine *cmdline,
+ const gchar *arg);
+
G_END_DECLS
#endif /* __G_APPLICATION_COMMAND_LINE_H__ */
return *p == ':';
}
+static GFile *
+new_for_cmdline_arg (const gchar *arg,
+ const gchar *cwd)
+{
+ GFile *file;
+ char *filename;
+
+ if (g_path_is_absolute (arg))
+ return g_file_new_for_path (arg);
+
+ if (has_valid_scheme (arg))
+ return g_file_new_for_uri (arg);
+
+ if (cwd == NULL)
+ {
+ char *current_dir;
+
+ current_dir = g_get_current_dir ();
+ filename = g_build_filename (current_dir, arg, NULL);
+ g_free (current_dir);
+ }
+ else
+ filename = g_build_filename (cwd, arg, NULL);
+
+ file = g_file_new_for_path (filename);
+ g_free (filename);
+
+ return file;
+}
+
/**
* g_file_new_for_commandline_arg:
* @arg: a command line string
GFile *
g_file_new_for_commandline_arg (const char *arg)
{
- GFile *file;
- char *filename;
- char *current_dir;
-
g_return_val_if_fail (arg != NULL, NULL);
- if (g_path_is_absolute (arg))
- return g_file_new_for_path (arg);
-
- if (has_valid_scheme (arg))
- return g_file_new_for_uri (arg);
-
- current_dir = g_get_current_dir ();
- filename = g_build_filename (current_dir, arg, NULL);
- g_free (current_dir);
+ return new_for_cmdline_arg (arg, NULL);
+}
- file = g_file_new_for_path (filename);
- g_free (filename);
+/**
+ * g_file_new_for_commandline_arg_and_cwd:
+ * @arg: a command line string
+ * @cwd: the current working directory of the commandline
+ *
+ * Creates a #GFile with the given argument from the command line.
+ *
+ * This function is similar to g_file_new_for_commandline_arg() except
+ * that it allows for passing the current working directory as an
+ * argument instead of using the current working directory of the
+ * process.
+ *
+ * This is useful if the commandline argument was given in a context
+ * other than the invocation of the current process.
+ *
+ * See also g_application_command_line_create_file_for_arg().
+ *
+ * Returns: (transfer full): a new #GFile
+ *
+ * Since: 2.36
+ **/
+GFile *
+g_file_new_for_commandline_arg_and_cwd (const gchar *arg,
+ const gchar *cwd)
+{
+ g_return_val_if_fail (arg != NULL, NULL);
+ g_return_val_if_fail (cwd != NULL, NULL);
- return file;
+ return new_for_cmdline_arg (arg, cwd);
}
/**
GFile * g_file_new_for_path (const char *path);
GFile * g_file_new_for_uri (const char *uri);
GFile * g_file_new_for_commandline_arg (const char *arg);
+GLIB_AVAILABLE_IN_2_36
+GFile * g_file_new_for_commandline_arg_and_cwd (const gchar *arg,
+ const gchar *cwd);
GLIB_AVAILABLE_IN_2_32
GFile * g_file_new_tmp (const char *tmpl,
GFileIOStream **iostream,
g_application_set_flags
g_application_set_inactivity_timeout
g_application_quit
+g_application_command_line_create_file_for_arg
g_application_command_line_get_arguments
g_application_command_line_get_cwd
g_application_command_line_get_environ
g_file_new_for_path
g_file_new_for_uri
g_file_new_for_commandline_arg
+g_file_new_for_commandline_arg_and_cwd
g_file_new_tmp
g_file_parse_name
g_file_dup