puts.c 484 Bytes
Newer Older
1
/*
2
 * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved.
3
 *
dp-arm's avatar
dp-arm committed
4
 * SPDX-License-Identifier: BSD-3-Clause
5
6
7
8
9
10
11
12
13
 */

#include <stdio.h>

int puts(const char *s)
{
	int count = 0;
	while(*s)
	{
14
		if (putchar(*s++) != EOF) {
15
16
			count++;
		} else {
17
			count = EOF;
18
19
20
			break;
		}
	}
21
22
23
24
25
26
27
28
29

	/* According to the puts(3) manpage, the function should write a
	 * trailing newline.
	 */
	if ((count != EOF) && (putchar('\n') != EOF))
		count++;
	else
		count = EOF;

30
31
	return count;
}