aboutsummaryrefslogtreecommitdiff
path: root/lib/portability.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2012-11-13 17:14:08 -0600
committerRob Landley <rob@landley.net>2012-11-13 17:14:08 -0600
commit7aa651a6a4496d848f86de9b1e6b3a003256a01f (patch)
tree6995fb4b7cc2e90a6706b0239ebaf95d9dbab530 /lib/portability.c
parent571b0706cce45716126776d0ad0f6ac65f4586e3 (diff)
downloadtoybox-7aa651a6a4496d848f86de9b1e6b3a003256a01f.tar.gz
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
The actual code should be the same afterward, this is just cosmetic refactoring.
Diffstat (limited to 'lib/portability.c')
-rw-r--r--lib/portability.c93
1 files changed, 45 insertions, 48 deletions
diff --git a/lib/portability.c b/lib/portability.c
index b1c448c8..d901a4b6 100644
--- a/lib/portability.c
+++ b/lib/portability.c
@@ -1,4 +1,3 @@
-/* vi: set sw=4 ts=4 :*/
/* portability.c - code to workaround the deficiencies of various platforms.
*
* Copyright 2012 Rob Landley <rob@landley.net>
@@ -10,66 +9,64 @@
#if defined(__APPLE__) || defined(__ANDROID__)
ssize_t getdelim(char **linep, size_t *np, int delim, FILE *stream)
{
- int ch;
- size_t new_len;
- ssize_t i = 0;
- char *line, *new_line;
+ int ch;
+ size_t new_len;
+ ssize_t i = 0;
+ char *line, *new_line;
- // Invalid input
- if (!linep || !np) {
- errno = EINVAL;
- return -1;
- }
+ // Invalid input
+ if (!linep || !np) {
+ errno = EINVAL;
+ return -1;
+ }
- if (*linep == NULL || *np == 0) {
- *np = 1024;
- *linep = calloc(1, *np);
- if (*linep == NULL)
- return -1;
- }
- line = *linep;
+ if (*linep == NULL || *np == 0) {
+ *np = 1024;
+ *linep = calloc(1, *np);
+ if (*linep == NULL) return -1;
+ }
+ line = *linep;
- while ((ch = getc(stream)) != EOF) {
- if (i > *np) {
- // Need more space
- new_len = *np + 1024;
- new_line = realloc(*linep, new_len);
- if (!new_line)
- return -1;
- *np = new_len;
- *linep = new_line;
- }
+ while ((ch = getc(stream)) != EOF) {
+ if (i > *np) {
+ // Need more space
+ new_len = *np + 1024;
+ new_line = realloc(*linep, new_len);
+ if (!new_line) return -1;
+ *np = new_len;
+ *linep = new_line;
+ }
- line[i] = ch;
- if (ch == delim)
- break;
- i += 1;
- }
+ line[i] = ch;
+ if (ch == delim) break;
+ i += 1;
+ }
- if (i > *np) {
- // Need more space
- new_len = i + 2;
- new_line = realloc(*linep, new_len);
- if (!new_line)
- return -1;
- *np = new_len;
- *linep = new_line;
- }
- line[i + 1] = '\0';
+ if (i > *np) {
+ // Need more space
+ new_len = i + 2;
+ new_line = realloc(*linep, new_len);
+ if (!new_line) return -1;
+ *np = new_len;
+ *linep = new_line;
+ }
+ line[i + 1] = '\0';
- return i > 0 ? i : -1;
+ return i > 0 ? i : -1;
}
-ssize_t getline(char **linep, size_t *np, FILE *stream) {
- return getdelim(linep, np, '\n', stream);
+ssize_t getline(char **linep, size_t *np, FILE *stream)
+{
+ return getdelim(linep, np, '\n', stream);
}
#endif
#if defined(__APPLE__)
extern char **environ;
-int clearenv(void) {
- *environ = NULL;
- return 0;
+int clearenv(void)
+{
+ *environ = NULL;
+ return 0;
}
#endif