Some work on ostree-build

This commit is contained in:
Colin Walters committed 2011-11-03 16:25:35 -04:00
1 parent 21c7ff74b6
commit 8bca739315
14 files changed
+749 -3

No files matched your search

+159
View File
@@ -0,0 +1,159 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright (C) 2011 Colin Walters <walters@verbum.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Author: Colin Walters <walters@verbum.org>
*/
#include "config.h"
#include <gio/gio.h>
#include <string.h>
#include "otutil.h"
#if GLIB_CHECK_VERSION(2,32,0)
/* nothing */
#else
/* Code copied from glib/glib/genviron.c */
/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1998 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GLib Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GLib at ftp://ftp.gtk.org/pub/gtk/.
*/
static gint
ot_g_environ_find (gchar **envp,
const gchar *variable)
{
gint len, i;
len = strlen (variable);
for (i = 0; envp[i]; i++)
{
if (strncmp (envp[i], variable, len) == 0 &&
envp[i][len] == '=')
return i;
}
return -1;
}
const gchar *
ot_g_environ_getenv (gchar **envp,
const gchar *variable)
{
gint index;
g_return_val_if_fail (envp != NULL, NULL);
g_return_val_if_fail (variable != NULL, NULL);
index = ot_g_environ_find (envp, variable);
if (index != -1)
return envp[index] + strlen (variable) + 1;
else
return NULL;
}
gchar **
ot_g_environ_setenv (gchar **envp,
const gchar *variable,
const gchar *value,
gboolean overwrite)
{
gint index;
g_return_val_if_fail (envp != NULL, NULL);
g_return_val_if_fail (variable != NULL, NULL);
g_return_val_if_fail (strchr (variable, '=') == NULL, NULL);
index = ot_g_environ_find (envp, variable);
if (index != -1)
{
if (overwrite)
{
g_free (envp[index]);
envp[index] = g_strdup_printf ("%s=%s", variable, value);
}
}
else
{
gint length;
length = g_strv_length (envp);
envp = g_renew (gchar *, envp, length + 2);
envp[length] = g_strdup_printf ("%s=%s", variable, value);
envp[length + 1] = NULL;
}
return envp;
}
gchar **
ot_g_environ_unsetenv (gchar **envp,
const gchar *variable)
{
gint len;
gchar **e, **f;
g_return_val_if_fail (envp != NULL, NULL);
g_return_val_if_fail (variable != NULL, NULL);
g_return_val_if_fail (strchr (variable, '=') == NULL, NULL);
len = strlen (variable);
/* Note that we remove *all* environment entries for
* the variable name, not just the first.
*/
e = f = envp;
while (*e != NULL)
{
if (strncmp (*e, variable, len) != 0 || (*e)[len] != '=')
{
*f = *e;
f++;
}
e++;
}
*f = NULL;
return envp;
}
#endif
+52
View File
@@ -0,0 +1,52 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright (C) 2011 Colin Walters <walters@verbum.org>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Author: Colin Walters <walters@verbum.org>
*/
#ifndef __OSTREE_GLIB_COMPAT_H__
#define __OSTREE_GLIB_COMPAT_H__
#include <gio/gio.h>
G_BEGIN_DECLS
#if GLIB_CHECK_VERSION(2,32,0)
#define ot_g_environ_getenv g_environ_getenv
#define ot_g_environ_setenv g_environ_setenv
#define ot_g_environ_unsetenv g_environ_unsetenv
#else
const gchar *
ot_g_environ_getenv (gchar **envp,
const gchar *variable);
gchar **
ot_g_environ_setenv (gchar **envp,
const gchar *variable,
const gchar *value,
gboolean overwrite);
gchar **
ot_g_environ_unsetenv (gchar **envp,
const gchar *variable);
#endif
G_END_DECLS
#endif
+2 -2
View File
@@ -19,8 +19,8 @@
* Author: Colin Walters <walters@verbum.org>
*/
#ifndef __OSTREE_GIO_UTILS_H__
#define __OSTREE_GIO_UTILS_H__
#ifndef __OSTREE_OPT_UTILS_H__
#define __OSTREE_OPT_UTILS_H__
#include <gio/gio.h>
+16
View File
@@ -28,6 +28,8 @@
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <dirent.h>
gboolean
@@ -254,3 +256,17 @@ ot_util_open_file_read_at (int dirfd, const char *name, GError **error)
ot_util_set_error_from_errno (error, errno);
return fd;
}
void
ot_util_fatal_literal (const char *msg)
{
g_printerr ("%s\n", msg);
exit (1);
}
void
ot_util_fatal_gerror (GError *error)
{
g_assert (error != NULL);
ot_util_fatal_literal (error->message);
}
+4
View File
@@ -38,6 +38,10 @@ G_BEGIN_DECLS
gboolean ot_util_spawn_pager (GOutputStream **out_stream, GError **error);
void ot_util_fatal_literal (const char *msg) G_GNUC_NORETURN;
void ot_util_fatal_gerror (GError *error) G_GNUC_NORETURN;
gboolean ot_util_filename_has_dotdot (const char *path);
GPtrArray *ot_util_sort_filenames_by_component_length (GPtrArray *files);
+1
View File
@@ -24,5 +24,6 @@
#include <ot-unix-utils.h>
#include <ot-gio-utils.h>
#include <ot-opt-utils.h>
#include <ot-glib-compat.h>
#endif