forked from andrea-rosasco/shell_bush
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.c
54 lines (48 loc) · 1.31 KB
/
utils.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
* bush--
*
* Programma sviluppato a supporto del laboratorio di
* Sistemi di Elaborazione e Trasmissione del corso di laurea
* in Informatica classe L-31 presso l'Universita` degli Studi di
* Genova, anno accademico 2016/2017.
*
* Copyright (C) 2015,2016 by Giovanni Lagorio <giovanni.lagorio@unige.it>
*
* 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.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "utils.h"
void fail_errno(const char * const msg)
{
perror(msg);
exit(EXIT_FAILURE);
}
void *my_malloc(size_t size)
{
void *result = malloc(size);
if (!result)
fail_errno("Cannot allocate memory with malloc");
return result;
}
void *my_realloc(void *ptr, size_t size)
{
void *result = realloc(ptr, size);
if (!result)
fail_errno("Cannot re-allocate memory");
return result;
}
void yyerror(void *scanner, const struct shell * const sh, struct node ** const cmd, char const * const msg)
{
fprintf (stderr, "Parsing error: %s\n", msg);
}
char *my_strdup(const char * const s) {
char *result = strdup(s);
if (!result)
fail_errno("Cannot allocate memory for strdup");
return result;
}