GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-3d7b331ba8
strlcpy.c File Reference

GIS Library - GRASS implementation of strlcpy(). More...

#include <stddef.h>
Include dependency graph for strlcpy.c:

Go to the source code of this file.

Functions

size_t G_strlcpy (char *dst, const char *src, size_t dsize)
 Safe string copy function. More...
 

Detailed Description

GIS Library - GRASS implementation of strlcpy().

Loïc Bartoletti - 2024-07-25

Copyright (c) 1998, 2015 Todd C. Miller Todd..nosp@m.Mill.nosp@m.er@co.nosp@m.urte.nosp@m.san.c.nosp@m.om

Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Definition in file strlcpy.c.

Function Documentation

◆ G_strlcpy()

size_t G_strlcpy ( char *  dst,
const char *  src,
size_t  dsize 
)

Safe string copy function.

Copy string src to buffer dst of size dsize. At most dsize-1 characters will be copied. Always NUL terminates (unless dsize == 0). This function is a safer alternative to strncpy.

Parameters
[out]dstPointer to the destination buffer.
[in]srcPointer to the source string. Must be a NUL-terminated C string.
[in]dsizeThe size of the destination buffer.
Returns
The total length of the string src (not including the terminating NUL character). If the return value is >= dsize, truncation occurred.
Note
If truncation occurred, the return value is the length of the string that would have been created if enough space had been available.
Warning
This function does not pad the destination buffer with NUL bytes if the source string is shorter than dsize-1 bytes, unlike strncpy.
The src string must be a valid NUL-terminated C string. Passing an unterminated string may result in buffer overrun.

Definition at line 52 of file strlcpy.c.

Referenced by dig_read_frmt_ascii(), G_matrix_print(), and Rast__mask_info().