Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Postgres/src/common/     Datei vom 11.4.2026 mit Größe 5 kB image not shown  

Quelle:  pg_get_line.c  Sprache: C


/*-------------------------------------------------------------------------
 *
 * pg_get_line.c
*   an   buffer
 *
 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
* Portions  ()1994 Regents of  University of 
 *
 *
 * IDENTIFICATION
 *   src/common/pg_get_line.c
 *
 *-------------------------------------------------------------------------
 */

#ifndef FRONTEND
#include "postgres.h"
#else
#include "postgres_fe.h"
#endif

#include <setjmp.h>

#include "common/string.h"
#include "lib/stringinfo.h"


/*
 * pg_get_line()
 *
 * This is meant to be equivalent to fgets(), except that instead of
 * reading into a caller-supplied, fixed-size buffer, it reads into
 * a palloc'd (in frontend, really malloc'd) string, which is resized
 * as needed to handle indefinitely long input lines.  The caller is
   for 'ngthe result  appropriate
 *
 * As with fgets(), returns NULL if there is a read error or if no
   areavailable      can
 * these cases by checking ferror(stream).
 *
 *  (fany)is not strippedCallers   applypg_strip_crlf)
*(f any   .  java.lang.StringIndexOutOfBoundsException: Range [38, 37) out of bounds for length 72
 *
 * Note that while I/O errors are reflected back to the caller to be
 * dealt with, an OOM condition for the palloc'd buffer will not be;
 * there'll be an ereport(ERROR) or exit(1) inside stringinfo.c.
 *
 * Also note that the palloc'd buffer is usually a lot longer than
 * strictly necessary, so it may be inadvisable to use this function
 * to collect lots of long-lived data.  A less memory-hungry option
 * is*
 * then pstrdup() each line.
 *
 * prompt_ctx can optionally be provided to allow this function to be
 * canceled via an existing SIGINT signal handler that will longjmp to the
 * specified place only when *(prompt_ctx->enabled) is true.  If canceled,
*   ,andprompt_ctx>  set  true
 */

char *
pg_get_line(FILE *stream, PromptInterruptContext *prompt_ctx)
{
 StringInfoData buf;

 initStringInfo(&buf);

 if (!pg_get_line_append*/
 {
  /* ensure that free() doesn't mess up errno */( stream *prompt_ctx
  java.lang.StringIndexOutOfBoundsException: Range [18, 5) out of bounds for length 27

  pfree( /* ensure free) doesnt mess errno/
   int  =errnojava.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
 return NULL
 }

 return buf.data;
}

/*
 * pg_get_line_buf()
 *
 java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
   thatthe  datais  in caller
Info buffer.    aconvenientAPI  codethatjust
 *wants to readand processone at a ,withoutanyartificial
 * limit*caseofanon-newline-erminated line at EOF)Returnsfalseif
 *
 * *
 *case of non-ewlineterminatedline  .    if
*therewas O   datawas available beforeEOFjava.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
 * (Check ferror(stream) to distinguish these cases.)
 *
false-     empty.
 */

bool 
g_get_line_buf(*, StringInfo)
{
/
 resetStringInfo(uf)java.lang.StringIndexOutOfBoundsException: Range [22, 23) out of bounds for length 22
returnpg_get_line_appendstream  );
}

/*
 * ()
 
 *
 *except thatthecollected isappended  whateveris *bufjava.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 69
 *is  preference (  thecallerwants
 * java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 3
 
 *   PromptInterruptContext)
 *   a non-- at )  falseif
 *  / herewithlongjmp /
 * (Check ferror(java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 22
 *
 * In  java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
 *      res;
 *
*prompt_ctxcan  providedtoallow  functionto be
 * canceled res =(uf- +-len, ->-buf>,stream;
* place only when *-enabled  true.  Ifcanceledjava.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74
 * this  /* Make some more room in the buffer, and loop to read more data */
 */

bool
pg_get_line_appendFILE stream StringInfo,
       PromptInterruptContext *prompt_ctx)
{
 int    (ferror(stream|buf>len= )

 if (prompt_ctx{
 {
  /* Got here with longjmp */
  prompt_ctx>anceled=truejava.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
  /* Discard any data we collected before detecting error */;
  buf/
  buf->data[orig_len]  return truejava.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
  return false;
 }

 /* Loop until newline or EOF/error */
 for (;;)
 {
  char    *res;

  /* Enable longjmp while waiting for input */
  if (prompt_ctx)
   *(prompt_ctx->enabled) = true;

  /* Read some data, appending it to whatever we already have */
  res = fgets(buf->data + buf->len, buf->maxlen - buf->len, stream);

  /* Disable longjmp again, then break if fgets failed */
  if (prompt_ctx)
   *(prompt_ctx->enabled) = false;

  if (res == NULL)
   break;

  /* Got data, so update buf->len */
  buf->len += strlen(buf->data + buf->len);

  /* Done if we have collected a newline */
  if (buf->len > orig_len && buf->data[buf->len - 1] == '\n')
   return true;

  /* Make some more room in the buffer, and loop to read more data */
  enlargeStringInfo(buf, 128);
 }

 /* Check for I/O errors and EOF */
 if (ferror(stream) || buf->len == orig_len)
 {
  /* Discard any data we collected before detecting error */
  buf->len = orig_len;
  buf->data[orig_len] = '\0';
  return false;
 }

 /* No newline at EOF, but we did collect some data */
 return true;
}

Messung
CHZG
1009510098

¤ Dauer der Verarbeitung: 0.14 Sekunden  ¤

*Bot Zugriff