PostgreSQL Source Code: src/common/stringinfo.c Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18#ifndef FRONTEND

19

22

23#else

24

26

27#endif

28

30

31

32

33

34

35

36

37

38

39

40static inline void

42{

44

45 str->data = (char *) palloc(initsize);

46 str->maxlen = initsize;

48}

49

50

51

52

53

54

55

56

59{

61

63 return res;

64}

65

66

67

68

69

70

73{

75}

76

77

78

79

80

81

82

83

86{

88}

89

90

91

92

93

94

95

96void

98{

100}

101

102

103

104

105

106

107

108

109

110void

112{

114}

115

116

117

118

119

120

121

122

123

124

125void

127{

128

130

131 str->data[0] = '\0';

132 str->len = 0;

133 str->cursor = 0;

134}

135

136

137

138

139

140

141

142

143

144void

146{

147 int save_errno = errno;

148

149 for (;;)

150 {

151 va_list args;

152 int needed;

153

154

155 errno = save_errno;

156 va_start(args, fmt);

158 va_end(args);

159

160 if (needed == 0)

161 break;

162

163

165 }

166}

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186int

188{

189 int avail;

190 size_t nprinted;

191

193

194

195

196

197

198

199 avail = str->maxlen - str->len;

200 if (avail < 16)

201 return 32;

202

204

205 if (nprinted < (size_t) avail)

206 {

207

208 str->len += (int) nprinted;

209 return 0;

210 }

211

212

213 str->data[str->len] = '\0';

214

215

216

217

218

219

220 return (int) nprinted;

221}

222

223

224

225

226

227

228

229void

231{

233}

234

235

236

237

238

239

240

241void

243{

244

245 if (str->len + 1 >= str->maxlen)

247

248

249 str->data[str->len] = ch;

250 str->len++;

251 str->data[str->len] = '\0';

252}

253

254

255

256

257

258

259void

261{

262 if (count > 0)

263 {

264

266

267

268 memset(&str->data[str->len], ' ', count);

269 str->len += count;

270 str->data[str->len] = '\0';

271 }

272}

273

274

275

276

277

278

279

280void

282{

284

285

287

288

289 memcpy(str->data + str->len, data, datalen);

290 str->len += datalen;

291

292

293

294

295

296

297 str->data[str->len] = '\0';

298}

299

300

301

302

303

304

305

306void

308{

310

311

313

314

315 memcpy(str->data + str->len, data, datalen);

316 str->len += datalen;

317}

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336void

338{

339 int newlen;

340

341

343

344

345

346

347

348 if (needed < 0)

349 {

350#ifndef FRONTEND

351 elog(ERROR, "invalid string enlargement request size: %d", needed);

352#else

353 fprintf(stderr, "invalid string enlargement request size: %d\n", needed);

355#endif

356 }

358 {

359#ifndef FRONTEND

361 (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),

362 errmsg("string buffer exceeds maximum allowed length (%zu bytes)", MaxAllocSize),

363 errdetail("Cannot enlarge string buffer containing %d bytes by %d more bytes.",

364 str->len, needed)));

365#else

367 _("string buffer exceeds maximum allowed length (%zu bytes)\n\nCannot enlarge string buffer containing %d bytes by %d more bytes.\n"),

370#endif

371 }

372

373 needed += str->len + 1;

374

375

376

377 if (needed <= str->maxlen)

378 return;

379

380

381

382

383

384

385 newlen = 2 * str->maxlen;

386 while (needed > newlen)

387 newlen = 2 * newlen;

388

389

390

391

392

393

396

398

399 str->maxlen = newlen;

400}

401

402

403

404

405

406

407

408void

410{

411

413

416}

#define fprintf(file, fmt, msg)

int errdetail(const char *fmt,...)

int errcode(int sqlerrcode)

int errmsg(const char *fmt,...)

#define ereport(elevel,...)

Assert(PointerIsAligned(start, uint64))

void * repalloc(void *pointer, Size size)

void pfree(void *pointer)

size_t pvsnprintf(char *buf, size_t len, const char *fmt, va_list args)

int appendStringInfoVA(StringInfo str, const char *fmt, va_list args)

void destroyStringInfo(StringInfo str)

StringInfo makeStringInfo(void)

static void initStringInfoInternal(StringInfo str, int initsize)

void resetStringInfo(StringInfo str)

void appendStringInfo(StringInfo str, const char *fmt,...)

void enlargeStringInfo(StringInfo str, int needed)

StringInfo makeStringInfoExt(int initsize)

void appendBinaryStringInfoNT(StringInfo str, const void *data, int datalen)

void appendBinaryStringInfo(StringInfo str, const void *data, int datalen)

static StringInfo makeStringInfoInternal(int initsize)

void appendStringInfoSpaces(StringInfo str, int count)

void initStringInfoExt(StringInfo str, int initsize)

void appendStringInfoString(StringInfo str, const char *s)

void appendStringInfoChar(StringInfo str, char ch)

void initStringInfo(StringInfo str)

#define STRINGINFO_DEFAULT_SIZE

StringInfoData * StringInfo