D-Bus  1.11.14
dbus-string-private.h
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /* dbus-string-private.h String utility class (internal to D-Bus implementation)
3  *
4  * Copyright (C) 2002, 2003 Red Hat, Inc.
5  *
6  * Licensed under the Academic Free License version 2.1
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  */
23 
24 #ifndef DBUS_STRING_PRIVATE_H
25 #define DBUS_STRING_PRIVATE_H
26 
27 #include <dbus/dbus-internals.h>
28 #include <dbus/dbus-memory.h>
29 #include <dbus/dbus-types.h>
30 
31 #ifndef DBUS_CAN_USE_DBUS_STRING_PRIVATE
32 #error "Don't go including dbus-string-private.h for no good reason"
33 #endif
34 
36 
43 typedef struct
44 {
45  unsigned char *str;
46  int len;
47  int allocated;
48  unsigned int constant : 1;
49  unsigned int locked : 1;
50  unsigned int invalid : 1;
51  unsigned int align_offset : 3;
53 
54 _DBUS_STATIC_ASSERT (sizeof (DBusRealString) == sizeof (DBusString));
55 
69 #define _DBUS_STRING_MAX_LENGTH (_DBUS_INT32_MAX - _DBUS_STRING_ALLOCATION_PADDING)
70 
76 #define DBUS_GENERIC_STRING_PREAMBLE(real) \
77  do { \
78  (void) real; /* might be unused unless asserting */ \
79  _dbus_assert ((real) != NULL); \
80  _dbus_assert (!(real)->invalid); \
81  _dbus_assert ((real)->len >= 0); \
82  _dbus_assert ((real)->allocated >= 0); \
83  _dbus_assert ((real)->len <= ((real)->allocated - _DBUS_STRING_ALLOCATION_PADDING)); \
84  _dbus_assert ((real)->len <= _DBUS_STRING_MAX_LENGTH); \
85  } while (0)
86 
93 #define DBUS_STRING_PREAMBLE(str) DBusRealString *real = (DBusRealString*) str; \
94  DBUS_GENERIC_STRING_PREAMBLE (real); \
95  _dbus_assert (!(real)->constant); \
96  _dbus_assert (!(real)->locked)
97 
105 #define DBUS_LOCKED_STRING_PREAMBLE(str) DBusRealString *real = (DBusRealString*) str; \
106  DBUS_GENERIC_STRING_PREAMBLE (real); \
107  _dbus_assert (!(real)->constant)
108 
114 #define DBUS_CONST_STRING_PREAMBLE(str) const DBusRealString *real = (DBusRealString*) str; \
115  DBUS_GENERIC_STRING_PREAMBLE (real)
116 
121 #define DBUS_IS_ASCII_BLANK(c) ((c) == ' ' || (c) == '\t')
122 
127 #define DBUS_IS_ASCII_WHITE(c) ((c) == ' ' || (c) == '\t' || (c) == '\n' || (c) == '\r')
128 
132 
133 #endif /* DBUS_STRING_PRIVATE_H */
Internals of DBusString.
#define DBUS_BEGIN_DECLS
Macro used prior to declaring functions in the D-Bus header files.
unsigned int invalid
DBusString is invalid (e.g.
int len
Length without nul.
unsigned int locked
DBusString has been locked and can&#39;t be changed.
int allocated
Allocated size of data.
unsigned int align_offset
str - align_offset is the actual malloc block
unsigned char * str
String data, plus nul termination.
unsigned int constant
String data is not owned by DBusString.
#define DBUS_END_DECLS
Macro used after declaring functions in the D-Bus header files.