libc: Cleanup SCC headers

Only leave the parts relevant to the Trusted Firmware.

Change-Id: I0444c16e402f6c1629211d03bf6cb32ca3dbcf59
Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
diff --git a/include/lib/libc/limits.h b/include/lib/libc/limits.h
index f6a4c7b..41bb658 100644
--- a/include/lib/libc/limits.h
+++ b/include/lib/libc/limits.h
@@ -8,12 +8,12 @@
  * All rights reserved.
  */
 
-#ifndef _LIMITS_H
-#define _LIMITS_H
+#ifndef LIMITS_H
+#define LIMITS_H
 
 #include <limits_.h>
 
 #define CHAR_BIT   8
 #define MB_LEN_MAX 1
 
-#endif
+#endif /* LIMITS_H */
diff --git a/include/lib/libc/stdarg.h b/include/lib/libc/stdarg.h
index 3c20788..e260b9b 100644
--- a/include/lib/libc/stdarg.h
+++ b/include/lib/libc/stdarg.h
@@ -3,9 +3,13 @@
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
+/*
+ * Portions copyright (c) 2018, ARM Limited and Contributors.
+ * All rights reserved.
+ */
 
-#ifndef _STDARG_H
-#define _STDARG_H
+#ifndef STDARG_H
+#define STDARG_H
 
 #define va_list __builtin_va_list
 #define va_start(ap, last) __builtin_va_start(ap, last)
@@ -13,4 +17,4 @@
 #define va_copy(to, from) __builtin_va_copy(to, from)
 #define va_arg(to, type) __builtin_va_arg(to, type)
 
-#endif
+#endif /* STDARG_H */
diff --git a/include/lib/libc/stddef.h b/include/lib/libc/stddef.h
index da884b3..c9957bd 100644
--- a/include/lib/libc/stddef.h
+++ b/include/lib/libc/stddef.h
@@ -8,8 +8,8 @@
  * All rights reserved.
  */
 
-#ifndef _STDDEF_H
-#define _STDDEF_H
+#ifndef STDDEF_H
+#define STDDEF_H
 
 #include <stddef_.h>
 
@@ -17,6 +17,6 @@
 #define NULL ((void *) 0)
 #endif
 
-#define offsetof(st, m) ((size_t)&(((st *)0)->m))
+#define offsetof(st, m) __builtin_offsetof(st, m)
 
-#endif
+#endif /* STDDEF_H */
diff --git a/include/lib/libc/stdint.h b/include/lib/libc/stdint.h
index 0b59a13..d44a973 100644
--- a/include/lib/libc/stdint.h
+++ b/include/lib/libc/stdint.h
@@ -8,9 +8,9 @@
  * All rights reserved.
  */
 
-#ifndef _STDINT_H_
-#define _STDINT_H_
+#ifndef STDINT_H
+#define STDINT_H
 
 #include <stdint_.h>
 
-#endif
+#endif /* STDINT_H */
diff --git a/include/lib/libc/stdio.h b/include/lib/libc/stdio.h
index 2e234ba..83fd18c 100644
--- a/include/lib/libc/stdio.h
+++ b/include/lib/libc/stdio.h
@@ -8,130 +8,28 @@
  * All rights reserved.
  */
 
-#ifndef _STDIO_H
-#define _STDIO_H
+#ifndef STDIO_H
+#define STDIO_H
 
 #include <stdio_.h>
 
-#ifndef FOPEN_MAX
-#define FOPEN_MAX 12
-#endif
-
 #ifndef NULL
 #define NULL ((void *) 0)
 #endif
 
 #define EOF            -1
-#define SEEK_CUR        0
-#define SEEK_END        1
-#define SEEK_SET        2
-
-
-#define _IOWRITE        (1 << 0)
-#define _IOREAD         (1 << 1)
-#define _IORW           (1 << 2)
-#define _IOEOF          (1 << 3)
-#define _IOERR          (1 << 4)
-#define _IOSTRG         (1 << 5)
-#define _IOTXT          (1 << 6)
-#define _IOFBF          (1 << 7)
-#define _IOLBF          (1 << 8)
-#define _IONBF          (1 << 9)
-#define _IOALLOC        (1 <<10)
 
