File: chomp.c

package info (click to toggle)
putty 0.83-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 13,216 kB
  • sloc: ansic: 148,476; python: 8,466; perl: 1,830; makefile: 128; sh: 117
file content (26 lines) | stat: -rw-r--r-- 585 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
22
23
24
25
26
/*
 * Perl-style 'chomp', for a line we just read with fgetline.
 *
 * Unlike Perl chomp, however, we're deliberately forgiving of strange
 * line-ending conventions.
 *
 * Also we forgive NULL on input, so you can just write 'line =
 * chomp(fgetline(fp));' and not bother checking for NULL until
 * afterwards.
 */

#include <string.h>

#include "defs.h"
#include "misc.h"

char *chomp(char *str)
{
    if (str) {
        int len = strlen(str);
        while (len > 0 && (str[len-1] == '\r' || str[len-1] == '\n'))
            len--;
        str[len] = '\0';
    }
    return str;
}