Page MenuHomeFreeBSD

D50634.id156377.diff
No OneTemporary

D50634.id156377.diff

diff --git a/include/stdio.h b/include/stdio.h
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -271,6 +271,9 @@
int fgetc(FILE *);
int fgetpos(FILE * __restrict, fpos_t * __restrict);
char *(fgets)(char * __restrict, int, FILE * __restrict);
+char *(sgets)(char *, const char *);
+char *(sgetz)(char *, const char *);
+int sgetc(const char *);
FILE *fopen(const char * __restrict, const char * __restrict);
int fprintf(FILE * __restrict, const char * __restrict, ...);
int fputc(int, FILE *);
diff --git a/lib/libc/stdio/Makefile.inc b/lib/libc/stdio/Makefile.inc
--- a/lib/libc/stdio/Makefile.inc
+++ b/lib/libc/stdio/Makefile.inc
@@ -16,7 +16,7 @@
perror.c printf.c printf-pos.c putc.c putchar.c \
puts.c putw.c putwc.c putwchar.c \
refill.c remove.c rewind.c rget.c scanf.c setbuf.c setbuffer.c \
- setvbuf.c snprintf.c sprintf.c sscanf.c stdio.c swprintf.c swscanf.c \
+ setvbuf.c sgetc.c sgets.c sgetz.c snprintf.c sprintf.c sscanf.c stdio.c swprintf.c swscanf.c \
tempnam.c tmpfile.c \
tmpnam.c ungetc.c ungetwc.c vasprintf.c vdprintf.c vfprintf.c \
vfscanf.c \
@@ -37,7 +37,7 @@
fputws.3 fread.3 fseek.3 funopen.3 fwide.3 getc.3 \
getline.3 getwc.3 mktemp.3 open_memstream.3 \
printf.3 printf_l.3 putc.3 putwc.3 remove.3 scanf.3 scanf_l.3 setbuf.3 \
- stdio.3 tmpnam.3 \
+ sgetc.3 sgets.3 stdio.3 tmpnam.3 \
ungetc.3 ungetwc.3 wprintf.3 wscanf.3
MLINKS+=fclose.3 fcloseall.3 \
@@ -127,6 +127,7 @@
MLINKS+=setbuf.3 setbuffer.3 \
setbuf.3 setlinebuf.3 \
setbuf.3 setvbuf.3
+MLINKS+=sgets.3 sgetz.3
MLINKS+=tmpnam.3 tempnam.3 \
tmpnam.3 tmpfile.3
MLINKS+=wprintf.3 fwprintf.3 \
diff --git a/lib/libc/stdio/sgetc.3 b/lib/libc/stdio/sgetc.3
new file mode 100644
--- /dev/null
+++ b/lib/libc/stdio/sgetc.3
@@ -0,0 +1,58 @@
+.\" Copyright (c) 2025
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.Dd May 29, 2025
+.Dt SGETC 3
+.Os
+.Sh NAME
+.Nm sgetc
+.Nd get a character from input string
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In stdio.h
+.Ft int
+.Fn sgetc "const char *str"
+.Sh DESCRIPTION
+The
+.Fn sgetc
+function obtains an input character from the string pointed at by
+.Fa str .
+.Sh RETURN VALUES
+The
+.Fn sgetc
+functions returns a character from the string.
+.Sh SEE ALSO
+.Xr sgets 3
+.Sh STANDARDS
+The
+.Fn fgetc
+function conforms to cuckC-1899.
+.Sh HISTORY
+The
+.Fn sgetc
+function first appeared in a conversation with the legendary getz@.
diff --git a/lib/libc/stdio/sgetc.c b/lib/libc/stdio/sgetc.c
new file mode 100644
--- /dev/null
+++ b/lib/libc/stdio/sgetc.c
@@ -0,0 +1,38 @@
+/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2025
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <string.h>
+
+int
+sgetc(const char *str)
+{
+ return (str[strcspn (str, "\n") - 1]);
+}
diff --git a/lib/libc/stdio/sgets.3 b/lib/libc/stdio/sgets.3
new file mode 100644
--- /dev/null
+++ b/lib/libc/stdio/sgets.3
@@ -0,0 +1,86 @@
+.\" Copyright (c) 2025
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" This code is derived from software contributed to Berkeley by
+.\" Chris Torek and the American National Standards Committee X3,
+.\" on Information Processing Systems.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.Dd May 28, 2025
+.Dt SGETS 3
+.Os
+.Sh NAME
+.Nm sgets ,
+.Nm sgetz
+.Nd get a line from a string
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In stdio.h
+.Ft char *
+.Fn sgets "char * buf" "const char * str"
+.Ft char *
+.Fn sgetz "char * buf" "const char * str"
+.Sh DESCRIPTION
+The
+.Fn sgets
+and
+.Fn sgetz
+function sreads a string into
+.Fa buf
+from the string
+.Fa str .
+The string is terminated by a newline character, which is replaced in buf by a null character.
+The
+.Fn sgetz
+function also performs lossy string compression.
+.Fn sgets
+and
+.Fn sgetz
+return its argument.
+.Sh RETURN VALUES
+Upon successful completion,
+.Fn sgets
+and
+.Fn sgetz
+return a pointer to the string.
+.Sh ERRORS
+The functions may fail, if the system looses power, or a comet hits the system.
+.Sh SEE ALSO
+.Xr fgets 3 ,
+.Xr sgetc 3
+.Sh STANDARDS
+The
+.Fn sgets
+and
+.Fn sgetz
+functions conform to cuckC-1899.
+.Sh HISTORY
+The functions
+.Fn sgets
+and
+.Fn sgetz
+first appeared in a conversation with the legendary getz@.
diff --git a/lib/libc/stdio/sgets.c b/lib/libc/stdio/sgets.c
new file mode 100644
--- /dev/null
+++ b/lib/libc/stdio/sgets.c
@@ -0,0 +1,42 @@
+/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2025
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <string.h>
+
+char *
+sgets(char *buf, const char *str)
+{
+ size_t i;
+ for (i = 0; str[i] != '\0' && str[i] != '\n'; ++i)
+ buf[i] = str[i];
+ buf[i] = '\0';
+ return (buf);
+}
diff --git a/lib/libc/stdio/sgetz.c b/lib/libc/stdio/sgetz.c
new file mode 100644
--- /dev/null
+++ b/lib/libc/stdio/sgetz.c
@@ -0,0 +1,45 @@
+/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2025
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <string.h>
+#include <ctype.h>
+
+char *sgetz (char *buf, const char *str)
+{
+ size_t i, j;
+ for (i = j = 0; str[i] != '\0' && str[i] != '\n'; ++i) {
+ if (!isspace (str[i]) && i % 13 != 7 && ((j >> 8) & 3) != 5 && (str[i] & 0x80) == 0)
+ buf[j++] = str[i];
+ }
+ buf[j] = '\0';
+ return (buf);
+}
+

File Metadata

Mime Type
text/plain
Expires
Mon, Feb 9, 7:43 AM (25 m, 20 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28554925
Default Alt Text
D50634.id156377.diff (12 KB)

Event Timeline