-typedef struct {
-	int fd;        	        /* file descriptor */
-	unsigned char *buf;     /* pointer to i/o buffer */
-	unsigned char *rp;      /* read pointer */
-	unsigned char *wp;      /* write pointer */
-	unsigned char *lp;      /* write pointer used when line-buffering */
-	size_t len;             /* actual length of buffer */
-	unsigned short flags;
-	unsigned char unbuf[1];  /* tiny buffer for unbuffered io */
-} FILE;
+int printf(const char *fmt, ...);
+int snprintf(char *s, size_t n, const char *fmt, ...);
+int sprintf(char *s, const char *fmt, ...);
+int sscanf(const char *s, const char *fmt, ...);
 
-extern FILE __iob[FOPEN_MAX];
-
-#define	stdin	(&__iob[0])
-#define	stdout	(&__iob[1])
-#define	stderr	(&__iob[2])
-
-extern int remove(const char *filename);
-extern int rename(const char *old, const char *new);
-extern FILE *tmpfile(void);
-extern char *tmpnam(char *s);
-extern int fclose(FILE *fp);
-extern int fflush(FILE *fp);
-extern FILE *fopen(const char * restrict fname, const char * restrict mode);
-extern FILE *freopen(const char * restrict fname, const char * restrict mode,
-                     FILE * restrict fp);
-extern void setbuf(FILE * restrict fp, char * restrict buf);
-extern int setvbuf(FILE * restrict fp,
-                   char * restrict buf, int mode, size_t size);
-extern int fprintf(FILE * restrict fp, const char * restrict fmt, ...);
-extern int fscanf(FILE * restrict fp, const char * restrict fmt, ...);
-extern int printf(const char * restrict fmt, ...);
-extern int scanf(const char * restrict fmt, ...);
-extern int snprintf(char * restrict s,
-                    size_t n, const char * restrict fmt, ...);
-extern int sprintf(char * restrict s, const char * restrict fmt, ...);
-extern int sscanf(const char * restrict s, const char * restrict fmt, ...);
-
-#ifdef _STDARG_H
-extern int vfprintf(FILE * restrict fp,
-                    const char * restrict fmt, va_list arg);
-extern int vfscanf(FILE * restrict fp,
-                   const char * restrict fmt, va_list arg);
-extern int vprintf(const char * restrict fmt, va_list arg);
-extern int vscanf(const char * restrict fmt, va_list arg);
-extern int vsnprintf(char * restrict s, size_t n, const char * restrict fmt,
-                     va_list arg);
-extern int vsprintf(char * restrict s,
-                    const char * restrict fmt, va_list arg);
-extern int vsscanf(const char * restrict s,
-                   const char * restrict fmt, va_list arg);
+#ifdef STDARG_H
+int vsnprintf(char *s, size_t n, const char *fmt, va_list arg);
+int vsprintf(char *s, const char *fmt, va_list arg);
 #endif
 
-extern int fgetc(FILE *fp);
-extern char *fgets(char * restrict s, int n, FILE * restrict fp);
-extern int fputc(int c, FILE *fp);
-extern int fputs(const char * restrict s, FILE * restrict fp);
-extern int getc(FILE *fp);
-extern int getchar(void);
-extern char *gets(char *s);
-extern int putc(int c, FILE *fp);
-extern int putchar(int c);
-extern int puts(const char *s);
-extern int ungetc(int c, FILE *fp);
-extern size_t fread(void * restrict ptr, size_t size, size_t nmemb,
-             FILE * restrict fp);
-extern size_t fwrite(const void * restrict ptr, size_t size, size_t nmemb,
-              FILE * restrict fp);
-extern int fgetpos(FILE * restrict fp, fpos_t * restrict pos);
-extern int fseek(FILE *fp, long int offset, int whence);
-extern int fsetpos(FILE *fp, const fpos_t *pos);
-extern long int ftell(FILE *fp);
-extern void rewind(FILE *fp);
-extern void clearerr(FILE *fp);
-extern int feof(FILE *fp);
-extern int ferror(FILE *fp);
-extern void perror(const char *s);
+int putchar(int c);
+int puts(const char *s);
 
