This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] __fsetlocking


Another of the stdio_ext functions from Solaris and glibc:

https://docs.oracle.com/cd/E19683-01/816-0213/6m6ne37vm/index.html
http://man7.org/linux/man-pages/man3/stdio_ext.3.html

Patch attached.

--
Yaakov Selkowitz
Associate Software Engineer, ARM
Red Hat, Inc.
2014-12-11  Yaakov Selkowitz  <yselkowi@...>

	* libc/include/stdio.h (__SNLK): Define.
	* libc/include/stdio_ext.h (FSETLOCKING_QUERY, FSETLOCKING_INTERNAL,
	FSETLOCKING_BYCALLER): Define.
	(__fsetlocking): Declare.
	* libc/stdio/Makefile.am: Build fsetlocking.c.
	* libc/stdio/Makefile.in: Regenerate.
	* libc/stdio/fsetlocking.c: New file.
	* libc/stdio/local.h (_newlib_flockfile_start): Make _flockfile
	call dependent on __SNLK flag.
	(_newlib_flockfile_exit, _newlib_flockfile_end): Ditto for
	_funlockfile calls.
	* libc/stdio/stdio.tex: Include fsetlocking.def.

Index: libc/include/stdio.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/stdio.h,v
retrieving revision 1.71
diff -u -p -r1.71 stdio.h
--- libc/include/stdio.h	9 May 2014 14:25:32 -0000	1.71
+++ libc/include/stdio.h	11 Dec 2014 17:42:01 -0000
@@ -83,6 +83,7 @@ typedef _fpos64_t fpos64_t;
 #define	__SL64	0x8000		/* is 64-bit offset large file */
 
 /* _flags2 flags */
+#define	__SNLK  0x0001		/* stdio functions do not lock streams themselves */
 #define	__SWID	0x2000		/* true => stream orientation wide, false => byte, only valid if __SORD in _flags is true */
 
 /*
Index: libc/include/stdio_ext.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/stdio_ext.h,v
retrieving revision 1.4
diff -u -p -r1.4 stdio_ext.h
--- libc/include/stdio_ext.h	11 Dec 2014 16:53:32 -0000	1.4
+++ libc/include/stdio_ext.h	11 Dec 2014 17:42:01 -0000
@@ -13,14 +13,18 @@
 
 #include <stdio.h>
 
+#define	FSETLOCKING_QUERY	0
+#define	FSETLOCKING_INTERNAL	1
+#define	FSETLOCKING_BYCALLER	2
+
 _BEGIN_STD_C
 
 void	 _EXFUN(__fpurge,(FILE *));
+int	 _EXFUN(__fsetlocking,(FILE *, int));
 
 /* TODO:
 
    void _flushlbf (void);
-   int __fsetlocking (FILE *__fp, int __type);
 */
 
 #ifdef  __GNUC__
Index: libc/stdio/Makefile.am
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/Makefile.am,v
retrieving revision 1.36
diff -u -p -r1.36 Makefile.am
--- libc/stdio/Makefile.am	11 Dec 2014 16:53:32 -0000	1.36
+++ libc/stdio/Makefile.am	11 Dec 2014 17:42:01 -0000
@@ -146,6 +146,7 @@ ELIX_4_SOURCES = \
 	fpurge.c		\
 	fputwc.c		\
 	fputws.c		\
+	fsetlocking.c		\
 	funopen.c		\
 	fwide.c			\
 	fwprintf.c		\
@@ -357,6 +358,7 @@ CHEWOUT_FILES = \
 	fread.def		\
 	freopen.def		\
 	fseek.def		\
+	fsetlocking.def		\
 	fsetpos.def		\
 	ftell.def		\
 	funopen.def		\
@@ -433,6 +435,7 @@ $(lpfx)fputws.$(oext): local.h fvwrite.h
 $(lpfx)fread.$(oext): local.h
 $(lpfx)freopen.$(oext): local.h
 $(lpfx)fseek.$(oext): local.h
+$(lpfx)fsetlocking.$(oext): local.h
 $(lpfx)ftell.$(oext): local.h
 $(lpfx)funopen.$(oext): local.h
 $(lpfx)fvwrite.$(oext): local.h fvwrite.h
