YetAnotherCoupler 3.5.2
Loading...
Searching...
No Matches
utils_core.c
Go to the documentation of this file.
1// Copyright (c) 2024 The YAC Authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#include <stdlib.h>
6#include <stdio.h>
7#include <string.h>
8#include <sys/stat.h>
9
10#include "utils_core.h"
11
12int yac_file_exists(const char * filename) {
13 struct stat buffer;
14 return !stat(filename,&buffer);
15}
16
18 struct yac_name_type_pair const * pairs, size_t count, int type) {
19
20 char const * name = NULL;
21 for (size_t i = 0; (i < count) && (name == NULL); ++i)
22 if (pairs[i].type == type) name = pairs[i].name;
23 return name;
24}
25
27 struct yac_name_type_pair const * pairs, size_t count, char const * name) {
28
29 int type = INT_MAX;
30 if (name != NULL)
31 for (size_t i = 0; (i < count) && (type == INT_MAX); ++i)
32 if (!strcmp(pairs[i].name, name)) type = pairs[i].type;
33 return type;
34}
enum callback_type type
const char * name
int yac_name_type_pair_get_type(struct yac_name_type_pair const *pairs, size_t count, char const *name)
Definition utils_core.c:26
char const * yac_name_type_pair_get_name(struct yac_name_type_pair const *pairs, size_t count, int type)
Definition utils_core.c:17
int yac_file_exists(const char *filename)
Definition utils_core.c:12