Reuse, not rework
Home

License Awareness



Highly Reusable Software

By activity
Professions, Sciences, Humanities, Business, ...

User Interface
Text-based, GUI, Audio, Video, Keyboards, Mouse, Images,...

Text Strings
Conversions, tests, processing, manipulation,...

Math
Integer, Floating point, Matrix, Statistics, Boolean, ...

Processing
Algorithms, Memory, Process control, Debugging, ...

Stored Data
Data storage, Integrity, Encryption, Compression, ...

Communications
Networks, protocols, Interprocess, Remote, Client Server, ...

Hard World
Timing, Calendar and Clock, Audio, Video, Printer, Controls...

File System
Management, Filtering, File & Directory access, Viewers, ...


NAME

librock_strn0cpy - copy at most n characters, always appending a \0.

#License - #Source code - #Example Use -

SYNOPSIS

#include <librock/parse.h>

char *
librock_strn0cpy(
    char *dest,
    const char *src,
    int n
);

DESCRIPTION

Copy the smaller of (strlen(src), n) characters from src to dest, always appending a '\0' onto dest. This is a well-behaved work-alike for strncpy. Remember that n+1 bytes at dest will be affected if strlen(src) >= n.

Returns the first argument. This does not '\0' fill dest[> strlen(src)] as some strncpy implementations do.

Typical use is to replace clumsy two-step calls to strncpy such as:

     strncpy(dest,src,sizeof(dest));
     dest[sizeof(dest)-1] = '\0';
with:
     librock_strn0cpy(dest,src,sizeof(dest-1));
If you don't want the '\0', then use memmove()

USES

   // [Makes no calls]

LICENSE

  Copyright 1998-2004 Forrest J. Cavalier III, http://www.mibsoftware.com
  Open-source under MIT license. NO WARRANTY. Copies must retain this block.
  License, originals, details: http://www.mibsoftware.com/librock/

Source Code

./text/compsearch/strfn.c (implementation, plus source of this manual page)

This software is part of Librock

Rapid reuse, without rework. Details
This page copyright (C) 2002-2004 Forrest J. Cavalier III, d-b-a Mib Software, Saylorsburg PA 18353, USA

Verbatim copying and distribution of this generated page is permitted in any medium provided that no changes are made.
(The source of this manual page may be covered by a more permissive license which allows modifications.)

Want to help? We welcome comments, patches. -- Need help? Request paid support.