strmaxcpy(3pub)

strmaxcpy3pub

Copy at most a given number of characters of string

Usage

#include <publib.h>
char *strmaxcpy(char *tgt, const char *src, size_t n);

Overview

strmaxcpy copies up to n-1 characters from the beginning of src to tgt, then adds a '\0'. 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 '\0'. It also doesn't fill the result with extra '\0' characters.

Return value

strmaxcpy returns its first argument.

Examples

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 + '\0' */
	puts(strmaxcpy(copy, string, sizeof(copy)));
}

Releases

16 releases since Debian 1.2 (Rex); the text changed 4 times.

  1. 1.2–1.3
  2. 2.0–2.2
  3. 3.0
  4. 3.1–6.0
  5. 7–13

Author

Lars Wirzenius ([email protected])

From publib-dev 0.40-4 in Debian 13 (Trixie). Parsed by carta from the page's man source.