| 1 | /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- |
| 2 | * |
| 3 | * Copyright (C) 2014,2015 Colin Walters <[email protected]>. |
| 4 | * SPDX-License-Identifier: LGPL-2.0-or-later |
| 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library; if not, write to the |
| 18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 19 | * Boston, MA 02111-1307, USA. |
| 20 | */ |
| 21 | |
| 22 | #pragma once |
| 23 | |
| 24 | #include <glnx-backport-autocleanups.h>cxx . . $ `<file>/subprojects/libglnx/glnx-backport-autocleanups.h`/ |
| 25 | #include <errno.h> |
| 26 | |
| 27 | G_BEGIN_DECLScxx . . $ `<external>/12741050725406041920/gmacros.h:947:9`! |
| 28 | |
| 29 | gbooleancxx . . $ gboolean# glnx_throwcxx . . $ glnx_throw(44907cd5abbe4444). (GErrorcxx . . $ GError# **error, const char *fmt, ...) G_GNUC_PRINTFcxx . . $ `<external>/12741050725406041920/gmacros.h:603:9`! (2,3); |
| 30 | |
| 31 | /* Like `glnx_throw ()`, but returns %NULL. */ |
| 32 | #define glnx_null_throwcxx . . $ `subprojects/libglnx/glnx-errors.h:32:9`!(error, args...) \ |
| 33 | ({glnx_throw (error, args); NULL;}) |
| 34 | |
| 35 | /* Like glnx_throw(), but yields -1 (invalid fd). */ |
| 36 | #define glnx_fd_throwcxx . . $ `subprojects/libglnx/glnx-errors.h:36:9`!(error, args...) \ |
| 37 | ({glnx_throw (error, args); -1;}) |
| 38 | |
| 39 | /* Implementation detail of glnx_throw_prefix() */ |
| 40 | void glnx_real_set_prefix_error_vacxx . . $ glnx_real_set_prefix_error_va(33712557eb8532da). (GErrorcxx . . $ GError# *error, |
| 41 | const char *format, |
| 42 | va_listcxx . . $ va_list# args) G_GNUC_PRINTFcxx . . $ `<external>/12741050725406041920/gmacros.h:603:9`! (2,0); |
| 43 | |
| 44 | gbooleancxx . . $ gboolean# glnx_prefix_errorcxx . . $ glnx_prefix_error(44907cd5abbe4444). (GErrorcxx . . $ GError# **error, const char *fmt, ...) G_GNUC_PRINTFcxx . . $ `<external>/12741050725406041920/gmacros.h:603:9`! (2,3); |
| 45 | |
| 46 | /* Like `glnx_prefix_error ()`, but returns %NULL. */ |
| 47 | #define glnx_prefix_error_nullcxx . . $ `subprojects/libglnx/glnx-errors.h:47:9`!(error, args...) \ |
| 48 | ({glnx_prefix_error (error, args); NULL;}) |
| 49 | |
| 50 | /** |
| 51 | * GLNX_AUTO_PREFIX_ERROR: |
| 52 | * |
| 53 | * An autocleanup-based macro to automatically call `g_prefix_error()` (also with a colon+space `: `) |
| 54 | * when it goes out of scope. This is useful when one wants error strings built up by the callee |
| 55 | * function, not all callers. |
| 56 | * |
| 57 | * ``` |
| 58 | * gboolean start_http_request (..., GError **error) |
| 59 | * { |
| 60 | * GLNX_AUTO_PREFIX_ERROR ("HTTP request", error) |
| 61 | * |
| 62 | * if (!libhttp_request_start (..., error)) |
| 63 | * return FALSE; |
| 64 | * ... |
| 65 | * return TRUE; |
| 66 | * ``` |
| 67 | */ |
| 68 | typedef structcxx . . $ $anonymous_type_169a906759b68c14_0# { |
| 69 | const char *prefixcxx . . $ $anonymous_type_169a906759b68c14_0#prefix.; |
| 70 | GErrorcxx . . $ GError# **errorcxx . . $ $anonymous_type_169a906759b68c14_0#error.; |
| 71 | } GLnxAutoErrorPrefixcxx . . $ GLnxAutoErrorPrefix#; |
| 72 | static inline void |
| 73 | glnx_cleanup_auto_prefix_errorcxx . . $ glnx_cleanup_auto_prefix_error(67c890a12b2ec5ba). (GLnxAutoErrorPrefixcxx . . $ GLnxAutoErrorPrefix# *prefix) |
| 74 | { |
| 75 | if (prefix->errorcxx . . $ $anonymous_type_169a906759b68c14_0#error. && *(prefix->errorcxx . . $ $anonymous_type_169a906759b68c14_0#error.)) |
| 76 | g_prefix_errorcxx . . $ g_prefix_error(61ba7b15d5a0f9c8). (prefix->errorcxx . . $ $anonymous_type_169a906759b68c14_0#error., "%s: ", prefix->prefixcxx . . $ $anonymous_type_169a906759b68c14_0#prefix.); |
| 77 | } |
| 78 | G_DEFINE_AUTO_CLEANUP_CLEAR_FUNCcxx . . $ glnx_cleanup_auto_prefix_error(67c890a12b2ec5ba).(GLnxAutoErrorPrefix, glnx_cleanup_auto_prefix_error) |
| 79 | #define GLNX_AUTO_PREFIX_ERRORcxx . . $ `subprojects/libglnx/glnx-errors.h:79:9`!(text, error) \ |
| 80 | G_GNUC_UNUSEDcxx . . $ `<external>/12741050725406041920/gmacros.h:647:9`! g_autocxx . . $ `<external>/12741050725406041920/gmacros.h:1428:9`!(GLnxAutoErrorPrefix) _GLNX_MAKE_ANONYMOUScxx . . $ `subprojects/libglnx/glnx-macros.h:130:9`!(_glnxautoprefixerror_) = { text, error } |
| 81 | |
| 82 | /* Set @error using the value of `g_strerror (errno)`. |
| 83 | * |
| 84 | * This function returns %FALSE so it can be used conveniently in a single |
| 85 | * statement: |
| 86 | * |
| 87 | * ``` |
| 88 | * if (unlinkat (fd, somepathname) < 0) |
| 89 | * return glnx_throw_errno (error); |
| 90 | * ``` |
| 91 | */ |
| 92 | static inline gbooleancxx . . $ gboolean# |
| 93 | glnx_throw_errnocxx . . $ glnx_throw_errno(99147cdc3c1dad38). (GErrorcxx . . $ GError# **error) |
| 94 | { |
| 95 | /* Save the value of errno, in case one of the |
| 96 | * intermediate function calls happens to set it. |
| 97 | */ |
| 98 | int errsv = errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!; |
| 99 | g_set_error_literalcxx . . $ g_set_error_literal(af35e45b47ff535e). (error, G_IO_ERRORcxx . . $ `<external>/13894955190784973534/gioerror.h:42:9`!, |
| 100 | g_io_error_from_errnocxx . . $ g_io_error_from_errno(b47e8a466716fd56). (errsv), |
| 101 | g_strerrorcxx . . $ g_strerror(f7ae7e56280f18ae). (errsv)); |
| 102 | /* We also restore the value of errno, since that's |
| 103 | * what was done in a long-ago libgsystem commit |
| 104 | * https://gitlab.gnome.org/Archive/libgsystem/-/commit/ed106741f7a0596dc8b960b31fdae671d31d666d |
| 105 | * but I certainly can't remember now why I did that. |
| 106 | */ |
| 107 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = errsv; |
| 108 | return FALSEcxx . . $ `<external>/12741050725406041920/gmacros.h:967:9`!; |
| 109 | } |
| 110 | |
| 111 | /* Like glnx_throw_errno(), but yields a NULL pointer. */ |
| 112 | #define glnx_null_throw_errnocxx . . $ `subprojects/libglnx/glnx-errors.h:112:9`!(error) \ |
| 113 | ({glnx_throw_errno (error); NULL;}) |
| 114 | |
| 115 | /* Like glnx_throw_errno(), but yields -1 (invalid fd). */ |
| 116 | #define glnx_fd_throw_errnocxx . . $ `subprojects/libglnx/glnx-errors.h:116:9`!(error) \ |
| 117 | ({glnx_throw_errno (error); -1;}) |
| 118 | |
| 119 | /* Implementation detail of glnx_throw_errno_prefix() */ |
| 120 | void glnx_real_set_prefix_error_from_errno_vacxx . . $ glnx_real_set_prefix_error_from_errno_va(469dc1b487d97517). (GErrorcxx . . $ GError# **error, |
| 121 | gintcxx . . $ gint# errsv, |
| 122 | const char *format, |
| 123 | va_listcxx . . $ va_list# args) G_GNUC_PRINTFcxx . . $ `<external>/12741050725406041920/gmacros.h:603:9`! (3,0); |
| 124 | |
| 125 | gbooleancxx . . $ gboolean# glnx_throw_errno_prefixcxx . . $ glnx_throw_errno_prefix(44907cd5abbe4444). (GErrorcxx . . $ GError# **error, const char *fmt, ...) G_GNUC_PRINTFcxx . . $ `<external>/12741050725406041920/gmacros.h:603:9`! (2,3); |
| 126 | |
| 127 | /* Like glnx_throw_errno_prefix(), but yields a NULL pointer. */ |
| 128 | #define glnx_null_throw_errno_prefixcxx . . $ `subprojects/libglnx/glnx-errors.h:128:9`!(error, args...) \ |
| 129 | ({glnx_throw_errno_prefix (error, args); NULL;}) |
| 130 | |
| 131 | /* Like glnx_throw_errno_prefix(), but yields -1 (invalid fd). */ |
| 132 | #define glnx_fd_throw_errno_prefixcxx . . $ `subprojects/libglnx/glnx-errors.h:132:9`!(error, args...) \ |
| 133 | ({glnx_throw_errno_prefix (error, args); -1;}) |
| 134 | |
| 135 | /* BEGIN LEGACY APIS */ |
| 136 | |
| 137 | #define glnx_set_error_from_errnocxx . . $ `subprojects/libglnx/glnx-errors.h:137:9`!(error) \ |
| 138 | do { \ |
| 139 | glnx_throw_errno (error); \ |
| 140 | } while (0); |
| 141 | |
| 142 | #define glnx_set_prefix_error_from_errnocxx . . $ `subprojects/libglnx/glnx-errors.h:142:9`!(error, format, args...) \ |
| 143 | do { \ |
| 144 | glnx_throw_errno_prefix (error, format, args); \ |
| 145 | } while (0); |
| 146 | |
| 147 | G_END_DECLScxx . . $ `<external>/12741050725406041920/gmacros.h:948:9`! |