diff options
| author | kx <kx@radix.pro> | 2023-04-11 01:18:34 +0300 |
|---|---|---|
| committer | kx <kx@radix.pro> | 2023-04-11 01:18:34 +0300 |
| commit | 11c606a6888dc269ef018359469a7276c3ad8f67 (patch) | |
| tree | 368294bb7cadcd5c44ccd082187d6a4433401027 /src/wrapper.c | |
| parent | 8c55752ed5b29a22fdab9faaa6ff27b7cafa6791 (diff) | |
| download | pkgtools-0.2.1.tar.xz | |
Version 0.2.1pkgtools-0.2.1
Diffstat (limited to 'src/wrapper.c')
| -rw-r--r-- | src/wrapper.c | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/wrapper.c b/src/wrapper.c new file mode 100644 index 0000000..2b311aa --- /dev/null +++ b/src/wrapper.c @@ -0,0 +1,75 @@ + +/********************************************************************** + + Copyright 2019 Andrey V.Kosteltsev + + Licensed under the Radix.pro License, Version 1.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + https://radix.pro/licenses/LICENSE-1.0-en_US.txt + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied. + + **********************************************************************/ + +#include <config.h> + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <errno.h> +#include <error.h> +#include <sys/stat.h> +#include <sys/wait.h> +#include <stdarg.h> +#include <unistd.h> + +#include <msglog.h> + + +char *xstrdup( const char *str ) +{ + char *ret = (char *)NULL; + size_t len; + + if( !str ) return ret; + + len = strlen( str ) + 1; + + ret = (char *)malloc( len ); + if( !ret ) + FATAL_ERROR( "Out of memory, strdup failed (tried to allocate %lu bytes)", (unsigned long)len ); + + ret[len-1] = '\0'; + ret = strncpy( ret, str, len-1 ); + return ret; +} + +void *xmalloc( size_t size ) +{ + void *ret = NULL; + + ret = malloc( size ); + if( !ret ) + { + FATAL_ERROR( "Out of memory, malloc failed (tried to allocate %lu bytes)", (unsigned long)size ); + } + memset( ret, 0, size ); + return ret; +} + +void *xrealloc( void *ptr, size_t size ) +{ + void *ret = NULL; + + ret = realloc( ptr, size ); + if( !ret && !size ) + ret = realloc( ptr, 1 ); + if( !ret ) + FATAL_ERROR( "Out of memory, realloc failed" ); + return ret; +} |
