• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2023 Google LLC.  All rights reserved.
3 //
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file or at
6 // https://developers.google.com/open-source/licenses/bsd
7 
8 #ifndef UPB_BASE_STATUS_H_
9 #define UPB_BASE_STATUS_H_
10 
11 #include <stdarg.h>
12 
13 // Must be last.
14 #include "upb/port/def.inc"
15 
16 #define _kUpb_Status_MaxMessage 511
17 
18 typedef struct {
19   bool ok;
20   char msg[_kUpb_Status_MaxMessage];  // Error message; NULL-terminated.
21 } upb_Status;
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 UPB_API const char* upb_Status_ErrorMessage(const upb_Status* status);
28 UPB_API bool upb_Status_IsOk(const upb_Status* status);
29 
30 // These are no-op if |status| is NULL.
31 UPB_API void upb_Status_Clear(upb_Status* status);
32 void upb_Status_SetErrorMessage(upb_Status* status, const char* msg);
33 void upb_Status_SetErrorFormat(upb_Status* status, const char* fmt, ...)
34     UPB_PRINTF(2, 3);
35 void upb_Status_VSetErrorFormat(upb_Status* status, const char* fmt,
36                                 va_list args) UPB_PRINTF(2, 0);
37 void upb_Status_VAppendErrorFormat(upb_Status* status, const char* fmt,
38                                    va_list args) UPB_PRINTF(2, 0);
39 
40 #ifdef __cplusplus
41 } /* extern "C" */
42 #endif
43 
44 #include "upb/port/undef.inc"
45 
46 #endif /* UPB_BASE_STATUS_H_ */
47