Radix cross Linux package tools

Package Tools – is a set of utilities to create, install, and update RcL packages

3 Commits   0 Branches   2 Tags
11c606a6 (kx 2023-04-11 01:18:34 +0300  1) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  2) /**********************************************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300  3) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  4)   Copyright 2019 Andrey V.Kosteltsev
11c606a6 (kx 2023-04-11 01:18:34 +0300  5) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  6)   Licensed under the Radix.pro License, Version 1.0 (the "License");
11c606a6 (kx 2023-04-11 01:18:34 +0300  7)   you may not use this file  except  in compliance with the License.
11c606a6 (kx 2023-04-11 01:18:34 +0300  8)   You may obtain a copy of the License at
11c606a6 (kx 2023-04-11 01:18:34 +0300  9) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 10)      https://radix.pro/licenses/LICENSE-1.0-en_US.txt
11c606a6 (kx 2023-04-11 01:18:34 +0300 11) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 12)   Unless required by applicable law or agreed to in writing, software
11c606a6 (kx 2023-04-11 01:18:34 +0300 13)   distributed under the License is distributed on an "AS IS" BASIS,
11c606a6 (kx 2023-04-11 01:18:34 +0300 14)   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
11c606a6 (kx 2023-04-11 01:18:34 +0300 15)   implied.
11c606a6 (kx 2023-04-11 01:18:34 +0300 16) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 17)  **********************************************************************/
11c606a6 (kx 2023-04-11 01:18:34 +0300 18) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 19) #include <config.h>
11c606a6 (kx 2023-04-11 01:18:34 +0300 20) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 21) #include <stdlib.h>
11c606a6 (kx 2023-04-11 01:18:34 +0300 22) #include <stdio.h>
11c606a6 (kx 2023-04-11 01:18:34 +0300 23) #include <string.h>
11c606a6 (kx 2023-04-11 01:18:34 +0300 24) #include <errno.h>
11c606a6 (kx 2023-04-11 01:18:34 +0300 25) #include <error.h>
11c606a6 (kx 2023-04-11 01:18:34 +0300 26) #include <sys/stat.h>
11c606a6 (kx 2023-04-11 01:18:34 +0300 27) #include <sys/wait.h>
11c606a6 (kx 2023-04-11 01:18:34 +0300 28) #include <stdarg.h>
11c606a6 (kx 2023-04-11 01:18:34 +0300 29) #include <unistd.h>
11c606a6 (kx 2023-04-11 01:18:34 +0300 30) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 31) #include <msglog.h>
11c606a6 (kx 2023-04-11 01:18:34 +0300 32) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 33) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 34) char *xstrdup( const char *str )
11c606a6 (kx 2023-04-11 01:18:34 +0300 35) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 36)   char   *ret = (char *)NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 37)   size_t  len;
11c606a6 (kx 2023-04-11 01:18:34 +0300 38) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 39)   if( !str ) return ret;
11c606a6 (kx 2023-04-11 01:18:34 +0300 40) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 41)   len = strlen( str ) + 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 42) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 43)   ret = (char *)malloc( len );
11c606a6 (kx 2023-04-11 01:18:34 +0300 44)   if( !ret )
11c606a6 (kx 2023-04-11 01:18:34 +0300 45)     FATAL_ERROR( "Out of memory, strdup failed (tried to allocate %lu bytes)", (unsigned long)len );
11c606a6 (kx 2023-04-11 01:18:34 +0300 46) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 47)   ret[len-1] = '\0';
11c606a6 (kx 2023-04-11 01:18:34 +0300 48)   ret = strncpy( ret, str, len-1 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 49)   return ret;
11c606a6 (kx 2023-04-11 01:18:34 +0300 50) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 51) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 52) void *xmalloc( size_t size )
11c606a6 (kx 2023-04-11 01:18:34 +0300 53) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 54)   void *ret = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 55) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 56)   ret = malloc( size );
11c606a6 (kx 2023-04-11 01:18:34 +0300 57)   if( !ret )
11c606a6 (kx 2023-04-11 01:18:34 +0300 58)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 59)     FATAL_ERROR( "Out of memory, malloc failed (tried to allocate %lu bytes)", (unsigned long)size );
11c606a6 (kx 2023-04-11 01:18:34 +0300 60)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 61)   memset( ret, 0, size );
11c606a6 (kx 2023-04-11 01:18:34 +0300 62)   return ret;
11c606a6 (kx 2023-04-11 01:18:34 +0300 63) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 64) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 65) void *xrealloc( void *ptr, size_t size )
11c606a6 (kx 2023-04-11 01:18:34 +0300 66) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 67)   void *ret = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 68) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 69)   ret = realloc( ptr, size );
11c606a6 (kx 2023-04-11 01:18:34 +0300 70)   if( !ret && !size )
11c606a6 (kx 2023-04-11 01:18:34 +0300 71)     ret = realloc( ptr, 1 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 72)   if( !ret )
11c606a6 (kx 2023-04-11 01:18:34 +0300 73)     FATAL_ERROR( "Out of memory, realloc failed" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 74)   return ret;
11c606a6 (kx 2023-04-11 01:18:34 +0300 75) }