-extern int __getc(FILE *fp);
-extern int __putc(int, FILE *fp);
-
-#ifdef __USE_MACROS
-#ifdef __UNIX_FILES
-#define getc(fp)     ((fp)->rp >= (fp)->wp ?  __getc(fp) : *(fp)->rp++)
-#define putc(c, fp)  ((fp)->wp >= (fp)->rp ? __putc(c,fp) : (*(fp)->wp++ = c))
-#endif
-
-#define ferror(fp)          ((fp)->flags & _IOERR)
-#define feof(fp)            ((fp)->flags & _IOEOF)
-#define clearerr(fp)        (void) ((fp)->flags &= ~(_IOERR|_IOEOF))
-#define getchar()           getc(stdin)
-#define putchar(c)          putc((c), stdout)
-#define setbuf(fp, b)       (void) setvbuf(fp, b, b ? _IOFBF:_IONBF, BUFSIZ)
-#endif
-
-#endif
+#endif /* STDIO_H */
diff --git a/include/lib/libc/stdlib.h b/include/lib/libc/stdlib.h
index 9aff5d0..edd6265 100644
--- a/include/lib/libc/stdlib.h
+++ b/include/lib/libc/stdlib.h
@@ -8,8 +8,8 @@
  * All rights reserved.
  */
 
-#ifndef _STDLIB_H
-#define _STDLIB_H
+#ifndef STDLIB_H
+#define STDLIB_H
 
 #include <stdlib_.h>
 
@@ -17,73 +17,10 @@
 #define NULL ((void *) 0)
 #endif
 
-#define _ATEXIT_MAX 32
+#define _ATEXIT_MAX 1
 
-#define MB_CUR_MAX 1
-#define RAND_MAX 32767
-
-typedef struct {
-	int quot, rem;
-} div_t;
-
-typedef struct {
-	long quot, rem;
-} ldiv_t;
-
-typedef struct {
-	long long quot, rem;
-} lldiv_t;
-
-extern double atof(const char *nptr);
-extern int atoi(const char *nptr);
-extern long int atol(const char *nptr);
-extern long long int atoll(const char *nptr);
-extern double strtod(const char * restrict nptr, char ** restrict endptr);
-extern float strtof(const char * restrict nptr, char ** restrict endptr);
-extern long double strtold(const char * restrict nptr, char ** restrict endptr);
-extern long int strtol(const char * restrict nptr, char ** restrict endptr, int base);
-extern long long int strtoll(const char * restrict nptr, char ** restrict endptr,
-                             int base);
-extern unsigned long int strtoul(const char * restrict nptr, char ** restrict endptr,
-                                 int base);
-extern unsigned long long int strtoull(const char * restrict nptr,
-                                       char ** restrict endptr, int base);
-extern int rand(void);
-extern void srand(unsigned int seed);
-extern void *calloc(size_t nmemb, size_t size);
-extern void free(void *ptr);
-extern void *malloc(size_t size);
-extern void *realloc(void *ptr, size_t size);
 extern void abort(void);
 extern int atexit(void (*func)(void));
 extern void exit(int status);
-extern void _Exit(int status);
-extern char *getenv(const char *name);
-extern int system(const char *string);
-extern void *bsearch(const void *key, const void *base, size_t nmemb, size_t size,
-                     int (*compar)(const void *, const void *));
-extern void qsort(void *base, size_t nmemb, size_t size,
-                  int (*compar)(const void *, const void *));
-extern int abs(int j);
-extern long int labs(long int j);
-extern long long int llabs(long long int j);
-extern div_t div(int numer, int denom);
-extern ldiv_t ldiv(long int numer, long int denom);
-extern lldiv_t lldiv(long long int numer, long long int denom);
-extern int mblen(const char *s, size_t n);
-extern int mbtowc(wchar_t * restrict pwc, const char * restrict s, size_t n);
-extern int wctomb(char *s, wchar_t wchar);
-extern size_t mbstowcs(wchar_t * restrict pwcs, const char * restrict s, size_t n);
-extern size_t wcstombs(char * restrict s, const wchar_t * restrict pwcs, size_t n);
 
