Extract opendirat() helper function into libotutil
We were duplicating the code to do an opendirat() in a few places.
This commit is contained in:
1 parent
dfeb27eca5
commit
b756a13a65
6 files changed
+94
-14
No files matched your search
@@ -0,0 +1,50 @@
|
||||
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
|
||||
*
|
||||
* Copyright (C) 2014 Colin Walters <walters@verbum.org>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "ot-fs-utils.h"
|
||||
|
||||
int
|
||||
ot_opendirat (int dfd, const char *path, gboolean follow)
|
||||
{
|
||||
int flags = O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_CLOEXEC | O_NOCTTY;
|
||||
if (!follow)
|
||||
flags |= O_NOFOLLOW;
|
||||
return openat (dfd, path, flags);
|
||||
}
|
||||
|
||||
gboolean
|
||||
ot_gopendirat (int dfd,
|
||||
const char *path,
|
||||
gboolean follow,
|
||||
int *out_fd,
|
||||
GError **error)
|
||||
{
|
||||
int ret = ot_opendirat (dfd, path, follow);
|
||||
if (ret == -1)
|
||||
{
|
||||
ot_util_set_error_from_errno (error, errno);
|
||||
return FALSE;
|
||||
}
|
||||
*out_fd = ret;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
|
||||
*
|
||||
* Copyright (C) 2014 Colin Walters <walters@verbum.org>.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ot-unix-utils.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
int ot_opendirat (int dfd, const char *path, gboolean follow);
|
||||
gboolean ot_gopendirat (int dfd,
|
||||
const char *path,
|
||||
gboolean follow,
|
||||
int *out_fd,
|
||||
GError **error);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
#include <ot-waitable-queue.h>
|
||||
#include <ot-keyfile-utils.h>
|
||||
#include <ot-gio-utils.h>
|
||||
#include <ot-fs-utils.h>
|
||||
#include <ot-opt-utils.h>
|
||||
#include <ot-unix-utils.h>
|
||||
#include <ot-variant-utils.h>
|
||||
|
||||
Reference in new issue
Block a user