Prusa MINI Firmware overview
getline.c File Reference
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
#include <errno.h>

Macros

#define SIZE_MAX   ((size_t) -1)
 
#define SSIZE_MAX   ((ssize_t) (SIZE_MAX / 2))
 
#define flockfile(x)   ((void)0)
 
#define funlockfile(x)   ((void)0)
 

Functions

ssize_t getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp)
 

Macro Definition Documentation

◆ SIZE_MAX

#define SIZE_MAX   ((size_t) -1)

getline.c — Based on...

getdelim.c — Implementation of replacement getdelim function. Copyright (C) 1994, 1996, 1997, 1998, 2001, 2003, 2005 Free Software Foundation, Inc.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

◆ SSIZE_MAX

#define SSIZE_MAX   ((ssize_t) (SIZE_MAX / 2))

◆ flockfile

#define flockfile (   x)    ((void)0)

◆ funlockfile

#define funlockfile (   x)    ((void)0)

Function Documentation

◆ getdelim()

ssize_t getdelim ( char **  lineptr,
size_t *  n,
int  delimiter,
FILE *  fp 
)
60  {
61  ssize_t result;
62  size_t cur_len = 0;
63 
64  if (lineptr == NULL || n == NULL || fp == NULL) {
65  errno = EINVAL;
66  return -1;
67  }
68 
69  flockfile (fp);
70 
71  if (*lineptr == NULL || *n == 0) {
72  *n = 120;
73  *lineptr = (char *) malloc(*n);
74  if (*lineptr == NULL) {
75  result = -1;
76  goto unlock_return;
77  }
78  }
79 
80  for (;;) {
81  int i;
82 
83  i = getc(fp);
84  if (i == EOF) {
85  result = -1;
86  break;
87  }
88 
89  /* Make enough space for len+1 (for final NUL) bytes. */
90  if (cur_len + 1 >= *n) {
91  size_t needed_max =
92  SSIZE_MAX < SIZE_MAX ? (size_t) SSIZE_MAX + 1 : SIZE_MAX;
93  size_t needed = 2 * *n + 1; /* Be generous. */
94  char *new_lineptr;
95 
96  if (needed_max < needed)
97  needed = needed_max;
98  if (cur_len + 1 >= needed) {
99  result = -1;
100  goto unlock_return;
101  }
102 
103  new_lineptr = (char *) realloc (*lineptr, needed);
104  if (new_lineptr == NULL) {
105  result = -1;
106  goto unlock_return;
107  }
108 
109  *lineptr = new_lineptr;
110  *n = needed;
111  }
112 
113  (*lineptr)[cur_len] = i;
114  cur_len++;
115 
116  if (i == delimiter) break;
117  }
118  (*lineptr)[cur_len] = '\0';
119  result = cur_len ? (int) cur_len : (int) result;
120 
121  unlock_return:
122  funlockfile(fp);
123  return result;
124 }
SSIZE_MAX
#define SSIZE_MAX
Definition: getline.c:42
funlockfile
#define funlockfile(x)
Definition: getline.c:50
i
uint8_t i
Definition: screen_test_graph.c:72
NULL
#define NULL
Definition: usbd_def.h:53
errno
int errno
flockfile
#define flockfile(x)
Definition: getline.c:46
createSpeedLookupTable.int
int
Definition: createSpeedLookupTable.py:15
SIZE_MAX
#define SIZE_MAX
Definition: getline.c:39
EOF
#define EOF
Definition: ff.h:286