-#ifdef __USE_MACROS
-extern int __abs;
-extern long __labs;
-extern long long __llabs;
-
-#define abs(x)   (__abs = (x), (__abs) < 0 ? -__abs :  __abs)
-#define labs(x)  (__labs = (x), (__labs) < 0 ? -__labs :  __labs)
-#define llabs(x) (__llabs = (x), (__llabs) < 0 ? -__llabs :  __llabs)
-#endif
-
-#endif
+#endif /* STDLIB_H */
diff --git a/include/lib/libc/string.h b/include/lib/libc/string.h
index b872d03..050f643 100644
--- a/include/lib/libc/string.h
+++ b/include/lib/libc/string.h
@@ -8,8 +8,8 @@
  * All rights reserved.
  */
 
-#ifndef _STRING_H
-#define _STRING_H
+#ifndef STRING_H
+#define STRING_H
 
 #include <string_.h>
 
@@ -17,27 +17,15 @@
 #define NULL ((void *) 0)
 #endif
 
-extern void *memcpy(void * restrict s1, const void * restrict s2, size_t n);
-extern void *memmove(void *s1, const void *s2, size_t n);
-extern char *strcpy(char * restrict s1, const char * restrict s2);
-extern char *strncpy(char * restrict s1, const char * restrict s2, size_t n);
-extern char *strcat(char * restrict s1, const char * restrict s2);
-extern char *strncat(char * restrict s1, const char * restrict s2, size_t n);
-extern int memcmp(const void *s1, const void *s2, size_t n);
-extern int strcmp(const char *s1, const char *s2);
-extern int strcoll(const char *s1, const char *s2);
-extern int strncmp(const char *s1, const char *s2, size_t n);
-extern size_t strxfrm(char * restrict s1, const char * restrict s2, size_t n);
-extern void *memchr(const void *s, int c, size_t n);
-extern char *strchr(const char *s, int c);
-extern size_t strcspn(const char *s1, const char *s2);
-extern char *strpbrk(const char *s1, const char *s2);
-extern char *strrchr(const char *s, int c);
-extern size_t strspn(const char *s1, const char *s2);
-extern char *strstr(const char *s1, const char *s2);
-extern char *strtok(char * restrict s1, const char * restrict s2);
-extern void *memset(void *s, int c, size_t n);
-extern char *strerror(int errnum);
-extern size_t strlen(const char *s);
+void *memcpy(void *dst, const void *src, size_t len);
+void *memmove(void *dst, const void *src, size_t len);
+int memcmp(const void *s1, const void *s2, size_t len);
+int strcmp(const char *s1, const char *s2);
+int strncmp(const char *s1, const char *s2, size_t n);
+void *memchr(const void *src, int c, size_t len);
+char *strchr(const char *s, int c);
+void *memset(void *dst, int val, size_t count);
+size_t strlen(const char *s);
+size_t strnlen(const char *s, size_t maxlen);
 
-#endif
+#endif /* STRING_H */
diff --git a/include/lib/libc/time.h b/include/lib/libc/time.h
index 5a48684..71d3e7e 100644
--- a/include/lib/libc/time.h
+++ b/include/lib/libc/time.h
@@ -8,8 +8,8 @@
  * All rights reserved.
  */
 
-#ifndef _TIME_H
-#define _TIME_H
+#ifndef TIME_H
+#define TIME_H
 
 #include <time_.h>
 
@@ -17,32 +17,4 @@
 #define NULL ((void *) 0)
 #endif
 
-#define CLOCKS_PER_SEC 1000000
-
-typedef long int clock_t;
-
-struct tm {
-	int tm_sec;
-	int tm_min;
-	int tm_hour;
-	int tm_mday;
-	int tm_mon;
-	int tm_year;
-	int tm_wday;
-	int tm_yday;
-	int tm_isdst;
-};
-
-extern clock_t clock(void);
-extern double difftime(time_t time1, time_t time0);
-extern time_t mktime(struct tm *timeptr);
-extern time_t time(time_t *timer);
-extern char *asctime(const struct tm *timeptr);
-extern char *ctime(const time_t *timer);
-extern struct tm *gmtime(const time_t *timer);
-extern struct tm *localtime(const time_t *timer);
-extern size_t strftime(char * restrict s, size_t maxsize,
-                       const char * restrict format,
-                       const struct tm * restrict timeptr);
-
-#endif
+#endif /* TIME_H */