lumiera_documentation/src/lib/safeclib.h
Ichthyostega 806db414dd Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
 * there is no entity "Lumiera.org" which holds any copyrights
 * Lumiera source code is provided under the GPL Version 2+

== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''

The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!

The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00

118 lines
2.9 KiB
C
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
SAFECLIB.h - Portable and safe wrappers around some clib functions and some tools
Copyright (C)
2008, Christian Thaeter <ct@pipapo.org>
  **Lumiera** 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. See the file COPYING for further details.
*/
/** @file safeclib.h
** Portable and safe wrappers around some C-Lib functions
*/
#include "error.h"
#include <stdlib.h>
LUMIERA_ERROR_DECLARE(NO_MEMORY);
/**
* Install the resourcecollector run hook.
* The resourcecollectr must be hooked into the safeclib at bootup after it got
* initialised and removed from it before shut down. Without resourcecollector
* failed allocations will abort().
* @param hook pointer to the resourcecollector_run function, must be of type
* lumiera_resourcecollector_run_fn but we don't want a dependency on vault in this header
*/
void
lumiera_safeclib_set_resourcecollector (void* hook);
/**
* Allocate memory.
* always succeeds or dies
* @param size memory to be allocated
* @return pointer to the allocated memory
*/
void*
lumiera_malloc (size_t sz);
/**
* Allocate cleared memory for an array.
* always succeeds or dies
* @param n number of elements
* @param size memory to be allocated
* @return pointer to the allocated memory
*/
void*
lumiera_calloc (size_t n, size_t size);
/**
* Change the size of a memory block.
* @param ptr pointer to the old memory block obtained by lumiera_malloc or lumiera_calloc
* @param size new size of the block
* @return address of new block
*/
void*
lumiera_realloc (void* ptr, size_t size);
/**
* Free previously allocated memory.
* @param mem pointer to the memory block obtained by lumiera_malloc or lumiera_calloc
*/
static inline void
lumiera_free (void* mem)
{
/* for now only a alias, might change in future */
free (mem);
}
/**
* Duplicate a C string.
* always succeeds or dies
* @param str string to be copied
* @param len maximal length to be copied
* @return pointer to the new string, "" if NULL was passed as str
*/
char*
lumiera_strndup (const char* str, size_t len);
/**
* Compare two C strings.
* Handles NULL pointers as "", shortcut for same addresses
* @param a first string for comparsion
* @param b second string for comparsion
* @param len maximal length for the comparsion
* @return 0 if the strings are identical, -1 if smaller 1 if bigger.
*/
int
lumiera_strncmp (const char* a, const char* b, size_t len);
/**
* check 2 strings for identity.
* @param a first string for comparsion
* @param b second string for comparsion
* @return 1 when the strings are the the same, 0 if not.
*/
int
lumiera_streq (const char* a, const char* b);
/*
// Local Variables:
// mode: C
// c-file-style: "gnu"
// indent-tabs-mode: nil
// End:
*/