mirror of
https://github.com/labwc/labwc.git
synced 2025-11-03 09:01:51 -05:00
common/file-helpers.c: share file_exists() to reduce duplication
This commit is contained in:
parent
a8951c4b75
commit
a386133068
5 changed files with 26 additions and 17 deletions
12
include/common/file-helpers.h
Normal file
12
include/common/file-helpers.h
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||||
|
#ifndef LABWC_FILE_HELPERS_H
|
||||||
|
#define LABWC_FILE_HELPERS_H
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* file_exists() - Test if file exists.
|
||||||
|
* @filename: Name of file to test.
|
||||||
|
*/
|
||||||
|
bool file_exists(const char *filename);
|
||||||
|
|
||||||
|
#endif /* LABWC_FILE_HELPERS_H */
|
||||||
|
|
@ -8,22 +8,14 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
#include "buffer.h"
|
#include "buffer.h"
|
||||||
#include "button/button-png.h"
|
#include "button/button-png.h"
|
||||||
#include "button/common.h"
|
#include "button/common.h"
|
||||||
|
#include "common/file-helpers.h"
|
||||||
#include "labwc.h"
|
#include "labwc.h"
|
||||||
#include "theme.h"
|
#include "theme.h"
|
||||||
|
|
||||||
/* Share with session.c:isfile() */
|
|
||||||
static bool
|
|
||||||
file_exists(const char *path)
|
|
||||||
{
|
|
||||||
struct stat st;
|
|
||||||
return (!stat(path, &st));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* cairo_image_surface_create_from_png() does not gracefully handle non-png
|
* cairo_image_surface_create_from_png() does not gracefully handle non-png
|
||||||
* files, so we verify the header before trying to read the rest of the file.
|
* files, so we verify the header before trying to read the rest of the file.
|
||||||
|
|
|
||||||
10
src/common/file-helpers.c
Normal file
10
src/common/file-helpers.c
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-only
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include "common/file-helpers.h"
|
||||||
|
|
||||||
|
bool
|
||||||
|
file_exists(const char *filename)
|
||||||
|
{
|
||||||
|
struct stat st;
|
||||||
|
return (!stat(filename, &st));
|
||||||
|
}
|
||||||
|
|
@ -2,6 +2,7 @@ labwc_sources += files(
|
||||||
'buf.c',
|
'buf.c',
|
||||||
'dir.c',
|
'dir.c',
|
||||||
'fd_util.c',
|
'fd_util.c',
|
||||||
|
'file-helpers.c',
|
||||||
'font.c',
|
'font.c',
|
||||||
'grab-file.c',
|
'grab-file.c',
|
||||||
'graphic-helpers.c',
|
'graphic-helpers.c',
|
||||||
|
|
|
||||||
|
|
@ -8,18 +8,12 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
#include "common/buf.h"
|
#include "common/buf.h"
|
||||||
|
#include "common/file-helpers.h"
|
||||||
#include "common/mem.h"
|
#include "common/mem.h"
|
||||||
#include "common/spawn.h"
|
#include "common/spawn.h"
|
||||||
#include "common/string-helpers.h"
|
#include "common/string-helpers.h"
|
||||||
#include "config/session.h"
|
#include "config/session.h"
|
||||||
|
|
||||||
static bool
|
|
||||||
isfile(const char *path)
|
|
||||||
{
|
|
||||||
struct stat st;
|
|
||||||
return (!stat(path, &st));
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
string_empty(const char *s)
|
string_empty(const char *s)
|
||||||
{
|
{
|
||||||
|
|
@ -130,7 +124,7 @@ session_autostart_init(const char *dir)
|
||||||
if (!autostart) {
|
if (!autostart) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!isfile(autostart)) {
|
if (!file_exists(autostart)) {
|
||||||
wlr_log(WLR_ERROR, "no autostart file");
|
wlr_log(WLR_ERROR, "no autostart file");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue