Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

strmaxcpy(3pub) [debian man page]

STRMAXCPY(3pub) 					       C Programmer's Manual						   STRMAXCPY(3pub)

NAME
strmaxcpy - copy at most a given number of characters of string SYNOPSIS
#include <publib.h> char *strmaxcpy(char *tgt, const char *src, size_t n); DESCRIPTION
strmaxcpy copies up to n-1 characters from the beginning of src to tgt, then adds a ''. n must be at least 1. The target string must be large enough to hold the result. Note that unlike strncpy(3), this function always terminates the result with ''. It also doesn't fill the result with extra '' charac- ters. RETURN VALUE
strmaxcpy returns its first argument. EXAMPLE
To print out the first 69 characters of a string, you might do the following (although familiarity with printf's format string might be more useful in this case). #include <stdio.h> #include <publib.h> void print42(const char *string) { char copy[43]; /* 42 + '' */ puts(strmaxcpy(copy, string, sizeof(copy))); } SEE ALSO
publib(3), strncpy(3) AUTHOR
Lars Wirzenius (lars.wirzenius@helsinki.fi) Publib C Programmer's Manual STRMAXCPY(3pub)

Check Out this Related Man Page

XMALLOC(3pub)						       C Programmer's Manual						     XMALLOC(3pub)

NAME
xmalloc, xrealloc, xfree, xstrdup, xmemdup, memdup - memory allocation functions for Publib SYNOPSIS
#include <publib.h> void *xmalloc(size_t bytes); void *xrealloc(void *ptr, size_t bytes); void xfree(void *ptr); char *xstrdup(const char *string); void *memdup(const void *mem, size_t bytes); void *xmemdup(const void *mem, size_t bytes); DESCRIPTION
These functions are utility functions for memory allocation from the publib library. xmalloc, xrealloc, and xfree are error checking ver- sions of the standard library routines malloc, realloc, and free, respectively. They are guaranteed to never return unless there was no problem: if, for example, xmalloc is unable to allocate the requested amount of memory, it prints an error message and terminates the pro- gram. Hence, the caller does not need to check for a NULL return value, and the code that calls these functions is simpler due to the lack of error checks. Similarly, xstrdup is an error checking version of the common (though not standard) strdup routine, which creates a duplicate of a string by allocating memory for the copy with malloc. (For systems that lack strdup, publib provides one in its portability module; it is always declared in <publib.h>.) memdup is similar to strdup, it creates a copy of an arbitrary memory area (the arguments are a pointer to the beginning of the area, and its size) by allocating memory for the copy with malloc. xmemdup is its error checking version. NOTE
xmalloc and xrealloc treat a request to allocate a block of 0 bytes as an error. xrealloc will allow its first argument to be NULL. SEE ALSO
publib(3), malloc(3), strdup(3) AUTHOR
Lars Wirzenius (lars.wirzenius@helsinki.fi) Publib C Programmer's Manual XMALLOC(3pub)
Man Page