Index: libc/stdio/Makefile.in
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/Makefile.in,v
retrieving revision 1.57
diff -u -p -r1.57 Makefile.in
--- libc/stdio/Makefile.in	11 Dec 2014 16:53:32 -0000	1.57
+++ libc/stdio/Makefile.in	11 Dec 2014 17:42:01 -0000
@@ -143,6 +143,7 @@ am__objects_2 = $(am__objects_1) lib_a-c
 @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@	lib_a-fpurge.$(OBJEXT) \
 @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@	lib_a-fputwc.$(OBJEXT) \
 @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@	lib_a-fputws.$(OBJEXT) \
+@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@	lib_a-fsetlocking.$(OBJEXT) \
 @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@	lib_a-funopen.$(OBJEXT) \
 @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@	lib_a-fwide.$(OBJEXT) \
 @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@	lib_a-fwprintf.$(OBJEXT) \
@@ -206,6 +207,7 @@ am__objects_8 = $(am__objects_7) clearer
 @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@	fpurge.lo \
 @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@	fputwc.lo \
 @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@	fputws.lo \
+@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@	fsetlocking.lo \
 @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@	funopen.lo \
 @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@	fwide.lo \
 @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@	fwprintf.lo \
@@ -514,6 +516,7 @@ GENERAL_SOURCES = \
 @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@	fpurge.c		\
 @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@	fputwc.c		\
 @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@	fputws.c		\
+@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@	fsetlocking.c		\
 @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@	funopen.c		\
 @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@	fwide.c			\
 @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@	fwprintf.c		\
@@ -631,6 +634,7 @@ CHEWOUT_FILES = \
 	fread.def		\
 	freopen.def		\
 	fseek.def		\
+	fsetlocking.def		\
 	fsetpos.def		\
 	ftell.def		\
 	funopen.def		\
@@ -1355,6 +1359,12 @@ lib_a-fputws.o: fputws.c
 lib_a-fputws.obj: fputws.c
 	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-fputws.obj `if test -f 'fputws.c'; then $(CYGPATH_W) 'fputws.c'; else $(CYGPATH_W) '$(srcdir)/fputws.c'; fi`
 
+lib_a-fsetlocking.o: fsetlocking.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-fsetlocking.o `test -f 'fsetlocking.c' || echo '$(srcdir)/'`fsetlocking.c
+
+lib_a-fsetlocking.obj: fsetlocking.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-fsetlocking.obj `if test -f 'fsetlocking.c'; then $(CYGPATH_W) 'fsetlocking.c'; else $(CYGPATH_W) '$(srcdir)/fsetlocking.c'; fi`
+
 lib_a-funopen.o: funopen.c
 	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-funopen.o `test -f 'funopen.c' || echo '$(srcdir)/'`funopen.c
 
@@ -1772,6 +1782,7 @@ $(lpfx)fputws.$(oext): local.h fvwrite.h
 $(lpfx)fread.$(oext): local.h
 $(lpfx)freopen.$(oext): local.h
 $(lpfx)fseek.$(oext): local.h
+$(lpfx)fsetlocking.$(oext): local.h
 $(lpfx)ftell.$(oext): local.h
 $(lpfx)funopen.$(oext): local.h
 $(lpfx)fvwrite.$(oext): local.h fvwrite.h
