source: rtems/cpukit/libcsupport/src/strlcpy.c @ 98b785e

4.115
Last change on this file since 98b785e was 34b5bdb6, checked in by Ralf Corsepius <ralf.corsepius@…>, on 03/25/03 at 20:48:35

Merger from rtems-4-6-branch.

  • Property mode set to 100644
File size: 1.3 KB
Line 
1/*
2 * utils.c - various utility functions used in pppd.
3 *
4 * Copyright (c) 1999 The Australian National University.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms are permitted
8 * provided that the above copyright notice and this paragraph are
9 * duplicated in all such forms and that any documentation,
10 * advertising materials, and other materials related to such
11 * distribution and use acknowledge that the software was developed
12 * by the Australian National University.  The name of the University
13 * may not be used to endorse or promote products derived from this
14 * software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18 */
19
20#if HAVE_CONFIG_H
21#include "config.h"
22#endif
23
24#include <string.h>
25
26#ifndef HAVE_STRLCPY
27/*
28 * strlcpy - like strcpy/strncpy, doesn't overflow destination buffer,
29 * always leaves destination null-terminated (for len > 0).
30 */
31size_t
32strlcpy(dest, src, len)
33    char *dest;
34    const char *src;
35    size_t len;
36{
37    size_t ret = strlen(src);
38
39    if (len != 0) {
40        if (ret < len)
41            strcpy(dest, src);
42        else {
43            strncpy(dest, src, len - 1);
44            dest[len-1] = 0;
45        }
46    }
47    return ret;
48}
49#endif
Note: See TracBrowser for help on using the repository browser.