aboutsummaryrefslogtreecommitdiffstats
path: root/src/estream.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* Release 1.39libgpg-error-1.39gpgrt-1.39Werner Koch2020-08-241-1/+1
|
* core,w32: Add UTF-8 support to gpgrt_fopen, gpgrt_mkdir and gpgrt_chdir.Werner Koch2020-08-211-3/+122
| | | | | | | | | | | | | | | | | | | | * src/protos.h: New. * src/Makefile.am (libgpg_error_la_SOURCES): Add file. * src/gpgrt-int.h: Include protos.h. * src/sysutils.c (_gpgrt_mkdir) [W32]: Make UTF-8 aware. (_gpgrt_chdir) [W32]: Ditto. * src/w32-gettext.c: Include protos.h. (utf8_to_wchar): Allow for strings. (_gpgrt_utf8_to_wchar): New. (_gpgrt_free_wchar): New. * src/estream.c (map_w32_to_errno): Add more error codes. (_gpgrt_w32_set_errno): New. (any8bitchar) [W32]: New helper. (func_file_create) [W32]: Convert file name and use _wopen. -- GnuPG-bug-id: 4083 Signed-off-by: Werner Koch <[email protected]>
* estream: Add gpgrt_fcancelWerner Koch2020-06-261-9/+32
| | | | | | | | | | | | * src/estream.c (do_close): Add arg 'cancel_mode' and chnage all callers. (_gpgrt_fcancel): New. * src/gpg-error.def.in, src/gpg-error.vers: Add function. * src/visibility.c (gpgrt_fcancel): New. * src/gpg-error.h.in (gpgrt_fcancel): New. -- Signed-off-by: Werner Koch <[email protected]>
* estream: Care about erroneous case for stream close.NIIBE Yutaka2019-09-181-10/+5
| | | | | | | | * src/estream.c (do_list_remove): Only access ITEM->NEXT when it's not null. GnuPG-bug-id: 4698 Signed-off-by: NIIBE Yutaka <[email protected]>
* estream: Fix gpgrt_poll at EOF.NIIBE Yutaka2019-08-231-1/+1
| | | | | | | | | | | | | | * src/estream.c [HAVE_POLL_H] (_gpgrt_poll): Catch POLLHUP event for want_read. -- At EOF, here is a difference of semantics between poll(2) and select(2). For poll(2), detection of EOF is an event of POLLHUP, not POLLIN. Fixes-commit: a21a7de8c2cf986235382e7e04805744f6df116e Signed-off-by: NIIBE Yutaka <[email protected]>
* estream: Fix gpgrt_poll to prevent waiting indefinitely for others.NIIBE Yutaka2019-08-231-0/+3
| | | | | | * src/estream.c (_gpgrt_poll): Go to leave, when something is ready. Signed-off-by: NIIBE Yutaka <[email protected]>
* estream: Fix poll condition.NIIBE Yutaka2019-08-221-3/+4
| | | | | | * src/estream.c (_gpgrt_poll): Fix for want_oob. Signed-off-by: NIIBE Yutaka <[email protected]>
* w32: Fix cast to internal fd.NIIBE Yutaka2019-07-251-1/+1
| | | | | | * src/estream.c (tmpfd): Use intptr_t. Signed-off-by: NIIBE Yutaka <[email protected]>
* estream: Fix IS_INVALID_FD.NIIBE Yutaka2019-07-251-5/+1
| | | | | | | | | | | | * src/estream.c (IS_INVALID_FD): Simply compare to -1. -- Perhaps, when it was written at first, use of HANDLE was in mind. Now, we have different set of methods for Windows, and this macro is only for integer fd access, no need of ifdef/endif. Signed-off-by: NIIBE Yutaka <[email protected]>
* estream: Add missing malloc check.Werner Koch2019-06-271-1/+6
| | | | | | * src/estream.c (_gpgrt_poll): Check for malloc error. Signed-off-by: Werner Koch <[email protected]>
* estream: Don't use variable length array.NIIBE Yutaka2019-06-261-1/+7
| | | | | | | | | * src/estream.c [HAVE_POLL_H] (_gpgrt_poll): No VLA. -- Fixes-commit: a21a7de8c2cf986235382e7e04805744f6df116e Signed-off-by: NIIBE Yutaka <[email protected]>
* estream: Use poll(2) when available.NIIBE Yutaka2019-06-261-0/+82
| | | | | | | | | | | * configure.ac: Detect poll.h. * src/estream.c [HAVE_POLL_H] (_gpgrt_poll): Use poll. -- Here, we use C99 feature of array declaration with variable. Signed-off-by: NIIBE Yutaka <[email protected]>
* core: New functions gpgrt_abort and gpgrt_add_emergency_cleanup.Werner Koch2019-01-041-9/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | * src/init.c (emergency_cleanup_list): New gloabl var. (_gpgrt_add_emergency_cleanup): New. (_gpgrt_abort): New. Repalce all calls to abort by this. Also replace all assert by either log_assert or a stderr output followed by a _gpgrt_abort. (run_emergency_cleanup): New. * src/visibility.c (gpgrt_add_emergency_cleanup): New public API. (gpgrt_abort): New public API. -- Libgcrypt uses its own assert function which makes sure to terminate the secure memory. This is safe as log as an assert is triggered internally in Libgcrypt. GnuPG runs emergency cleanup handlers right before log_fatal etc to tell Libgcrypt to terminate the secure memory. With the move of the logging function to gpgrt in gnupg 2.3 this did not anymore. Thus we now provide a mechanism in gpgrt to do right that. Eventually Libgcrypt can also make use of this. What this does not handle are calls to abort or failed asserts in external libraries or in libc. We can't do anything about it in a library because a library may not setup signal handlers. Signed-off-by: Werner Koch <[email protected]>
* core: New functions gpgrt_fprintf_sf anf gpgrt_fprintf_sf_unlocked.Werner Koch2018-11-261-5/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | * src/gpg-error.h.in (gpgrt_string_filter_t): New type. (gpgrt_fprintf_sf, gpgrt_fprintf_sf_unlocked): New. * src/gpg-error.vers, src/gpg-error.def.in: Add them. * src/visibility.c (gpgrt_fprintf_sf): New. (gpgrt_fprintf_sf_unlocked): New. * src/estream-printf.c (pr_string): Add and use args sf, sfvalue and string_no. (do_format): Add args sf and sfvalue. Keep a string format counter. (_gpgrt_estream_format): Add args sf and sfvalue. Change all callers to provide NULL for them. * src/estream.c (_gpgrt_vfprintf_unlocked, _gpgrt_vfprintf): Add sf and sfvalue and adjust all callers. (do_print_stream): Ditto. * tests/t-printf.c (stream_to_string): New. (struct sfstate_s): New. (string_filter): New. (check_fprintf_sf): New. (main): Call new test. -- The actual reason to implement these functions is to enhance the internal logging function with a filter to sanitized strings so that control values or other things can be quoted. Signed-off-by: Werner Koch <[email protected]>
* core: Add a limited version of gpgrt_ftruncate.Werner Koch2018-11-261-0/+31
| | | | | | | | | | | | | | | * src/gpg-error.h.in (gpgrt_ftruncate, es_ftruncate): New. * src/gpg-error.def.in, src/gpg-error.vers: Add gpgrt_ftruncate. * src/visibility.c (gpgrt_ftruncate): new. * src/gpgrt-int.h (COOKIE_IOCTL_TRUNCATE): New. * src/estream.c (func_mem_ioctl): Support new internal IOCTL. (_gpgrt_ftruncate): New. -- Right now the ftruncate works only on memory streams. Can easily be added to other stream times. Signed-off-by: Werner Koch <[email protected]>
* estream: Always propagate flush event to cookie functions.Werner Koch2018-07-121-3/+4
| | | | | | * src/estream.c (flush_stream): Always call cookie's flush func. Signed-off-by: Werner Koch <[email protected]>
* core: Fix gpgrt_poll for Windows under nPth.Werner Koch2018-04-301-0/+2
| | | | | | * src/estream.c (_gpgrt_poll) [W32]: Use syscall clamp. Signed-off-by: Werner Koch <[email protected]>
* doc: Typo fixes.Werner Koch2018-02-211-1/+1
| | | | --
* core: Unify syscall_clamp functions.Werner Koch2017-11-291-92/+32
| | | | | | | | | | | | | | | * src/estream.c (_gpgrt_set_syscall_clamp) (_gpgrt_get_syscall_clamp): Move to ... * src/syscall-clamp.c: new file. (_gpgrt_pre_syscall, _gpgrt_post_syscall): New. * src/Makefile.am (libgpg_error_la_SOURCES): Add that file. * src/estream.c: Replace the syscall wrapper with the new functions. * src/posix-lock.c: Ditto. * src/w32-lock.c: Ditto. * src/posix-thread.c: Ditto. * src/w32-thread.c: Ditto. Signed-off-by: Werner Koch <[email protected]>
* Align 'es_poll' semantics closer with POSIX.Justus Winter2017-05-311-3/+0
| | | | | | | | | | | | | * src/estream.c (_gpgrt_poll): Do not return early if some streams are found to be ready before even polling the others. -- POSIX mandates that all streams are examined and returning early violates that. It also imposes an order on how the callee serves the streams, which might be incompatible with the order the callee wants to serve them, leading to deadlocks. Signed-off-by: Justus Winter <[email protected]>
* Fix memory leak for estream.NIIBE Yutaka2017-05-301-5/+20
| | | | | | | * src/estream.c (do_list_remove): Free the item. (do_close): Free the buffer. Signed-off-by: NIIBE Yutaka <[email protected]>
* Minor clean up.NIIBE Yutaka2017-04-191-2/+2
| | | | | | | | * src/b64dec.c (_gpgrt_b64dec_proc): Add a comment. * src/estream.c (_gpgrt_fread, _gpgrt_fwrite): Use &&. * src/mkheader.c (xstrdup): Use memcpy as we know length. Signed-off-by: NIIBE Yutaka <[email protected]>
* Improve tracing of estream.Werner Koch2017-02-281-15/+39
| | | | | | | | | | | | * src/gpgrt-int.h (trace_errno): Add new parameter. Adjust all users. * src/init.c (trace_fp, trace_with_errno, trace_missing_lf) (trace_prefix_done): New vars. (_gpgrt_internal_trace_begin): Add arg WITH_ERRNO. Open a trace file on first use. Init new vars. (print_internal_trace_prefix): New. * src/estream.c, src/w32-estream.c: Improve tracing. Signed-off-by: Werner Koch <[email protected]>
* w32: Fix gpgrt_poll for Windows.Werner Koch2017-02-281-6/+0
| | | | | | | | | | | | * src/estream.c (_gpgrt_poll) [W32]: Do not call the syscall clamp. -- The system call clamp may only be used directloy around system calls. We don't need them here because we use independent threads to implement non-blocking behaviour. In fact the clamp may lead to a deadlock. Signed-off-by: Werner Koch <[email protected]>
* Use the new tracing ramework for estream.Werner Koch2017-02-261-9/+76
| | | | | | | | | * src/estream.c: Add trace calls to some functions. * src/w32-estream.c: Replace existing trace calls by the new framework. -- Signed-off-by: Werner Koch <[email protected]>
* Rename internal functions of estream.Werner Koch2017-02-261-90/+91
| | | | | | | | | | | | | | | | | | | | * src/estream.c (_gpgrt_es_init): Rename to _gpgrt_estream_init. (es_fill): Rename to fill_stream. (es_fflush): Rename to flush_stream. (es_deinitialize): Rename to deinit_stream_obj. (es_create): Rename to create_stream (es_read_nbf): Rename to do_read_nbf. (es_read_lbf): Rename to do_read_lbf. (es_read_fbf): Rename to do_read_fbf. (es_peek): Rename to peek_stream. (es_skip): Rename to skip_stream. (es_print): Rename to do_print_stream. -- The use of the "es_" was confusing. Avoid that. Signed-off-by: Werner Koch <[email protected]>
* w32: Do not use the syscall clamps in pollable mode.Werner Koch2017-02-241-10/+36
| | | | | | | | | | | | | * src/estream.c (estream_cookie_w32): Add flag no_syscall_clamp. (func_w32_create): Add arg no_syscall_clamp. (func_w32_read): Do not call pre/post_syscall_clamp when flag is set. (func_w32_write): Ditto. (func_w32_seek): Ditto. (do_w32open): Set NO_SYSCALL_CLAMP in pollable mode. (es_create) [W32]: Make sure that pollable-mode is unly used with the W32 backend. Signed-off-by: Werner Koch <[email protected]>
* estream: Correctly set ERRNO to EOPNOTSUPP.Werner Koch2017-01-191-2/+4
| | | | | | | * src/estream.c (es_flush, es_write_nbf): Fix setting of ERRNO to EOPNOTSUPP. Signed-off-by: Werner Koch <[email protected]>
* estream: Minor portability fix.Werner Koch2016-11-121-3/+3
| | | | | | | | | | -- A trailing comma in an enum is not groked by all compilers. Binary operation should have their own parentheses to make it clear that a binary operator was meant. Signed-off-by: Werner Koch <[email protected]>
* estream: Support 'es_poll' on Windows.Justus Winter2016-11-121-73/+52
| | | | | | | | | | | | | | | | | | | | | * src/Makefile.am (arch_sources): Add new file. * src/estream.c (O_NONBLOCK): Move to 'gpgrt-int.h'. (BUFFER_BLOCK_SIZE): Likewise. (BUFFER_UNREAD_SIZE): Likewise. (struct notify_list_s, notify_list_t): Likewise. (struct _gpgrt_stream_internal, estream_internal_t): Likewise. (X_POLLABLE): New macro. (parse_mode): Parse keyword 'pollable', emulate O_NONBLOCK using the same mechanism on Windows. (_gpgrt_poll): Use the new '_gpgrt_w32_poll' on Windows. * src/gpgrt-int.h (_gpgrt_functions_w32_pollable): New declaration. (_gpgrt_w32_pollable_create): New prototype. (_gpgrt_w32_poll): Likewise. * src/w32-estream.c: New file. This code is adapted from GPGME. * tests/t-poll.c (create_pipe): Create pollable streams. GnuPG-bug-id: 2731 Signed-off-by: Justus Winter <[email protected]>
* estream: Track the kind of backend used.Justus Winter2016-11-121-17/+22
| | | | | | | | | * src/estream.c (struct _gpgrt_stream_internal): Add 'kind'. (init_stream_obj): New parameter 'kind', initialize field. (es_create): New parameter 'kind'. Update all callers. * src/gpgrt-int.h (gpgrt_stream_backend_kind_t): New type. Signed-off-by: Justus Winter <[email protected]>
* estream: Rework how the cookie functions are handled.Justus Winter2016-11-121-49/+49
| | | | | | | | | | | | | | | | | | | | | | * src/estream.c (cookie_ioctl_function_t): Move to 'gpgrt-int.h', along with the macros for the IOCTL numbers. (estream_functions_mem): Use the new type and add the ioctl function. (estream_functions_fd): Likewise. (estream_functions_w32): Likewise. (estream_functions_fp): Likewise. (init_stream_object): Use the new type, and also initialize 'func_ioctl'. (es_create): Use the new type. (_gpgrt_fopen): Adapt. (_gpgrt_mopen): Likewise. (_gpgrt_fopenmem): Likewise. (_gpgrt_fopencookie): Likewise. (_gpgrt_fdopen): Likewise. (_gpgrt_fpopen): Likewise. (do_w32open): Likewise. * src/gpgrt-int.h (struct cookie_io_functions_s): New type. Signed-off-by: Justus Winter <[email protected]>
* estream: Rework modestring handling.Justus Winter2016-11-121-46/+44
| | | | | | | | | | | | | | | | | | * src/estream.c (X_SAMETHREAD, X_SYSOPEN): New macros. (parse_mode): Rework how information flows from here to 'es_create'. Instead of using an integer flag per mode, use flags. (init_stream_obj): Adapt accordingly. (es_create): Likewise. (_gpgrt_fopen): Likewise. (_gpgrt_mopen): Likewise. (_gpgrt_fopenmem): Likewise. (_gpgrt_fopencookie): Likewise. (_gpgrt_fdopen): Likewise. (_gpgrt_fpopen): Likewise. (do_w32open): Likewise. (_gpgrt_freopen): Likewise. Signed-off-by: Justus Winter <[email protected]>
* Add new interface gpgrt_get_syscall_clamp.Werner Koch2016-11-121-0/+11
| | | | | | | | | | | | | * src/visibility.c (gpgrt_get_syscall_clamp): New. * src/gpg-error.vers, src/gpg-error.def.in: Add function. * src/gpg-error.h.in: Ditto. * src/estream.c (_gpgrt_get_syscall_clamp): New. -- This function can be used by other libraries to set their own system clamp functions. Signed-off-by: Werner Koch <[email protected]>
* Use the syscall clamp functions also for lock functionsWerner Koch2016-11-111-1/+6
| | | | | | | | | | | | | | | | | | | | * src/posix-lock.c (pre_lock_func, post_lock_func): New. (_gpgrt_lock_set_lock_clamp): New. (_gpgrt_lock_lock): Use clamp functions. * src/w32-lock.c (pre_lock_func, post_lock_func): New. (_gpgrt_lock_set_lock_clamp): New. (_gpgrt_lock_lock): Use clamp functions. * src/posix-lock.c (pre_syscall_func, post_syscall_func): New. (_gpgrt_thread_set_syscall_clamp): New. (_gpgrt_yield): Use clamp functions. * src/w32-lock.c (pre_syscall_func, post_syscall_func): New. (_gpgrt_thread_set_syscall_clamp): New. (_gpgrt_yield): Use clamp functions. * src/estream.c: Include lock.h and thread.h. (do_deinit): Call _gpgrt_lock_set_lock_clamp. (_gpgrt_set_syscall_clamp): Ditto. Signed-off-by: Werner Koch <[email protected]>
* estream: Fix modestring parsing.Justus Winter2016-10-181-1/+1
| | | | | | * src/estream.c (parse_mode): Fix parsing the 'sysopen' flag. Signed-off-by: Justus Winter <[email protected]>
* Define EWOULDBLOCK in case it is not definedAndre Heinecke2016-07-051-0/+5
| | | | | | | * src/estream.c (EWOULDBLOCK): Define fallback. -- Older mingw versions (2.0) do not define EWOULDBLOCK in errno.h
* estream: Fix bug es_fclose_snatch if a seek has been used.Werner Koch2016-06-271-1/+1
| | | | | | * src/estream.c (func_mem_ioctl): Set LEN from DATA_LEN. Signed-off-by: Werner Koch <[email protected]>
* w32: Silence compiler warnings about redefined macros.Werner Koch2016-06-251-6/+19
| | | | | | * src/estream.c (S_IRGRP) [W32]: Protect against redefinition. Signed-off-by: Werner Koch <[email protected]>
* estream: Remove two compiler warning.Werner Koch2016-06-241-40/+41
| | | | | | | | | * src/estream.c (func_file_create): Remove dead assignment. (doreadline): Do not decrement SPACE_LEFT before breaking the loop. Add an extra block to limit the scope of that variable. -- Signed-off-by: Werner Koch <[email protected]>
* estream: Fix assertion failure due to es_flush.NIIBE Yutaka2016-06-151-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | * src/estream.c (es_writen): Set writing flag even if no data was written. -- GnuPG-bug-id: 2371 Signed-off-by: Werner Koch <[email protected]> gniibe tracked the problem down to a fully valid change in GnuPG (gnupg commit 12af2630cf4d1a39179179925fac8f2cce7504ff). He wrote: This is the first instance for estream to do READ and WRITE (in the history of the code > 10 years :-). In the [gnupg] function agent_write_private_key, the pattern is: es_fopen es_fread es_fseek es_fwrite which should work well, but if results core dump by assertion failure in the function es_flush of libgpg-error.
* Adjust memory limit of es_fopenmem to the block size.Werner Koch2016-06-151-0/+8
| | | | | | | | | | * src/estream.c (func_mem_create): Round up memory limit. -- This is required so that giving a memory limit to es_fopenmem won't fail if it is below the block size. Signed-off-by: Werner Koch <[email protected]>
* estream,w32: Temporary fix for gpgrt_poll.Werner Koch2016-04-051-0/+4
| | | | | | | | | | | * src/estream.c (_gpgrt_poll) [W32]: Do not use FD_ISSET. -- gpgrt_poll return an error on Windows anyway and thus it does not make sense to use a possible undefined macro here. Reported-by: Andre Heinecke Signed-off-by: Werner Koch <[email protected]>
* estream: Prepare for new mode flag "sysopen".Werner Koch2016-03-291-14/+47
| | | | | | * src/estream.c (parse_mode): Add arg "sysopen". Adjust all callers. Signed-off-by: Werner Koch <[email protected]>
* estream: Use simpler names for static functions.Werner Koch2016-03-291-44/+44
| | | | | | * src/estream.c: Replace all es_func_* to just func_*. Signed-off-by: Werner Koch <[email protected]>
* doc: Re-format comments in estream.cWerner Koch2016-03-291-150/+311
| | | | | -- Signed-off-by: Werner Koch <[email protected]>
* estream: Remove strange macro for better readability.Werner Koch2016-03-291-15/+11
| | | | | | | * src/estream.c (SET_UNLESS_NONZERO): Remove macro. (es_deinitialize): Replace that macro by direct code. Signed-off-by: Werner Koch <[email protected]>
* Convert http links to https where possible in the source.Daniel Kahn Gillmor2016-02-081-1/+1
| | | | | | | | | | | | | | | | -- * use https for bug reporting * in comments and docs, use https to refer to: - www.gnu.org - creativecommons.org - translationproject.org - mail.gnome.org - www.perl.org - www.ctan.org - www.cl.cam.ac.uk - www.ntg.nl - cygwin.com - www.ethnologue.com
* Fix typos found by codespell.Justus Winter2015-11-191-3/+3
| | | | | -- Signed-off-by: Justus Winter <[email protected]>
* estream: Avoid calling write(fd,NULL,n).Werner Koch2015-10-181-20/+32
| | | | | | | | | | | | | | | * src/estream.c (es_func_fd_write): Take care of a flush requests. (es_func_w32_write): Ditto. (es_func_fp_write): Ditto. -- The write handlers may be called with (BUFFER,SIZE) of (NULL,0) to propagate flush events to user supplied functions (es_fopencookie). However we need to take care to also do this with the internal handler. Might be a reason for system faults due to write or fwrite with a NULL buffer; on Linux this seems to be harmless. Signed-off-by: Werner Koch <[email protected]>