Index: libc/stdio/fsetlocking.c
===================================================================
RCS file: libc/stdio/fsetlocking.c
diff -N libc/stdio/fsetlocking.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ libc/stdio/fsetlocking.c	11 Dec 2014 17:42:01 -0000
@@ -0,0 +1,65 @@
+/*
+FUNCTION
+<<__fsetlocking>>---set or query locking mode on FILE stream
+
+INDEX
+	__fsetlocking
+
+ANSI_SYNOPSIS
+	#include <stdio.h>
+	#include <stdio_ext.h>
+	int __fsetlocking(FILE *<[fp]>, int <[type]>);
+
+DESCRIPTION
+This function sets how the stdio functions handle locking of FILE <[fp]>.
+The following values describe <[type]>:
+
+<<FSETLOCKING_INTERNAL>> is the default state, where stdio functions
+automatically lock and unlock the stream.
+
+<<FSETLOCKING_BYCALLER>> means that automatic locking in stdio functions
+is disabled. Applications which set this take all responsibility for file
+locking themselves.
+
+<<FSETLOCKING_QUERY>> returns the current locking mode without changing it.
+
+RETURNS
+<<__fsetlocking>> returns the current locking mode of <[fp]>.
+
+PORTABILITY
+This function originates from Solaris and is also provided by GNU libc.
+
+No supporting OS subroutines are required.
+*/
+
+#ifndef __rtems__
+
+#include <_ansi.h>
+#include <stdio.h>
+#include <stdio_ext.h>
+#include "local.h"
+
+int
+_DEFUN(__fsetlocking, (fp, type),
+       FILE * fp _AND
+       int type)
+{
+  int result;
+  CHECK_INIT(_REENT, fp);
+  result = (fp->_flags2 & __SNLK) ? FSETLOCKING_BYCALLER : FSETLOCKING_INTERNAL;
+  switch (type)
+    {
+    case FSETLOCKING_BYCALLER:
+      fp->_flags2 |= __SNLK;
+      break;
+    case FSETLOCKING_INTERNAL:
+      fp->_flags2 &= ~__SNLK;
+      break;
+    case FSETLOCKING_QUERY:
+    default:
+      break;
+    }
+  return result;
+}
+
+#endif /* __rtems__ */
Index: libc/stdio/local.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/local.h,v
retrieving revision 1.40
diff -u -p -r1.40 local.h
--- libc/stdio/local.h	4 Apr 2014 21:40:58 -0000	1.40
+++ libc/stdio/local.h	11 Dec 2014 17:42:01 -0000
@@ -68,16 +68,19 @@
 	{ \
 	  int __oldfpcancel; \
 	  pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &__oldfpcancel); \
-	  _flockfile (_fp)
+	  if (!(_fp->_flags2 & __SNLK)) \
+	    _flockfile (_fp)
 
 /* Exit from a stream oriented critical section prematurely: */
 # define _newlib_flockfile_exit(_fp) \
-	  _funlockfile (_fp); \
+	  if (!(_fp->_flags2 & __SNLK)) \
+	    _funlockfile (_fp); \
 	  pthread_setcancelstate (__oldfpcancel, &__oldfpcancel);
 
 /* End a stream oriented critical section: */
 # define _newlib_flockfile_end(_fp) \
-	  _funlockfile (_fp); \
+	  if (!(_fp->_flags2 & __SNLK)) \
+	    _funlockfile (_fp); \
 	  pthread_setcancelstate (__oldfpcancel, &__oldfpcancel); \
 	}
 
@@ -103,13 +106,16 @@
 
 # define _newlib_flockfile_start(_fp) \
 	{ \
-		_flockfile(_fp)
+		if (!(_fp->_flags2 & __SNLK)) \
+		  _flockfile (_fp)
 
 # define _newlib_flockfile_exit(_fp) \
-		_funlockfile(_fp); \
+		if (!(_fp->_flags2 & __SNLK)) \
+		  _funlockfile(_fp); \
 
 # define _newlib_flockfile_end(_fp) \
-		_funlockfile(_fp); \
+		if (!(_fp->_flags2 & __SNLK)) \
+		  _funlockfile(_fp); \
 	}
 
 # define _newlib_sfp_lock_start() \
Index: libc/stdio/stdio.tex
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/stdio.tex,v
retrieving revision 1.16
diff -u -p -r1.16 stdio.tex
--- libc/stdio/stdio.tex	11 Dec 2014 16:53:32 -0000	1.16
+++ libc/stdio/stdio.tex	11 Dec 2014 17:49:42 -0000
@@ -178,6 +178,9 @@ structure.
 @include stdio/fseek.def
 
 @page
+@include stdio/fsetlocking.def
+
+@page
 @include stdio/fsetpos.def
 
 @page

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]