File: safecopy.c

package info (click to toggle)
ascpu 1.9-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 280 kB
  • ctags: 126
  • sloc: ansic: 1,219; sh: 183; makefile: 51
file content (21 lines) | stat: -rw-r--r-- 595 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
 * ascpu is the CPU statistics monitor utility for X Windows
 * Copyright (c) 1998-2000  Albert Dorofeev <albert@tigr.net>
 * For the updates see http://www.tigr.net/
 *
 * This software is distributed under GPL. For details see LICENSE file.
 */

#include <string.h>

/*
 * Copies at most maxlen-1 characters from the source.
 * Makes sure that the destination string is zero-terminated.
 */
char *safecopy(char *dest, const char *src, unsigned short maxlen)
{
	/* safety precaution */
	dest[maxlen-1] = 0;
	return strlen(src) < maxlen ? strcpy(dest, src) : strncpy(dest, src, maxlen-1);
}