file
stringlengths
18
26
data
stringlengths
3
1.04M
the_stack_data/1056825.c
int i = 42;
the_stack_data/41472.c
# 1 "kernel/vfs/vfs_register.c" # 1 "/home/stone/Documents/Ali_IOT//" # 1 "<built-in>" # 1 "<command-line>" # 1 "kernel/vfs/vfs_register.c" # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/string.h" 1 3 # 10 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/string.h" 3 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/_ansi.h" 1 3 # 15 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/_ansi.h" 3 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/newlib.h" 1 3 # 14 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/newlib.h" 3 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/_newlib_version.h" 1 3 # 15 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/newlib.h" 2 3 # 16 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/_ansi.h" 2 3 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/config.h" 1 3 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/machine/ieeefp.h" 1 3 # 5 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/config.h" 2 3 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/features.h" 1 3 # 6 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/config.h" 2 3 # 17 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/_ansi.h" 2 3 # 11 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/string.h" 2 3 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/reent.h" 1 3 # 13 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/reent.h" 3 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/_ansi.h" 1 3 # 14 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/reent.h" 2 3 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/lib/gcc/arm-none-eabi/5.4.1/include/stddef.h" 1 3 4 # 149 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/lib/gcc/arm-none-eabi/5.4.1/include/stddef.h" 3 4 # 149 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/lib/gcc/arm-none-eabi/5.4.1/include/stddef.h" 3 4 typedef int ptrdiff_t; # 216 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/lib/gcc/arm-none-eabi/5.4.1/include/stddef.h" 3 4 typedef unsigned int size_t; # 328 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/lib/gcc/arm-none-eabi/5.4.1/include/stddef.h" 3 4 typedef unsigned int wchar_t; # 426 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/lib/gcc/arm-none-eabi/5.4.1/include/stddef.h" 3 4 typedef struct { long long __max_align_ll __attribute__((__aligned__(__alignof__(long long)))); long double __max_align_ld __attribute__((__aligned__(__alignof__(long double)))); } max_align_t; # 15 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/reent.h" 2 3 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_types.h" 1 3 # 24 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_types.h" 3 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/machine/_types.h" 1 3 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/machine/_default_types.h" 1 3 # 27 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/machine/_default_types.h" 3 typedef signed char __int8_t; typedef unsigned char __uint8_t; # 41 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/machine/_default_types.h" 3 typedef short int __int16_t; typedef short unsigned int __uint16_t; # 63 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/machine/_default_types.h" 3 typedef long int __int32_t; typedef long unsigned int __uint32_t; # 89 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/machine/_default_types.h" 3 typedef long long int __int64_t; typedef long long unsigned int __uint64_t; # 120 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/machine/_default_types.h" 3 typedef signed char __int_least8_t; typedef unsigned char __uint_least8_t; # 146 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/machine/_default_types.h" 3 typedef short int __int_least16_t; typedef short unsigned int __uint_least16_t; # 168 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/machine/_default_types.h" 3 typedef long int __int_least32_t; typedef long unsigned int __uint_least32_t; # 186 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/machine/_default_types.h" 3 typedef long long int __int_least64_t; typedef long long unsigned int __uint_least64_t; # 200 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/machine/_default_types.h" 3 typedef int __intptr_t; typedef unsigned int __uintptr_t; # 8 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/machine/_types.h" 2 3 # 25 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_types.h" 2 3 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/lock.h" 1 3 typedef int _LOCK_T; typedef int _LOCK_RECURSIVE_T; # 26 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_types.h" 2 3 typedef long __blkcnt_t; typedef long __blksize_t; typedef __uint64_t __fsblkcnt_t; typedef __uint32_t __fsfilcnt_t; typedef long _off_t; typedef int __pid_t; typedef short __dev_t; typedef unsigned short __uid_t; typedef unsigned short __gid_t; typedef __uint32_t __id_t; typedef unsigned short __ino_t; # 88 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_types.h" 3 typedef __uint32_t __mode_t; __extension__ typedef long long _off64_t; typedef _off_t __off_t; typedef _off64_t __loff_t; typedef long __key_t; typedef long _fpos_t; # 129 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_types.h" 3 typedef unsigned int __size_t; # 145 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_types.h" 3 typedef signed int _ssize_t; # 156 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_types.h" 3 typedef _ssize_t __ssize_t; # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/lib/gcc/arm-none-eabi/5.4.1/include/stddef.h" 1 3 4 # 357 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/lib/gcc/arm-none-eabi/5.4.1/include/stddef.h" 3 4 typedef unsigned int wint_t; # 160 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_types.h" 2 3 typedef struct { int __count; union { wint_t __wch; unsigned char __wchb[4]; } __value; } _mbstate_t; typedef _LOCK_RECURSIVE_T _flock_t; typedef void *_iconv_t; typedef unsigned long __clock_t; typedef long __time_t; typedef unsigned long __clockid_t; typedef unsigned long __timer_t; typedef __uint8_t __sa_family_t; typedef __uint32_t __socklen_t; typedef unsigned short __nlink_t; typedef long __suseconds_t; typedef unsigned long __useconds_t; typedef char * __va_list; # 16 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/reent.h" 2 3 typedef unsigned long __ULong; # 38 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/reent.h" 3 struct _reent; struct __locale_t; struct _Bigint { struct _Bigint *_next; int _k, _maxwds, _sign, _wds; __ULong _x[1]; }; 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; }; struct _on_exit_args { void * _fnargs[32]; void * _dso_handle[32]; __ULong _fntypes; __ULong _is_cxa; }; # 93 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/reent.h" 3 struct _atexit { struct _atexit *_next; int _ind; void (*_fns[32])(void); struct _on_exit_args _on_exit_args; }; # 117 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/reent.h" 3 struct __sbuf { unsigned char *_base; int _size; }; # 181 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/reent.h" 3 struct __sFILE { unsigned char *_p; int _r; int _w; short _flags; short _file; struct __sbuf _bf; int _lbfsize; void * _cookie; int (* _read) (struct _reent *, void *, char *, int) ; int (* _write) (struct _reent *, void *, const char *, int) ; _fpos_t (* _seek) (struct _reent *, void *, _fpos_t, int); int (* _close) (struct _reent *, void *); struct __sbuf _ub; unsigned char *_up; int _ur; unsigned char _ubuf[3]; unsigned char _nbuf[1]; struct __sbuf _lb; int _blksize; _off_t _offset; struct _reent *_data; _flock_t _lock; _mbstate_t _mbstate; int _flags2; }; # 287 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/reent.h" 3 typedef struct __sFILE __FILE; struct _glue { struct _glue *_next; int _niobs; __FILE *_iobs; }; # 319 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/reent.h" 3 struct _rand48 { unsigned short _seed[3]; unsigned short _mult[3]; unsigned short _add; }; # 569 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/reent.h" 3 struct _reent { int _errno; __FILE *_stdin, *_stdout, *_stderr; int _inc; char _emergency[25]; int _unspecified_locale_info; struct __locale_t *_locale; int __sdidinit; void (* __cleanup) (struct _reent *); struct _Bigint *_result; int _result_k; struct _Bigint *_p5s; struct _Bigint **_freelist; int _cvtlen; char *_cvtbuf; union { struct { unsigned int _unused_rand; char * _strtok_last; char _asctime_buf[26]; struct __tm _localtime_buf; int _gamma_signgam; __extension__ unsigned long long _rand_next; struct _rand48 _r48; _mbstate_t _mblen_state; _mbstate_t _mbtowc_state; _mbstate_t _wctomb_state; char _l64a_buf[8]; char _signal_buf[24]; int _getdate_err; _mbstate_t _mbrlen_state; _mbstate_t _mbrtowc_state; _mbstate_t _mbsrtowcs_state; _mbstate_t _wcrtomb_state; _mbstate_t _wcsrtombs_state; int _h_errno; } _reent; struct { unsigned char * _nextf[30]; unsigned int _nmalloc[30]; } _unused; } _new; struct _atexit *_atexit; struct _atexit _atexit0; void (**(_sig_func))(int); struct _glue __sglue; __FILE __sf[3]; }; # 766 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/reent.h" 3 extern struct _reent *_impure_ptr ; extern struct _reent *const _global_impure_ptr ; void _reclaim_reent (struct _reent *); # 12 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/string.h" 2 3 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/cdefs.h" 1 3 # 45 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/cdefs.h" 3 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/lib/gcc/arm-none-eabi/5.4.1/include/stddef.h" 1 3 4 # 46 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/cdefs.h" 2 3 # 13 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/string.h" 2 3 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/lib/gcc/arm-none-eabi/5.4.1/include/stddef.h" 1 3 4 # 18 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/string.h" 2 3 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_locale.h" 1 3 # 9 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_locale.h" 3 struct __locale_t; typedef struct __locale_t *locale_t; # 21 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/string.h" 2 3 void * memchr (const void *, int, size_t); int memcmp (const void *, const void *, size_t); void * memcpy (void * restrict, const void * restrict, size_t); void * memmove (void *, const void *, size_t); void * memset (void *, int, size_t); char *strcat (char *restrict, const char *restrict); char *strchr (const char *, int); int strcmp (const char *, const char *); int strcoll (const char *, const char *); char *strcpy (char *restrict, const char *restrict); size_t strcspn (const char *, const char *); char *strerror (int); size_t strlen (const char *); char *strncat (char *restrict, const char *restrict, size_t); int strncmp (const char *, const char *, size_t); char *strncpy (char *restrict, const char *restrict, size_t); char *strpbrk (const char *, const char *); char *strrchr (const char *, int); size_t strspn (const char *, const char *); char *strstr (const char *, const char *); char *strtok (char *restrict, const char *restrict); size_t strxfrm (char *restrict, const char *restrict, size_t); int strcoll_l (const char *, const char *, locale_t); char *strerror_l (int, locale_t); size_t strxfrm_l (char *restrict, const char *restrict, size_t, locale_t); char *strtok_r (char *restrict, const char *restrict, char **restrict); int bcmp (const void *, const void *, size_t); void bcopy (const void *, void *, size_t); void bzero (void *, size_t); void explicit_bzero (void *, size_t); int timingsafe_bcmp (const void *, const void *, size_t); int timingsafe_memcmp (const void *, const void *, size_t); int ffs (int); char *index (const char *, int); void * memccpy (void * restrict, const void * restrict, int, size_t); # 86 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/string.h" 3 char *rindex (const char *, int); char *stpcpy (char *restrict, const char *restrict); char *stpncpy (char *restrict, const char *restrict, size_t); int strcasecmp (const char *, const char *); char *strdup (const char *); char *_strdup_r (struct _reent *, const char *); char *strndup (const char *, size_t); char *_strndup_r (struct _reent *, const char *, size_t); # 121 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/string.h" 3 int strerror_r (int, char *, size_t) __asm__ ("" "__xpg_strerror_r") ; char * _strerror_r (struct _reent *, int, int, int *); size_t strlcat (char *, const char *, size_t); size_t strlcpy (char *, const char *, size_t); int strncasecmp (const char *, const char *, size_t); size_t strnlen (const char *, size_t); char *strsep (char **, const char *); char *strlwr (char *); char *strupr (char *); char *strsignal (int __signo); # 192 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/string.h" 3 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/string.h" 1 3 # 193 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/string.h" 2 3 # 6 "kernel/vfs/vfs_register.c" 2 # 1 "./include/aos/aos.h" 1 # 12 "./include/aos/aos.h" # 1 "./include/aos/types.h" 1 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/lib/gcc/arm-none-eabi/5.4.1/include/stdint.h" 1 3 4 # 9 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/lib/gcc/arm-none-eabi/5.4.1/include/stdint.h" 3 4 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/stdint.h" 1 3 4 # 13 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/stdint.h" 3 4 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_intsup.h" 1 3 4 # 49 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_intsup.h" 3 4 # 201 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_intsup.h" 3 4 # 14 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/stdint.h" 2 3 4 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_stdint.h" 1 3 4 # 20 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_stdint.h" 3 4 typedef __int8_t int8_t ; typedef __uint8_t uint8_t ; typedef __int16_t int16_t ; typedef __uint16_t uint16_t ; typedef __int32_t int32_t ; typedef __uint32_t uint32_t ; typedef __int64_t int64_t ; typedef __uint64_t uint64_t ; typedef __intptr_t intptr_t; typedef __uintptr_t uintptr_t; # 15 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/stdint.h" 2 3 4 typedef __int_least8_t int_least8_t; typedef __uint_least8_t uint_least8_t; typedef __int_least16_t int_least16_t; typedef __uint_least16_t uint_least16_t; typedef __int_least32_t int_least32_t; typedef __uint_least32_t uint_least32_t; typedef __int_least64_t int_least64_t; typedef __uint_least64_t uint_least64_t; # 51 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/stdint.h" 3 4 typedef int int_fast8_t; typedef unsigned int uint_fast8_t; # 61 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/stdint.h" 3 4 typedef int int_fast16_t; typedef unsigned int uint_fast16_t; # 71 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/stdint.h" 3 4 typedef int int_fast32_t; typedef unsigned int uint_fast32_t; # 81 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/stdint.h" 3 4 typedef long long int int_fast64_t; typedef long long unsigned int uint_fast64_t; # 130 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/stdint.h" 3 4 typedef long long int intmax_t; # 139 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/stdint.h" 3 4 typedef long long unsigned int uintmax_t; # 10 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/lib/gcc/arm-none-eabi/5.4.1/include/stdint.h" 2 3 4 # 9 "./include/aos/types.h" 2 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/lib/gcc/arm-none-eabi/5.4.1/include/stddef.h" 1 3 4 # 10 "./include/aos/types.h" 2 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/unistd.h" 1 3 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/unistd.h" 1 3 # 12 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/unistd.h" 3 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/types.h" 1 3 # 28 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/types.h" 3 typedef __uint8_t u_int8_t; typedef __uint16_t u_int16_t; typedef __uint32_t u_int32_t; typedef __uint64_t u_int64_t; typedef int register_t; # 62 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/types.h" 3 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/lib/gcc/arm-none-eabi/5.4.1/include/stddef.h" 1 3 4 # 63 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/types.h" 2 3 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/machine/endian.h" 1 3 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/machine/_endian.h" 1 3 # 7 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/machine/endian.h" 2 3 # 68 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/types.h" 2 3 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/select.h" 1 3 # 25 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/select.h" 3 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_sigset.h" 1 3 # 41 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_sigset.h" 3 typedef unsigned long __sigset_t; # 26 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/select.h" 2 3 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_timeval.h" 1 3 # 35 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_timeval.h" 3 typedef __suseconds_t suseconds_t; typedef long time_t; # 52 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_timeval.h" 3 struct timeval { time_t tv_sec; suseconds_t tv_usec; }; # 27 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/select.h" 2 3 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/timespec.h" 1 3 # 38 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/timespec.h" 3 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_timespec.h" 1 3 # 45 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_timespec.h" 3 struct timespec { time_t tv_sec; long tv_nsec; }; # 39 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/timespec.h" 2 3 # 58 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/timespec.h" 3 struct itimerspec { struct timespec it_interval; struct timespec it_value; }; # 28 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/select.h" 2 3 typedef __sigset_t sigset_t; # 45 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/select.h" 3 typedef unsigned long fd_mask; typedef struct _types_fd_set { fd_mask fds_bits[(((64)+(((sizeof (fd_mask) * 8))-1))/((sizeof (fd_mask) * 8)))]; } _types_fd_set; # 71 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/select.h" 3 int select (int __n, _types_fd_set *__readfds, _types_fd_set *__writefds, _types_fd_set *__exceptfds, struct timeval *__timeout) ; int pselect (int __n, _types_fd_set *__readfds, _types_fd_set *__writefds, _types_fd_set *__exceptfds, const struct timespec *__timeout, const sigset_t *__set) ; # 69 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/types.h" 2 3 typedef __uint32_t in_addr_t; typedef __uint16_t in_port_t; # 87 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/types.h" 3 typedef unsigned char u_char; typedef unsigned short u_short; typedef unsigned int u_int; typedef unsigned long u_long; typedef unsigned short ushort; typedef unsigned int uint; typedef unsigned long ulong; typedef __blkcnt_t blkcnt_t; typedef __blksize_t blksize_t; typedef unsigned long clock_t; # 135 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/types.h" 3 typedef long daddr_t; typedef char * caddr_t; typedef __fsblkcnt_t fsblkcnt_t; typedef __fsfilcnt_t fsfilcnt_t; typedef __id_t id_t; typedef __ino_t ino_t; # 173 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/types.h" 3 typedef __off_t off_t; typedef __dev_t dev_t; typedef __uid_t uid_t; typedef __gid_t gid_t; typedef __pid_t pid_t; typedef __key_t key_t; typedef _ssize_t ssize_t; typedef __mode_t mode_t; typedef __nlink_t nlink_t; typedef __clockid_t clockid_t; typedef __timer_t timer_t; typedef __useconds_t useconds_t; # 236 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/types.h" 3 typedef __int64_t sbintime_t; # 465 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/types.h" 3 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/machine/types.h" 1 3 # 466 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/types.h" 2 3 # 13 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/unistd.h" 2 3 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/lib/gcc/arm-none-eabi/5.4.1/include/stddef.h" 1 3 4 # 15 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/unistd.h" 2 3 extern char **environ; void _exit (int __status ) __attribute__ ((__noreturn__)); int access (const char *__path, int __amode ); unsigned alarm (unsigned __secs ); int chdir (const char *__path ); int chmod (const char *__path, mode_t __mode ); int chown (const char *__path, uid_t __owner, gid_t __group ); int chroot (const char *__path ); int close (int __fildes ); size_t confstr (int __name, char *__buf, size_t __len); # 44 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/unistd.h" 3 int daemon (int nochdir, int noclose); int dup (int __fildes ); int dup2 (int __fildes, int __fildes2 ); # 56 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/unistd.h" 3 void endusershell (void); int execl (const char *__path, const char *, ... ); int execle (const char *__path, const char *, ... ); int execlp (const char *__file, const char *, ... ); int execlpe (const char *__file, const char *, ... ); int execv (const char *__path, char * const __argv[] ); int execve (const char *__path, char * const __argv[], char * const __envp[] ); int execvp (const char *__file, char * const __argv[] ); int faccessat (int __dirfd, const char *__path, int __mode, int __flags); int fchdir (int __fildes); int fchmod (int __fildes, mode_t __mode ); int fchown (int __fildes, uid_t __owner, gid_t __group ); int fchownat (int __dirfd, const char *__path, uid_t __owner, gid_t __group, int __flags); int fexecve (int __fd, char * const __argv[], char * const __envp[] ); pid_t fork (void ); long fpathconf (int __fd, int __name ); int fsync (int __fd); int fdatasync (int __fd); char * getcwd (char *__buf, size_t __size ); int getdomainname (char *__name, size_t __len); int getentropy (void *, size_t); gid_t getegid (void ); uid_t geteuid (void ); gid_t getgid (void ); int getgroups (int __gidsetsize, gid_t __grouplist[] ); long gethostid (void); char * getlogin (void ); char * getpass (const char *__prompt); int getpagesize (void); int getpeereid (int, uid_t *, gid_t *); pid_t getpgid (pid_t); pid_t getpgrp (void ); pid_t getpid (void ); pid_t getppid (void ); pid_t getsid (pid_t); uid_t getuid (void ); char * getusershell (void); char * getwd (char *__buf ); int iruserok (unsigned long raddr, int superuser, const char *ruser, const char *luser); int isatty (int __fildes ); int issetugid (void); int lchown (const char *__path, uid_t __owner, gid_t __group ); int link (const char *__path1, const char *__path2 ); int linkat (int __dirfd1, const char *__path1, int __dirfd2, const char *__path2, int __flags ); int nice (int __nice_value ); off_t lseek (int __fildes, off_t __offset, int __whence ); int lockf (int __fd, int __cmd, off_t __len); long pathconf (const char *__path, int __name ); int pause (void ); int pthread_atfork (void (*)(void), void (*)(void), void (*)(void)); int pipe (int __fildes[2] ); ssize_t pread (int __fd, void *__buf, size_t __nbytes, off_t __offset); ssize_t pwrite (int __fd, const void *__buf, size_t __nbytes, off_t __offset); int read (int __fd, void *__buf, size_t __nbyte ); int rresvport (int *__alport); int revoke (char *__path); int rmdir (const char *__path ); int ruserok (const char *rhost, int superuser, const char *ruser, const char *luser); void * sbrk (ptrdiff_t __incr); int setegid (gid_t __gid ); int seteuid (uid_t __uid ); int setgid (gid_t __gid ); int setgroups (int ngroups, const gid_t *grouplist ); int sethostname (const char *, size_t); int setpgid (pid_t __pid, pid_t __pgid ); int setpgrp (void ); int setregid (gid_t __rgid, gid_t __egid); int setreuid (uid_t __ruid, uid_t __euid); pid_t setsid (void ); int setuid (uid_t __uid ); void setusershell (void); unsigned sleep (unsigned int __seconds ); void swab (const void *restrict, void *restrict, ssize_t); long sysconf (int __name ); pid_t tcgetpgrp (int __fildes ); int tcsetpgrp (int __fildes, pid_t __pgrp_id ); char * ttyname (int __fildes ); int ttyname_r (int, char *, size_t); int unlink (const char *__path ); int usleep (useconds_t __useconds); int vhangup (void ); int write (int __fd, const void *__buf, size_t __nbyte ); extern char *optarg; extern int optind, opterr, optopt; int getopt(int, char * const [], const char *); extern int optreset; pid_t vfork (void ); # 257 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/unistd.h" 3 int ftruncate (int __fd, off_t __length); int truncate (const char *, off_t __length); # 278 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/unistd.h" 3 ssize_t readlink (const char *restrict __path, char *restrict __buf, size_t __buflen) ; int symlink (const char *__name1, const char *__name2); ssize_t readlinkat (int __dirfd1, const char *restrict __path, char *restrict __buf, size_t __buflen) ; int symlinkat (const char *, int, const char *); int unlinkat (int, const char *, int); # 5 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/unistd.h" 2 3 # 11 "./include/aos/types.h" 2 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/fcntl.h" 1 3 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/fcntl.h" 1 3 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_default_fcntl.h" 1 3 # 163 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_default_fcntl.h" 3 struct flock { short l_type; short l_whence; long l_start; long l_len; short l_pid; short l_xxx; }; struct eflock { short l_type; short l_whence; long l_start; long l_len; short l_pid; short l_xxx; long l_rpid; long l_rsys; }; # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/stat.h" 1 3 # 9 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/stat.h" 3 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/time.h" 1 3 # 16 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/time.h" 3 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/lib/gcc/arm-none-eabi/5.4.1/include/stddef.h" 1 3 4 # 17 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/time.h" 2 3 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/machine/time.h" 1 3 # 20 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/time.h" 2 3 # 35 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/time.h" 3 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; }; clock_t clock (void); double difftime (time_t _time2, time_t _time1); time_t mktime (struct tm *_timeptr); time_t time (time_t *_timer); char *asctime (const struct tm *_tblock); char *ctime (const time_t *_time); struct tm *gmtime (const time_t *_timer); struct tm *localtime (const time_t *_timer); size_t strftime (char *restrict _s, size_t _maxsize, const char *restrict _fmt, const struct tm *restrict _t) ; extern size_t strftime_l (char *restrict _s, size_t _maxsize, const char *restrict _fmt, const struct tm *restrict _t, locale_t _l); char *asctime_r (const struct tm *restrict, char *restrict) ; char *ctime_r (const time_t *, char *); struct tm *gmtime_r (const time_t *restrict, struct tm *restrict) ; struct tm *localtime_r (const time_t *restrict, struct tm *restrict) ; # 101 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/time.h" 3 void tzset (void); void _tzset_r (struct _reent *); typedef struct __tzrule_struct { char ch; int m; int n; int d; int s; time_t change; long offset; } __tzrule_type; typedef struct __tzinfo_struct { int __tznorth; int __tzyear; __tzrule_type __tzrule[2]; } __tzinfo_type; __tzinfo_type *__gettzinfo (void); # 154 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/time.h" 3 extern long _timezone; extern int _daylight; extern char *_tzname[2]; # 10 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/stat.h" 2 3 # 27 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/stat.h" 3 struct stat { dev_t st_dev; ino_t st_ino; mode_t st_mode; nlink_t st_nlink; uid_t st_uid; gid_t st_gid; dev_t st_rdev; off_t st_size; # 50 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/stat.h" 3 time_t st_atime; long st_spare1; time_t st_mtime; long st_spare2; time_t st_ctime; long st_spare3; blksize_t st_blksize; blkcnt_t st_blocks; long st_spare4[2]; }; # 147 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/stat.h" 3 int chmod ( const char *__path, mode_t __mode ); int fchmod (int __fd, mode_t __mode); int fstat ( int __fd, struct stat *__sbuf ); int mkdir ( const char *_path, mode_t __mode ); int mkfifo ( const char *__path, mode_t __mode ); int stat ( const char *restrict __path, struct stat *restrict __sbuf ); mode_t umask ( mode_t __mask ); int fchmodat (int, const char *, mode_t, int); int fstatat (int, const char *restrict , struct stat *restrict, int); int mkdirat (int, const char *, mode_t); int mkfifoat (int, const char *, mode_t); int mknodat (int, const char *, mode_t, dev_t); int utimensat (int, const char *, const struct timespec *, int); int futimens (int, const struct timespec *); # 189 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_default_fcntl.h" 2 3 extern int open (const char *, int, ...); extern int openat (int, const char *, int, ...); extern int creat (const char *, mode_t); extern int fcntl (int, int, ...); extern int flock (int, int); # 5 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/fcntl.h" 2 3 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/fcntl.h" 2 3 # 12 "./include/aos/types.h" 2 # 17 "./include/aos/types.h" struct pollfd { int fd; short events; short revents; }; # 13 "./include/aos/aos.h" 2 # 1 "./include/aos/cli.h" 1 # 18 "./include/aos/cli.h" typedef void (*FUNCPTR)(void); struct cli_command { const char *name; const char *help; void (*function)(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); }; struct cli_st { int initialized; int echo_disabled; const struct cli_command *commands[64]; unsigned int num_commands; unsigned int bp; char inbuf[256]; char outbuf[2048]; int his_idx; int his_cur; char history[5][256]; }; # 137 "./include/aos/cli.h" # 1 "././platform/arch/arm/armv5/./gcc/k_types.h" 1 # 14 "././platform/arch/arm/armv5/./gcc/k_types.h" typedef char name_t; typedef uint32_t sem_count_t; typedef uint32_t cpu_stack_t; typedef uint32_t hr_timer_t; typedef uint32_t lr_timer_t; typedef uint32_t mutex_nested_t; typedef uint8_t suspend_nested_t; typedef uint64_t ctx_switch_t; typedef uint32_t cpu_cpsr_t; # 138 "./include/aos/cli.h" 2 static inline int aos_cli_register_command(const struct cli_command *command) { return 0; } static inline int aos_cli_unregister_command(const struct cli_command *command) { return 0; } static inline int aos_cli_register_commands(const struct cli_command *commands, int num_commands) { return 0; } static inline int aos_cli_unregister_commands(const struct cli_command *commands, int num_commands) { return 0; } static inline int aos_cli_init(void) { return 0; } static inline int aos_cli_stop(void) { return 0; } # 14 "./include/aos/aos.h" 2 # 1 "./include/aos/cloud.h" 1 enum { CLOUD_CONNECTED, CLOUD_DISCONNECTED, GET_DEVICE_STATUS, SET_DEVICE_STATUS, GET_DEVICE_RAWDATA, SET_DEVICE_RAWDATA, UPGRADE_DEVICE, CANCEL_UPGRADE_DEVICE, GET_SUB_DEVICE_STATUS, SET_SUB_DEVICE_STATUS, MAX_EVENT_TYPE, }; typedef void (*aos_cloud_cb_t)(int event, const char *json_buffer); # 32 "./include/aos/cloud.h" int aos_cloud_register_callback(int cb_type, aos_cloud_cb_t cb); # 44 "./include/aos/cloud.h" int aos_cloud_report(const char *method, const char *json_buffer, void (*done_cb)(void *), void *arg); void aos_cloud_trigger(int cb_type, const char *json_buffer); void aos_cloud_register_backend(int (*report)(const char *method, const char *json_buffer)); # 15 "./include/aos/aos.h" 2 # 1 "./include/aos/debug.h" 1 # 16 "./include/aos/aos.h" 2 # 1 "./include/aos/kernel.h" 1 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/lib/gcc/arm-none-eabi/5.4.1/include/stddef.h" 1 3 4 # 9 "./include/aos/kernel.h" 2 # 19 "./include/aos/kernel.h" typedef struct { void *hdl; } aos_hdl_t; typedef aos_hdl_t aos_task_t; typedef aos_hdl_t aos_mutex_t; typedef aos_hdl_t aos_sem_t; typedef aos_hdl_t aos_queue_t; typedef aos_hdl_t aos_timer_t; typedef aos_hdl_t aos_work_t; typedef aos_hdl_t aos_event_t; typedef struct { void *hdl; void *stk; } aos_workqueue_t; typedef unsigned int aos_task_key_t; void aos_reboot(void); int aos_get_hz(void); const char *aos_version_get(void); # 67 "./include/aos/kernel.h" int aos_task_new(const char *name, void (*fn)(void *), void *arg, int stack_size); # 82 "./include/aos/kernel.h" int aos_task_new_ext(aos_task_t *task, const char *name, void (*fn)(void *), void *arg, int stack_size, int prio); void aos_task_exit(int code); const char *aos_task_name(void); # 106 "./include/aos/kernel.h" int aos_task_key_create(aos_task_key_t *key); void aos_task_key_delete(aos_task_key_t key); # 123 "./include/aos/kernel.h" int aos_task_setspecific(aos_task_key_t key, void *vp); void *aos_task_getspecific(aos_task_key_t key); # 140 "./include/aos/kernel.h" int aos_mutex_new(aos_mutex_t *mutex); void aos_mutex_free(aos_mutex_t *mutex); # 158 "./include/aos/kernel.h" int aos_mutex_lock(aos_mutex_t *mutex, unsigned int timeout); # 167 "./include/aos/kernel.h" int aos_mutex_unlock(aos_mutex_t *mutex); # 176 "./include/aos/kernel.h" int aos_mutex_is_valid(aos_mutex_t *mutex); # 187 "./include/aos/kernel.h" int aos_sem_new(aos_sem_t *sem, int count); void aos_sem_free(aos_sem_t *sem); # 205 "./include/aos/kernel.h" int aos_sem_wait(aos_sem_t *sem, unsigned int timeout); void aos_sem_signal(aos_sem_t *sem); # 221 "./include/aos/kernel.h" int aos_sem_is_valid(aos_sem_t *sem); void aos_sem_signal_all(aos_sem_t *sem); # 240 "./include/aos/kernel.h" int aos_event_new(aos_event_t *event, unsigned int flags); # 251 "./include/aos/kernel.h" void aos_event_free(aos_event_t *event); # 272 "./include/aos/kernel.h" int aos_event_get(aos_event_t *event, unsigned int flags, unsigned char opt, unsigned int *actl_flags, unsigned int timeout); # 286 "./include/aos/kernel.h" int aos_event_set(aos_event_t *event, unsigned int flags, unsigned char opt); # 299 "./include/aos/kernel.h" int aos_queue_new(aos_queue_t *queue, void *buf, unsigned int size, int max_msg); void aos_queue_free(aos_queue_t *queue); # 317 "./include/aos/kernel.h" int aos_queue_send(aos_queue_t *queue, void *msg, unsigned int size); # 329 "./include/aos/kernel.h" int aos_queue_recv(aos_queue_t *queue, unsigned int ms, void *msg, unsigned int *size); # 338 "./include/aos/kernel.h" int aos_queue_is_valid(aos_queue_t *queue); # 347 "./include/aos/kernel.h" void *aos_queue_buf_ptr(aos_queue_t *queue); # 360 "./include/aos/kernel.h" int aos_timer_new(aos_timer_t *timer, void (*fn)(void *, void *), void *arg, int ms, int repeat); # 375 "./include/aos/kernel.h" int aos_timer_new_ext(aos_timer_t *timer, void (*fn)(void *, void *), void *arg, int ms, int repeat, unsigned char auto_run); void aos_timer_free(aos_timer_t *timer); # 392 "./include/aos/kernel.h" int aos_timer_start(aos_timer_t *timer); # 401 "./include/aos/kernel.h" int aos_timer_stop(aos_timer_t *timer); # 411 "./include/aos/kernel.h" int aos_timer_change(aos_timer_t *timer, int ms); # 422 "./include/aos/kernel.h" int aos_workqueue_create(aos_workqueue_t *workqueue, int pri, int stack_size); # 434 "./include/aos/kernel.h" int aos_work_init(aos_work_t *work, void (*fn)(void *), void *arg, int dly); void aos_work_destroy(aos_work_t *work); # 451 "./include/aos/kernel.h" int aos_work_run(aos_workqueue_t *workqueue, aos_work_t *work); # 460 "./include/aos/kernel.h" int aos_work_sched(aos_work_t *work); # 469 "./include/aos/kernel.h" int aos_work_cancel(aos_work_t *work); # 479 "./include/aos/kernel.h" void *aos_realloc(void *mem, unsigned int size); # 488 "./include/aos/kernel.h" void *aos_malloc(unsigned int size); # 497 "./include/aos/kernel.h" void *aos_zalloc(unsigned int size); void aos_alloc_trace(void *addr, size_t allocator); void aos_free(void *mem); long long aos_now(void); long long aos_now_ms(void); void aos_msleep(int ms); void aos_init(void); void aos_start(void); # 17 "./include/aos/aos.h" 2 # 1 "./include/aos/kv.h" 1 # 25 "./include/aos/kv.h" int aos_kv_set(const char *key, const void *value, int len, int sync); # 40 "./include/aos/kv.h" int aos_kv_get(const char *key, void *buffer, int *buffer_len); # 49 "./include/aos/kv.h" int aos_kv_del(const char *key); # 18 "./include/aos/aos.h" 2 # 1 "./include/aos/list.h" 1 # 31 "./include/aos/list.h" typedef struct dlist_s { struct dlist_s *prev; struct dlist_s *next; } dlist_t; static inline void __dlist_add(dlist_t *node, dlist_t *prev, dlist_t *next) { node->next = next; node->prev = prev; prev->next = node; next->prev = node; } # 56 "./include/aos/list.h" static inline void dlist_add(dlist_t *node, dlist_t *queue) { __dlist_add(node, queue, queue->next); } static inline void dlist_add_tail(dlist_t *node, dlist_t *queue) { __dlist_add(node, queue->prev, queue); } static inline void dlist_del(dlist_t *node) { dlist_t *prev = node->prev; dlist_t *next = node->next; prev->next = next; next->prev = prev; } static inline void dlist_init(dlist_t *node) { node->next = node->prev = node; } static inline void INIT_AOS_DLIST_HEAD(dlist_t *list) { list->next = list; list->prev = list; } static inline int dlist_empty(const dlist_t *head) { return head->next == head; } # 185 "./include/aos/list.h" static inline int dlist_entry_number(dlist_t *queue) { int num; dlist_t *cur = queue; for (num=0;cur->next != queue;cur=cur->next, num++) ; return num; } # 213 "./include/aos/list.h" typedef struct slist_s { struct slist_s *next; } slist_t; static inline void slist_add(slist_t *node, slist_t *head) { node->next = head->next; head->next = node; } static inline void slist_add_tail(slist_t *node, slist_t *head) { while (head->next) { head = head->next; } slist_add(node, head); } static inline void slist_del(slist_t *node, slist_t *head) { while (head->next) { if (head->next == node) { head->next = node->next; break; } head = head->next; } } static inline int slist_empty(const slist_t *head) { return !head->next; } static inline void slist_init(slist_t *head) { head->next = 0; } # 322 "./include/aos/list.h" static inline int slist_entry_number(slist_t *queue) { int num; slist_t *cur = queue; for (num=0;cur->next;cur=cur->next, num++) ; return num; } # 19 "./include/aos/aos.h" 2 # 1 "./include/aos/log.h" 1 # 12 "./include/aos/log.h" # 1 "./include/aos/internal/log_impl.h" 1 # 12 "./include/aos/internal/log_impl.h" extern unsigned int aos_log_level; static inline unsigned int aos_log_get_level(void) { return aos_log_level; } enum log_level_bit { AOS_LL_V_NONE_BIT = -1, AOS_LL_V_FATAL_BIT, AOS_LL_V_ERROR_BIT, AOS_LL_V_WARN_BIT, AOS_LL_V_INFO_BIT, AOS_LL_V_DEBUG_BIT, AOS_LL_V_MAX_BIT }; # 52 "./include/aos/internal/log_impl.h" extern int csp_printf(const char *fmt, ...); # 80 "./include/aos/internal/log_impl.h" int csp_printf(const char *fmt, ...); # 13 "./include/aos/log.h" 2 typedef enum { AOS_LL_NONE, AOS_LL_FATAL, AOS_LL_ERROR, AOS_LL_WARN, AOS_LL_INFO, AOS_LL_DEBUG, } aos_log_level_t; extern unsigned int aos_log_level; static inline int aos_get_log_level(void) { return aos_log_level; } void aos_set_log_level(aos_log_level_t log_level); # 20 "./include/aos/aos.h" 2 # 1 "./include/aos/vfs.h" 1 # 16 "./include/aos/vfs.h" typedef struct { int d_ino; uint8_t d_type; char d_name[]; } aos_dirent_t; typedef struct { int dd_vfs_fd; int dd_rsv; } aos_dir_t; # 35 "./include/aos/vfs.h" int aos_open(const char *path, int flags); # 44 "./include/aos/vfs.h" int aos_close(int fd); # 55 "./include/aos/vfs.h" ssize_t aos_read(int fd, void *buf, size_t nbytes); # 66 "./include/aos/vfs.h" ssize_t aos_write(int fd, const void *buf, size_t nbytes); # 77 "./include/aos/vfs.h" int aos_ioctl(int fd, int cmd, unsigned long arg); # 89 "./include/aos/vfs.h" int aos_poll(struct pollfd *fds, int nfds, int timeout); # 100 "./include/aos/vfs.h" int aos_fcntl(int fd, int cmd, int val); # 114 "./include/aos/vfs.h" off_t aos_lseek(int fd, off_t offset, int whence); # 123 "./include/aos/vfs.h" int aos_sync(int fd); # 133 "./include/aos/vfs.h" int aos_stat(const char *path, struct stat *st); # 142 "./include/aos/vfs.h" int aos_unlink(const char *path); # 152 "./include/aos/vfs.h" int aos_rename(const char *oldpath, const char *newpath); # 161 "./include/aos/vfs.h" aos_dir_t *aos_opendir(const char *path); # 170 "./include/aos/vfs.h" int aos_closedir(aos_dir_t *dir); # 179 "./include/aos/vfs.h" aos_dirent_t *aos_readdir(aos_dir_t *dir); # 188 "./include/aos/vfs.h" int aos_mkdir(const char *path); # 21 "./include/aos/aos.h" 2 # 1 "./include/aos/version.h" 1 # 13 "./include/aos/version.h" const char *aos_get_product_model(void); const char *aos_get_os_version(void); const char *aos_get_kernel_version(void); const char *aos_get_app_version(void); const char *aos_get_device_name(void); void dump_sys_info(void); # 22 "./include/aos/aos.h" 2 # 1 "./include/aos/yloop.h" 1 # 14 "./include/aos/yloop.h" # 1 "./include/aos/internal/event_type_code.h" 1 # 15 "./include/aos/yloop.h" 2 # 65 "./include/aos/yloop.h" typedef struct { uint32_t time; uint16_t type; uint16_t code; unsigned long value; unsigned long extra; } input_event_t; typedef void (*aos_event_cb)(input_event_t *event, void *private_data); typedef void (*aos_call_t)(void *arg); typedef void (*aos_poll_call_t)(int fd, void *arg); # 94 "./include/aos/yloop.h" int aos_register_event_filter(uint16_t type, aos_event_cb cb, void *priv); # 105 "./include/aos/yloop.h" int aos_unregister_event_filter(uint16_t type, aos_event_cb cb, void *priv); # 116 "./include/aos/yloop.h" int aos_post_event(uint16_t type, uint16_t code, unsigned long value); # 127 "./include/aos/yloop.h" int aos_poll_read_fd(int fd, aos_poll_call_t action, void *param); # 136 "./include/aos/yloop.h" void aos_cancel_poll_read_fd(int fd, aos_poll_call_t action, void *param); # 147 "./include/aos/yloop.h" int aos_post_delayed_action(int ms, aos_call_t action, void *arg); # 156 "./include/aos/yloop.h" void aos_cancel_delayed_action(int ms, aos_call_t action, void *arg); # 169 "./include/aos/yloop.h" int aos_schedule_call(aos_call_t action, void *arg); typedef void *aos_loop_t; aos_loop_t aos_loop_init(void); aos_loop_t aos_current_loop(void); void aos_loop_run(void); void aos_loop_exit(void); void aos_loop_destroy(void); # 211 "./include/aos/yloop.h" int aos_loop_schedule_call(aos_loop_t *loop, aos_call_t action, void *arg); # 224 "./include/aos/yloop.h" void *aos_loop_schedule_work(int ms, aos_call_t action, void *arg1, aos_call_t fini_cb, void *arg2); # 234 "./include/aos/yloop.h" void aos_cancel_work(void *work, aos_call_t action, void *arg1); # 23 "./include/aos/aos.h" 2 # 1 "./include/aos/errno.h" 1 # 13 "./include/aos/errno.h" # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/errno.h" 1 3 # 5 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/errno.h" 3 typedef int error_t; # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/errno.h" 1 3 # 15 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/errno.h" 3 extern int *__errno (void); extern const char * const _sys_errlist[]; extern int _sys_nerr; # 10 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/errno.h" 2 3 # 14 "./include/aos/errno.h" 2 # 24 "./include/aos/aos.h" 2 # 1 "./include/aos/init.h" 1 # 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/lib/gcc/arm-none-eabi/5.4.1/include/stdbool.h" 1 3 4 # 9 "./include/aos/init.h" 2 # 11 "./include/aos/init.h" typedef struct { int argc; char **argv; # 15 "./include/aos/init.h" 3 4 _Bool # 15 "./include/aos/init.h" cli_enable; } kinit_t; extern int aos_kernel_init(kinit_t *kinit); # 25 "./include/aos/aos.h" 2 # 8 "kernel/vfs/vfs_register.c" 2 # 1 "./kernel/vfs/include/vfs_conf.h" 1 # 9 "kernel/vfs/vfs_register.c" 2 # 1 "./kernel/vfs/include/vfs_err.h" 1 # 10 "kernel/vfs/vfs_register.c" 2 # 1 "./kernel/vfs/include/vfs_register.h" 1 # 1 "./kernel/vfs/include/vfs_inode.h" 1 # 17 "./kernel/vfs/include/vfs_inode.h" enum { VFS_TYPE_NOT_INIT, VFS_TYPE_CHAR_DEV, VFS_TYPE_BLOCK_DEV, VFS_TYPE_FS_DEV }; # 43 "./kernel/vfs/include/vfs_inode.h" typedef const struct file_ops file_ops_t; typedef const struct fs_ops fs_ops_t; union inode_ops_t { const file_ops_t *i_ops; const fs_ops_t *i_fops; }; typedef struct { union inode_ops_t ops; void *i_arg; char *i_name; int i_flags; uint8_t type; uint8_t refs; aos_mutex_t mutex; } inode_t; typedef struct { inode_t *node; void *f_arg; size_t offset; } file_t; struct pollfd; typedef void (*poll_notify_t)(struct pollfd *fd, void *arg); struct file_ops { int (*open) (inode_t *node, file_t *fp); int (*close) (file_t *fp); ssize_t (*read) (file_t *fp, void *buf, size_t nbytes); ssize_t (*write) (file_t *fp, const void *buf, size_t nbytes); int (*ioctl) (file_t *fp, int cmd, unsigned long arg); int (*poll) (file_t *fp, # 77 "./kernel/vfs/include/vfs_inode.h" 3 4 _Bool # 77 "./kernel/vfs/include/vfs_inode.h" flag, poll_notify_t notify, struct pollfd *fd, void *arg); }; struct fs_ops { int (*open) (file_t *fp, const char *path, int flags); int (*close) (file_t *fp); ssize_t (*read) (file_t *fp, char *buf, size_t len); ssize_t (*write) (file_t *fp, const char *buf, size_t len); off_t (*lseek) (file_t *fp, off_t off, int whence); int (*sync) (file_t *fp); int (*stat) (file_t *fp, const char *path, struct stat *st); int (*unlink) (file_t *fp, const char *path); int (*rename) (file_t *fp, const char *oldpath, const char *newpath); aos_dir_t *(*opendir) (file_t *fp, const char *path); aos_dirent_t *(*readdir) (file_t *fp, aos_dir_t *dir); int (*closedir) (file_t *fp, aos_dir_t *dir); int (*mkdir) (file_t *fp, const char *path); int (*ioctl) (file_t *fp, int cmd, unsigned long arg); }; int inode_init(void); int inode_alloc(void); int inode_del(inode_t *node); inode_t *inode_open(const char *path); int inode_ptr_get(int fd, inode_t **node); int inode_avail_count(void); void inode_ref(inode_t *); void inode_unref(inode_t *); int inode_busy(inode_t *); int inode_reserve(const char *path, inode_t **inode); int inode_release(const char *path); # 9 "./kernel/vfs/include/vfs_register.h" 2 int aos_register_driver(const char *path, file_ops_t *fops, void *arg); int aos_unregister_driver(const char *path); int aos_register_fs(const char *path, fs_ops_t *fops, void *arg); int aos_unregister_fs(const char *path); # 11 "kernel/vfs/vfs_register.c" 2 extern aos_mutex_t g_vfs_mutex; int aos_register_driver(const char *path, file_ops_t *ops, void *arg) { inode_t *node = # 16 "kernel/vfs/vfs_register.c" 3 4 ((void *)0) # 16 "kernel/vfs/vfs_register.c" ; int err, ret; err = aos_mutex_lock(&g_vfs_mutex, 0xffffffffu); if (err != 0) { return err; } ret = inode_reserve(path, &node); if (ret == 0u) { do { (node)->type = (VFS_TYPE_CHAR_DEV); } while(0); node->ops.i_ops = ops; node->i_arg = arg; ret = aos_mutex_new(&node->mutex); } err = aos_mutex_unlock(&g_vfs_mutex); if (err != 0) { if (node->i_name != # 39 "kernel/vfs/vfs_register.c" 3 4 ((void *)0) # 39 "kernel/vfs/vfs_register.c" ) { aos_free(node->i_name); } memset(node, 0, sizeof(inode_t)); return err; } return ret; } int aos_unregister_driver(const char *path) { int err, ret; err = aos_mutex_lock(&g_vfs_mutex, 0xffffffffu); if (err != 0) { return err; } ret = inode_release(path); err = aos_mutex_unlock(&g_vfs_mutex); if (err != 0) { return err; } return ret; } int aos_register_fs(const char *path, fs_ops_t *ops, void *arg) { inode_t *node = # 71 "kernel/vfs/vfs_register.c" 3 4 ((void *)0) # 71 "kernel/vfs/vfs_register.c" ; int err, ret; err = aos_mutex_lock(&g_vfs_mutex, 0xffffffffu); if (err != 0) { return err; } ret = inode_reserve(path, &node); if (ret == 0u) { do { (node)->type = (VFS_TYPE_FS_DEV); } while(0); node->ops.i_fops = ops; node->i_arg = arg; } err = aos_mutex_unlock(&g_vfs_mutex ); if (err != 0) { if (node->i_name != # 89 "kernel/vfs/vfs_register.c" 3 4 ((void *)0) # 89 "kernel/vfs/vfs_register.c" ) { aos_free(node->i_name); } memset(node, 0, sizeof(inode_t)); return err; } return ret; } int aos_unregister_fs(const char *path) { int err, ret; err = aos_mutex_lock(&g_vfs_mutex, 0xffffffffu); if (err != 0) { return err; } ret = inode_release(path); err = aos_mutex_unlock(&g_vfs_mutex); if (err != 0) { return err; } return ret; }
the_stack_data/126704097.c
#include <stdio.h> #include <stdlib.h> #define N 10 float *remontee(float A[N][N], float B[N], int n) { /******Implement the solution here******/ /***************************************/ float *X; int i,j; float s; X = malloc(sizeof(float)*n); X[n-1] = B[n-1]/A[n-1][n-1]; for(i= n-2 ; i>-1 ; i--) { s = 0 ; for (j=i+1 ; j<n;j++) { s = s + A[i][j]*X[j]; } X[i] = (B[i] - s)/A[i][i]; } /***************************************/ return X; } float *gauss(float A[N][N] ,float B[N], int n) { /******Implement the Gaussian elimination******/ /**********************************************/ int i,j,k; float s; float *x; for (k = 0 ; i<n+1 ; k++) { for(i = k+1 ; i<n ; i++) { s = A[i][k] /A[k][k]; //printf(" \n %f",s); for (j = 0 ; j <n ; j++) { A[i][j] = A[i][j] - s * A[k][j] ; // printf(" \n %f A[%d][%d] ",A[i][j],i,j); } B[i] = B[i] - s * B[k]; } } /**********************************************/ /*Resolve the system using the back substitution method*/ /*You can use your solution of the exercice 1-b*/ x = remontee(A, B, n); return(x); } int main() { float A[N][N], B[N]; float *x; int n; printf("Enter the size of the matrix: "); scanf("%d", &n); /* Filling the matrix A */ printf("Filling the matrix A\n"); for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { printf("A[%d][%d] = ", i, j); scanf("%f", &A[i][j]); } } /* Filling the vector B*/ printf("Filling the matrix B\n"); for (int i = 0; i < n; i++) { printf("B[%d] = ", i); scanf("%f", &B[i]); } /* The calculation of the result */ x = gauss(A, B, n); /* Printing the results */ printf("\nThe resulting vector: ["); for (int i = 0; i < n; i++) printf("%f%c", x[i], ",]"[i == n - 1]); }
the_stack_data/187644155.c
int b[3] = {4, 5, 6}; int j = 1, k; void main() { k = --b[j]; print("k 4"); printid(k); }
the_stack_data/66334.c
#include <stdio.h> void bfs(int[20][20],int,int[20],int); int count=0,visitedorder[20],i,visited[20],queue[20]; void main() { int n,a[20][20],j,source; printf("Enter number of vertices: \n"); scanf("%d",&n); printf("Enter the adjacency matrix: \n"); for(i=1; i<=n; i++) for(j=1; j<=n; j++) scanf("%d",&a[i][j]); for(i=1; i<=n; i++) visited[i]=0; printf("Enter the source node \n"); scanf("%d",&source); bfs(a,n,visited,source); for(i=1; i<=n; i++) if(visited[i]==0) bfs(a,n,visited,i); for(i=1; i<=n; i++) visitedorder[visited[i]]=i; printf("BFS Traversal \n"); for(i=1; i<=n; i++) printf("%c \t",64+visitedorder[i]); } void bfs(int a[20][20],int n,int visitedorder[20],int source) { int f,r,u,v; f=0; r=-1; count++; visited[source]=count; queue[++r]=source; while(f<=r) { u=queue[f++]; for(v=1; v<=n; v++) { if(a[u][v]==1&&visited[v]==0) { queue[++r]=v; count++; visited[v]=count; } } } }
the_stack_data/95449801.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_putendl_fd.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: yaziz <[email protected]> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/10/18 19:33:36 by yaziz #+# #+# */ /* Updated: 2019/10/25 04:12:14 by yaziz ### ########.fr */ /* */ /* ************************************************************************** */ #include <unistd.h> void ft_putendl_fd(char *s, int fd) { int i; if (s == NULL) return ; i = 0; while (s[i]) i++; write(fd, s, i); write(fd, "\n", 1); }
the_stack_data/120809.c
/* * Copyright (C) 2007-2021 Intel Corporation. * SPDX-License-Identifier: MIT */ /* * this application calls a user-written function that contains a bad code pattern. */ #include <stdio.h> #include <stdlib.h> #include <string.h> extern void move_ip(); int main(int argc, char* argv[]) { char* buffer; buffer = (char*)malloc(64); strcpy(buffer, "abc"); printf("%s\n", buffer); move_ip(); printf("returned from move_ip.\n"); free(buffer); return 0; }
the_stack_data/165765191.c
/* ** mouse:~ppr/src/z_install_end/id.c ** Copyright 1995--2003, Trinity College Computing Center. ** Written by David Chappell. ** ** Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are met: ** ** * Redistributions of source code must retain the above copyright notice, ** this list of conditions and the following disclaimer. ** ** * Redistributions in binary form must reproduce the above copyright ** notice, this list of conditions and the following disclaimer in the ** documentation and/or other materials provided with the distribution. ** ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN ** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ** POSSIBILITY OF SUCH DAMAGE. ** ** Last modified 5 March 2003. */ /* ** We have this partial implementation of id because some implementations ** don't have the features which we need for these scripts. */ #include <stdio.h> #include <unistd.h> #include <sys/types.h> #include <pwd.h> #include <grp.h> extern char *optarg; extern int optind; int main(int argc, char *argv[]) { int opt_n=0, opt_u=0, opt_g=0, opt_r=0; int c; uid_t uid; gid_t gid; while((c = getopt(argc, argv, "nugGr")) != -1) { switch(c) { case 'u': opt_u = 1; break; case 'g': opt_g = 1; break; case 'n': opt_n = 1; break; case 'G': fprintf(stderr, "%s: not implemented\n", argv[0]); return 1; case 'r': opt_r = 1; break; default: return 1; } } if(opt_u && opt_g) { fprintf(stderr, "%s: can't print both\n", argv[0]); return 1; } if(opt_r) { uid = getuid(); gid = getgid(); } else { uid = geteuid(); gid = getegid(); } if(opt_n) { if(opt_u) { struct passwd *pw; if((pw = getpwuid(uid))) { printf("%s\n", pw->pw_name); return 0; } } else if(opt_g) { struct group *gr; if((gr = getgrgid(gid))) { printf("%s\n", gr->gr_name); return 0; } } } if(opt_u) { printf("%ld\n", (long)uid); return 0; } if(opt_g) { printf("%ld\n", (long)gid); return 0; } { struct passwd *pw = getpwuid(uid); struct group *gr = getgrgid(gid); printf("uid=%ld(%s) gid=%ld(%s)\n", (long)uid, pw?pw->pw_name:"?", (long)gid, gr?gr->gr_name:"?"); return 0; } } /* end of file */
the_stack_data/407712.c
/* $OpenBSD$ */ /*- * Copyright (c) 2003 Mike Barcroft <[email protected]> * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD: src/tools/regression/lib/libc/gen/test-fpclassify.c,v 1.3 2003/03/27 05:32:28 das Exp $ */ #include <assert.h> #include <float.h> #include <math.h> #include <stdlib.h> int main(void) { assert(fpclassify((float)0) == FP_ZERO); assert(fpclassify((float)-0.0) == FP_ZERO); assert(fpclassify((float)1) == FP_NORMAL); assert(fpclassify((float)1000) == FP_NORMAL); #ifndef __alpha__ assert(fpclassify(0x1.2p-150f) == FP_SUBNORMAL); #endif /* !__alpha__ */ assert(fpclassify(HUGE_VALF) == FP_INFINITE); assert(fpclassify((float)HUGE_VAL) == FP_INFINITE); assert(fpclassify((float)HUGE_VALL) == FP_INFINITE); assert(fpclassify(NAN) == FP_NAN); assert(fpclassify((double)0) == FP_ZERO); assert(fpclassify((double)-0) == FP_ZERO); assert(fpclassify((double)1) == FP_NORMAL); assert(fpclassify((double)1000) == FP_NORMAL); #ifndef __alpha__ assert(fpclassify(0x1.2p-1075) == FP_SUBNORMAL); #endif /* !__alpha__ */ assert(fpclassify(HUGE_VAL) == FP_INFINITE); assert(fpclassify((double)HUGE_VALF) == FP_INFINITE); assert(fpclassify((double)HUGE_VALL) == FP_INFINITE); assert(fpclassify((double)NAN) == FP_NAN); assert(fpclassify((long double)0) == FP_ZERO); assert(fpclassify((long double)-0.0) == FP_ZERO); assert(fpclassify((long double)1) == FP_NORMAL); assert(fpclassify((long double)1000) == FP_NORMAL); #if (LDBL_MANT_DIG > DBL_MANT_DIG) assert(fpclassify(0x1.2p-16383L) == FP_SUBNORMAL); #endif /* (LDBL_MANT_DIG > DBL_MANT_DIG) */ assert(fpclassify(HUGE_VALL) == FP_INFINITE); assert(fpclassify((long double)HUGE_VALF) == FP_INFINITE); assert(fpclassify((long double)HUGE_VAL) == FP_INFINITE); assert(fpclassify((long double)NAN) == FP_NAN); return (0); }
the_stack_data/86672.c
#define WEAK __attribute__ ((__used__, weak)) #define ALIAS(f) __attribute__ ((__used__, weak, alias (#f))) WEAK void IntDefaultHandler(void); WEAK void DAC_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void M0APP_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void DMA_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void FLASH_EEPROM_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void ETH_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void SDIO_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void LCD_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void USB0_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void USB1_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void SCT_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void RIT_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void TIMER0_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void TIMER1_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void TIMER2_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void TIMER3_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void MCPWM_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void ADC0_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void I2C0_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void SPI_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void I2C1_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void ADC1_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void SSP0_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void SSP1_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void UART0_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void UART1_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void UART2_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void UART3_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void I2S0_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void I2S1_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void SPIFI_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void SGPIO_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void GPIO0_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void GPIO1_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void GPIO2_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void GPIO3_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void GPIO4_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void GPIO5_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void GPIO6_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void GPIO7_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void GINT0_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void GINT1_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void EVRT_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void CAN1_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void ADCHS_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void ATIMER_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void RTC_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void WDT_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void M0SUB_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void CAN0_IRQHandler(void) ALIAS(IntDefaultHandler); WEAK void QEI_IRQHandler(void) ALIAS(IntDefaultHandler); // Chip Level - LPC43 (M4) __attribute__ ((used,section(".isr_vendor_vector"))) void (* const g_pfnVendorVectors[])(void) = { DAC_IRQHandler, // 16 M0APP_IRQHandler, // 17 CortexM4/M0 (LPC43XX ONLY) DMA_IRQHandler, // 18 0, // 19 FLASH_EEPROM_IRQHandler, // 20 ORed flash Bank A, flash Bank B, EEPROM interrupts ETH_IRQHandler, // 21 SDIO_IRQHandler, // 22 LCD_IRQHandler, // 23 USB0_IRQHandler, // 24 USB1_IRQHandler, // 25 SCT_IRQHandler, // 26 RIT_IRQHandler, // 27 TIMER0_IRQHandler, // 28 TIMER1_IRQHandler, // 29 TIMER2_IRQHandler, // 30 TIMER3_IRQHandler, // 31 MCPWM_IRQHandler, // 32 ADC0_IRQHandler, // 33 I2C0_IRQHandler, // 34 I2C1_IRQHandler, // 35 SPI_IRQHandler, // 36 ADC1_IRQHandler, // 37 SSP0_IRQHandler, // 38 SSP1_IRQHandler, // 39 UART0_IRQHandler, // 40 UART1_IRQHandler, // 41 UART2_IRQHandler, // 42 UART3_IRQHandler, // 43 I2S0_IRQHandler, // 44 I2S1_IRQHandler, // 45 SPIFI_IRQHandler, // 46 SGPIO_IRQHandler, // 47 GPIO0_IRQHandler, // 48 GPIO1_IRQHandler, // 49 GPIO2_IRQHandler, // 50 GPIO3_IRQHandler, // 51 GPIO4_IRQHandler, // 52 GPIO5_IRQHandler, // 53 GPIO6_IRQHandler, // 54 GPIO7_IRQHandler, // 55 GINT0_IRQHandler, // 56 GINT1_IRQHandler, // 57 EVRT_IRQHandler, // 58 CAN1_IRQHandler, // 59 0, // 60 ADCHS_IRQHandler, // 61 ADCHS combined interrupt ATIMER_IRQHandler, // 62 RTC_IRQHandler, // 63 0, // 64 WDT_IRQHandler, // 65 M0SUB_IRQHandler, // 66 CAN0_IRQHandler, // 67 QEI_IRQHandler, // 68 }; __attribute__ ((section(".after_vectors"))) void IntDefaultHandler(void) { while (1) { } }
the_stack_data/154829124.c
/* * * Copyright (c) 2005-2021 Imperas Software Ltd., www.imperas.com * * The contents of this file are provided under the Software License * Agreement that you accepted before downloading this file. * * This source forms part of the Software and can be used for educational, * training, and demonstration purposes but cannot be used for derivative * works except in cases where the derivative works require OVP technology * to run. * * For open source models released under licenses that you can use for * derivative works, please visit www.OVPworld.org or www.imperas.com * for the location of the open source models. * */ #include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { printf("Hello World\n"); return 0; }
the_stack_data/843053.c
// PureLISP.c: fpLISP in C // // (C) 2021 TAKIZAWA Yozo // This code is Licensed under CC0. // https://creativecommons.org/publicdomain/zero/1.0/ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdint.h> #include <ctype.h> #define SSTR_MAX 4096 typedef uintptr_t value_t; enum NODE_TAG { NODE_STRG, NODE_CONS }; typedef struct _node_t_ { value_t value; enum NODE_TAG tag; } _node_t, *node_t; // Basic functions for conscel operations: // cons, car, cdr, eq, atom node_t node(value_t value, enum NODE_TAG tag) { node_t n = (node_t)malloc(sizeof(_node_t)); n->value = value; n->tag = tag; return (n); } typedef struct _cons_t_ { node_t x, y; } _cons_t, *cons_t; #define str_to_node(s) (node((value_t)(s), NODE_STRG)) #define node_to_str(s) ((char *)(s->value)) #define n_strg(s) (s->tag == NODE_STRG) #define n_cons(s) (s->tag == NODE_CONS) int eq(node_t s1, node_t s2); #define atom(s) (eq(s, NULL) || n_strg(s)) node_t car(node_t s) { if (s == NULL || atom(s)) return NULL; else return ((cons_t)(s->value))->x; } node_t cdr(node_t s) { if (s == NULL || atom(s)) return NULL; else return ((cons_t)(s->value))->y; } node_t cons(node_t x, node_t y) { cons_t c = (cons_t)malloc(sizeof(_cons_t)); c->x = x; c->y = y; node_t n = node((value_t)c, NODE_CONS); return (n); } int eq(node_t s1, node_t s2) { if (s1 == NULL && s2 == NULL) return (1); else if (s1 == NULL && (!n_cons(s2) && !strcmp(node_to_str(s2), "nil"))) return (1); else if (s2 == NULL && (!n_cons(s1) && !strcmp(node_to_str(s1), "nil"))) return (1); else if (s1 == NULL || s2 == NULL) return (0); else if (n_cons(s1) || n_cons(s2)) return (0); else return (!strcmp(node_to_str(s1), node_to_str(s2))); } // S-expression input: fp_lex and fp_syn int fp_lex(const char *s, char* sl[]) { char sf[SSTR_MAX * 3]; int i, j = 0; for (i = 0; i < strlen(s); i++) { switch (s[i]) { case '(': case ')': case '\'': sf[j++] = ' '; sf[j++] = s[i]; sf[j++] = ' '; break; case '\n': j++; break; default: sf[j++] = s[i]; } } sf[j] = '\0'; char *t; int len = 0; for (t = strtok(sf, " "); t != NULL; t = strtok(NULL, " ")) sl[len++] = t; sl[len] = NULL; return (len); } node_t fp_syn(char *s[], int *pos) { char *t = s[*pos]; *pos = *pos - 1; if (t[0] == ')') { if (*pos <= 0) return NULL; node_t r = NULL; while (s[*pos][0] != '(') { if (s[*pos][0] == '.') { *pos = *pos - 1; r = cons(fp_syn(s, pos), car(r)); } else r = cons(fp_syn(s, pos), r); } *pos = *pos - 1; if (*pos != -1 && s[*pos][0] == '\'') { *pos = *pos - 1; return cons(str_to_node("quote"), cons(r, NULL)); } else return (r); } else { char *tr = malloc((strlen(t) + 1) * sizeof(*tr)); sprintf(tr, "%s", t); node_t tn = str_to_node(tr); if (*pos != -1 && s[*pos][0] == '\'') { *pos = *pos - 1; return cons(str_to_node("quote"), cons(tn, NULL)); } else return (tn); } } // S-expression output: fp_string char fp_eval_retval[SSTR_MAX]; void fp_string(node_t s); void fp_strcons(node_t s) { fp_string(car(s)); node_t sd = cdr(s); if (eq(sd, NULL)) { } else if (n_strg(sd)) { strcat(fp_eval_retval, " . "); strcat(fp_eval_retval, node_to_str(sd)); } else { strcat(fp_eval_retval, " "); fp_strcons(sd); } } void fp_string(node_t s) { if (s == NULL) { strcat(fp_eval_retval, "nil"); } else if (n_strg(s)) { strcat(fp_eval_retval, node_to_str(s)); } else { strcat(fp_eval_retval, "("); fp_strcons(s); strcat(fp_eval_retval, ")"); } } // The evaluator: fp_eval and utility functions node_t fp_eval(node_t e, node_t a); #define FP_T (str_to_node("t")) #define FP_NIL (str_to_node("nil")) #define FP_CONS (str_to_node("cons")) #define FP_CAR (str_to_node("car")) #define FP_CDR (str_to_node("cdr")) #define FP_EQ (str_to_node("eq")) #define FP_ATOM (str_to_node("atom")) #define FP_ADD (str_to_node("+")) #define FP_SUB (str_to_node("-")) #define FP_MUL (str_to_node("*")) #define FP_DIV (str_to_node("/")) #define FP_MOD (str_to_node("%")) #define FP_LTN (str_to_node("lt")) node_t caar(node_t x) { return car(car(x)); } node_t cadr(node_t x) { return car(cdr(x)); } node_t cdar(node_t x) { return cdr(car(x)); } node_t cadar(node_t x) { return car(cdr(car(x))); } node_t caddr(node_t x) { return car(cdr(cdr(x))); } node_t cadddr(node_t x) { return car(cdr(cdr(cdr(x)))); } node_t fp_null(node_t x) { if (eq(x, NULL)) return FP_T; else return NULL; } node_t fp_append(node_t x, node_t y) { if (fp_null(x)) return y; else return cons(car(x), fp_append(cdr(x), y)); } node_t fp_pair(node_t x, node_t y) { if (fp_null(x) || fp_null(y)) return NULL; else if (!atom(x) && !atom(y)) return cons(cons(car(x), car(y)), fp_pair(cdr(x), cdr(y))); else return NULL; } node_t fp_assq(node_t k, node_t v) { if (fp_null(v)) return NULL; else if (eq(k, caar(v))) return cdar(v); else return fp_assq(k, cdr(v)); } node_t fp_cond(node_t c, node_t a) { if (fp_null(c)) return NULL; else if (eq(fp_eval(caar(c), a), FP_T)) return cadar(c); else return fp_cond(cdr(c), a); } int fp_isinteger(node_t t) { const char *str = node_to_str(t); int i; for (i = 0; i < strlen(str); i++) if (!isdigit(str[i]) && str[i] != '-') break; return i == strlen(str) ? 1 : 0; } node_t initenv; node_t fp_lookup(node_t t, node_t a) { if (eq(t, FP_T)) return FP_T; else if (eq(t, FP_NIL)) return FP_NIL; else if (eq(t, FP_CONS) || eq(t, FP_CAR) || eq(t, FP_CDR) || eq(t, FP_EQ) || eq(t, FP_ATOM) || eq(t, FP_ADD) || eq(t, FP_SUB) || eq(t, FP_MUL) || eq(t, FP_DIV) || eq(t, FP_MOD) || eq(t, FP_LTN) || fp_isinteger(t)) return t; else return fp_assq(t, fp_append(a, initenv)); } node_t fp_bool2node(int e) { if (e) return FP_T; else return NULL; } #define node_to_int(s) (atoi((char *)(s->value))) node_t int_to_node(int n) { char *s = malloc(sizeof(1024) * sizeof(*s)); sprintf(s, "%d", n); return node((value_t)(s), NODE_STRG); } node_t fp_apply(node_t f, node_t v) { if (eq(f, FP_CONS)) return cons(car(v), cadr(v)); else if (eq(f, FP_CAR)) return car(car(v)); else if (eq(f, FP_CDR)) return cdr(car(v)); else if (eq(f, FP_EQ)) return fp_bool2node(eq(car(v), cadr(v))); else if (eq(f, FP_ATOM)) return fp_bool2node(atom(car(v))); else if (eq(f, FP_ADD)) return int_to_node(node_to_int(car(v)) + node_to_int(cadr(v))); else if (eq(f, FP_SUB)) return int_to_node(node_to_int(car(v)) - node_to_int(cadr(v))); else if (eq(f, FP_MUL)) return int_to_node(node_to_int(car(v)) * node_to_int(cadr(v))); else if (eq(f, FP_DIV)) return int_to_node(node_to_int(car(v)) / node_to_int(cadr(v))); else if (eq(f, FP_MOD)) return int_to_node(node_to_int(car(v)) % node_to_int(cadr(v))); else if (eq(f, FP_LTN)) return fp_bool2node(node_to_int(car(v)) < node_to_int(cadr(v))); else return NULL; } #define FP_QUOTE (str_to_node("quote")) #define FP_IF (str_to_node("if")) #define FP_LAMBDA (str_to_node("lambda")) node_t fp_evals(node_t v, node_t a) { if (fp_null(v)) return NULL; else return cons(fp_eval(car(v), a), fp_evals(cdr(v), a)); } node_t fp_eval(node_t e, node_t a) { while (1) { if (atom(e)) { return fp_lookup(e, a); } else if (eq(car(e), FP_QUOTE)) { node_t vals = cadr(e); return vals; } else if (eq(car(e), FP_IF)) { if (eq(fp_eval(cadr(e), a), FP_T)) return fp_eval(caddr(e), a); else return fp_eval(cadddr(e), a); } else if (eq(car(e), FP_LAMBDA)) { node_t name = car(e); node_t vars = cadr(e); node_t body = caddr(e); return cons(name, cons(vars, cons(body, cons(a, NULL)))); } else { node_t efunc = fp_eval(car(e), a); node_t fvals = fp_evals(cdr(e), a); if (atom(efunc)) return fp_apply(efunc, fvals); else { node_t lname = car(efunc); node_t lvars = cadr(efunc); node_t lbody = caddr(efunc); node_t lenvs = cadddr(efunc); node_t fenvs = a; e = lbody; if (fp_null(lvars)) a = lenvs; else if (atom(lvars)) a = fp_append(cons(cons(lvars, fvals), NULL), lenvs); else a = fp_append(fp_pair(lvars, fvals), lenvs); } } } } // eval_string const char *INITENV = "(quote (" "(unfold . " " (lambda a " " ((lambda (f seed i) " " (((lambda (u) (u u)) (lambda (u) (lambda (e r) " " (if (eq e nil) r " " ((u u) (f (car e)) (cons (cdr e) r)))))) " " (f seed) (if (eq i nil) nil (car i)))) " " (car a) (car (cdr a)) (cdr (cdr a))))) " "(fold . " " (lambda x " " ((lambda (f i0 a0 b0) " " (((lambda (u) (u u)) (lambda (u) (lambda (i a b) " " (if (eq a nil) i " " (if (eq b nil) " " ((u u) (f i (car a)) (cdr a) b) " " ((u u) (f i (car a) (car b)) " " (cdr a) (cdr b))))))) " " i0 a0 (if (eq b0 nil) nil (car b0)))) " " (car x) (car (cdr x)) (car (cdr (cdr x))) " " (cdr (cdr (cdr x)))))) " "(unfold-stream . " " (lambda (f seed) " " (((lambda (u) (u u)) (lambda (u) (lambda (e) " " (cons (car e) (lambda () ((u u) (f (cdr e)))))))) " " (f seed)))) " "(take-stream . " " (lambda (s k) " " (((lambda (u) (u u)) (lambda (u) (lambda (s k) " " (if (eq k 0) nil " " (cons (car s) ((u u) ((cdr s)) (- k 1))))))) " " s k))) " "))"; void fp_eval_string(char *s) { char *lr_s_e[SSTR_MAX];; int fp_len_e = fp_lex(INITENV, lr_s_e) - 1; node_t rs_e = fp_syn(lr_s_e, &fp_len_e); initenv = fp_eval(rs_e, NULL); char *lr_s[SSTR_MAX];; int fp_len = fp_lex(s, lr_s) - 1; node_t rs = fp_syn(lr_s, &fp_len); node_t r = fp_eval(rs, NULL); fp_eval_retval[0] = '\0'; fp_string(r); } int main(int argc, char *argv[]) { char fp_src[SSTR_MAX], in[SSTR_MAX]; fp_src[0] = '\0'; while ((fgets(in, SSTR_MAX, stdin)) != NULL) { if (in[0] != '\n') { in[strlen(in)-1] = ' '; strcat(fp_src, in); } } if (strlen(fp_src)) { fp_eval_retval[0] = '\0'; fp_eval_string(fp_src); printf("%s\n", fp_eval_retval); } return (0); }
the_stack_data/79278.c
#include<stdio.h> #define ROW 10 #define COL 10 #define MAX 100 int a[ROW][COL]; int b[ROW][COL]; int c[ROW][COL]; int atrip[3][MAX]; int btrip[3][MAX]; int ctrip[3][MAX]; int dtrip[3][MAX]; void read_sparse(int mat[][COL], int row, int col){ int i,j; printf("\nEnter %d rows X %d cols elements:\n",row,col); for(i=0;i<row;i++){ for(j=0;j<col;j++){ scanf("%d",&mat[i][j]); } } } void print_sparse(int mat[][COL], int row, int col){ int i,j; printf("\nMatrix:\n"); for(i=0;i<row;i++){ for(j=0;j<col;j++){ printf("%4d ",mat[i][j]); } printf("\n"); } } void read_triplet(int mat[][3]) { int i,t,m,n; printf("\n Enter no. of rows and columns:\n"); scanf("%d%d",&m,&n); printf("\n No. of non-zero triples:\n"); scanf("%d",&t); mat[0][0]=m; mat[0][1]=n; mat[0][2]=t; printf("\n Enter the triples(row, column, value):\n"); for(i=1;i<=t;i++){ scanf("%d%d%d",&mat[i][0],&mat[i][1],&mat[i][2]); } } void print_triplet(int mat[3][MAX], int nzero){ int t; printf("\nOnly Print (Triplet):\n"); for(t=0;t<=nzero;t++){ printf("\n%d--%d: %d",mat[0][t],mat[1][t],mat[2][t]); } } void print_sparse_triplet(int sparseMat[][COL], int trip[3][MAX], int row, int col){ int size = 0; for (int i = 0; i < row; i++) for (int j = 0; j < col; j++) if (sparseMat[i][j] != 0) size++; // number of columns in compactMatrix (size) must be // equal to number of non - zero elements in // sparseMatrix int tripletMatrix[3][size+1]; tripletMatrix[0][0] = row; tripletMatrix[1][0] = col; tripletMatrix[2][0] = size; // Making of new matrix int k = 1; for (int i = 0; i < row; i++) for (int j = 0; j < col; j++) if (sparseMat[i][j] != 0) { tripletMatrix[0][k] = i; tripletMatrix[1][k] = j; tripletMatrix[2][k] = sparseMat[i][j]; k++; } printf("\n Triplet Matrix:\n"); for (int i=0; i<3; i++) { for (int j=0; j<=size; j++){ printf("%4d", tripletMatrix[i][j]); trip[i][j] = tripletMatrix[i][j]; } printf("\n"); } } void mul2sparse_mat(int mat1[][COL], int mat2[][COL], int row1, int col1, int row2, int col2){ int i, j, k; for(i=0;i<row1;i++){ for(j=0;j<col2;j++){ c[i][j]=0; for(k=0;k<col1;k++) c[i][j] = c[i][j] + (mat1[i][k]*mat2[k][j]); } } printf("\nThe multiplied matrix in traditional way:\n"); print_sparse(c, row1, col2); } void multiply_triplet(int a[3][MAX], int b[3][MAX]){ int r1,c1,d1,r2,c2,d2,i,j,k,l,flag1=0,flag2=0; int t1,t2,i1,j1,t,x,y,m; r1 = a[0][0]; c1 = a[1][0]; d1 = a[2][0]; r2 = b[0][0]; c2 = b[1][0]; d2 = b[2][0]; dtrip[0][0] = r1; dtrip[1][0] = c2; l=1; t = 0; x = 0; y = 0; for(i=0;i<r1;i++){ for(t1=1;t1<=d1;t1++){ if(a[0][t1]==i){ //printf("A:%d\t",a[2][t1]); for(j=0;j<c2;j++){ for(t2=1;t2<=d2;t2++){ if(b[1][t2]==j){ //printf("B:%d\n",b[2][t2]); for(k=0;k<c1;k++){ if(a[1][t1]==k && b[0][t2]==k && flag1 == 0) { x = a[0][t1]; y = b[1][t2]; //printf("\n%d-%d\n",x,y); //printf("\n%d * %d\n",a[2][t1],b[2][t2]); t = (a[2][t1]*b[2][t2]); flag1 = 1; } else flag1 = 0; if (flag1==1){ for(m=1;m<=l;m++){ if(dtrip[0][m] == x && dtrip[1][m]==y){ dtrip[2][m] = dtrip[2][m] + t; flag2 = 1; } } if(flag2==0){ dtrip[0][l] = x; dtrip[1][l] = y; dtrip[2][l] = t; l = l + 1; flag1 = 0; flag2 = 0; t = 0; } else{ if(l==1){ dtrip[2][l] = t; l = l + 1; } flag1 = 0; flag2 = 0; t = 0; } } } } } } } } } dtrip[2][0] = l-1; } int main(){ int row1, col1,row2, col2; printf("\nEnter the Row1 and Col1 values:\n"); scanf("%d%d",&row1,&col1); printf("\nEnter the Row2 and Col2 values:\n"); scanf("%d%d",&row2,&col2); printf("\nRead Sparse Matrix1:\n"); read_sparse(a,row1, col1); printf("\nRead Sparse Matrix2:\n"); read_sparse(b,row2, col2); printf("\nPrint Sparse Matrix1:\n"); print_sparse(a,row1, col1); print_sparse_triplet(a, atrip, row1, col1); printf("\nPrint Sparse Matrix2:\n"); print_sparse(b,row2, col2); print_sparse_triplet(b, btrip, row2, col2); //Multiplication in traditional way mul2sparse_mat(a, b, row1, col1, row2, col2); print_sparse_triplet(c, ctrip, row1, col2); //Print the respective triplets only print_triplet(atrip, row1*col1); print_triplet(btrip, row1*col1); print_triplet(ctrip, row1*col1); printf("\n***Triplet Multiplication***"); multiply_triplet(atrip, btrip); print_triplet(dtrip, row1*col1); return 0; }
the_stack_data/6439.c
#include <stdlib.h> int* f(int** v){ int* ptr = malloc(sizeof(int) * 100000); *v = ptr; } int main(void){ int* v; f(&v); }
the_stack_data/3262129.c
#include <stdlib.h> typedef struct element { int valeur; struct element *pred; struct element *succ; } t_element; t_element *drapeau; t_element *ec; void init_liste(){ drapeau = malloc(sizeof(t_element)); drapeau->pred = drapeau; drapeau->succ = drapeau; ec = drapeau; } int liste_vide(){ return (drapeau ->pred = drapeau); } int hors_liste(){ return ec == drapeau; } void en_tete(){ if(!liste_vide()) ec = drapeau->succ; } void en_queue(){ if(!liste_vide()) ec = drapeau->pred; } void suivant(){ if(!hors_liste()) ec = ec->succ; } void precedent(){ if(!hors_liste()) ec = ec->pred; } void valeur_elt(int *v){ if(!hors_liste()) *v = ec->valeur; } void modif_elt(int v){ if(!hors_liste()) ec->valeur = v; } void oter_elt(){ t_element *t; if (!hors_liste()){ t = ec; precedent(); ec->succ = t->succ; (t->succ)->pred = ec; free(t); } } void ajout_droit(int v){ t_element *t; t = malloc(sizeof(t_element)); t->valeur = v; t->pred = ec; t->succ = ec->succ; (ec->succ)->pred = t; ec->succ = t; ec = t; } void ajout_gauche(int v){ t_element *t; t = malloc(sizeof(t_element)); t->valeur = v; t->succ = ec; t->pred = ec->pred; (ec->pred)->succ = t; ec->pred = t; ec = t; }
the_stack_data/243893382.c
/* $OpenBSD: strlcat.c,v 1.15 2015/03/02 21:41:08 millert Exp $ */ /* * Copyright (c) 1998, 2015 Todd C. Miller <[email protected]> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include <string.h> /* * Appends src to string dst of size dsize (unlike strncat, dsize is the * full size of dst, not space left). At most dsize-1 characters * will be copied. Always NUL terminates (unless dsize <= strlen(dst)). * Returns strlen(src) + MIN(dsize, strlen(initial dst)). * If retval >= dsize, truncation occurred. */ size_t strlcat(char *dst, const char *src, size_t dsize) { const char *odst = dst; const char *osrc = src; size_t n = dsize; size_t dlen; /* Find the end of dst and adjust bytes left but don't go past end. */ while (n-- != 0 && *dst != '\0') dst++; dlen = dst - odst; n = dsize - dlen; if (n-- == 0) return(dlen + strlen(src)); while (*src != '\0') { if (n != 0) { *dst++ = *src; n--; } src++; } *dst = '\0'; return(dlen + (src - osrc)); /* count does not include NUL */ }
the_stack_data/220456109.c
/* * ESPRESSIF MIT License * * Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD> * * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case, * it is free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished * to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #include <stdio.h> #include <string.h> #if MICROPY_PY_AUDIO #include "py/objstr.h" #include "py/runtime.h" #include "audio_hal.h" #include "audio_pipeline.h" #include "board.h" #include "filter_resample.h" #include "i2s_stream.h" #include "raw_stream.h" #include "vfs_stream.h" #include "amrnb_encoder.h" #include "wav_encoder.h" enum { PCM, AMR, WAV, MP3 }; typedef struct _audio_recorder_obj_t { mp_obj_base_t base; audio_pipeline_handle_t pipeline; audio_element_handle_t i2s_stream; audio_element_handle_t filter; audio_element_handle_t encoder; audio_element_handle_t out_stream; esp_timer_handle_t timer; mp_obj_t end_cb; } audio_recorder_obj_t; STATIC mp_obj_t audio_recorder_stop(mp_obj_t self_in); STATIC mp_obj_t audio_recorder_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 0, false); audio_recorder_obj_t *self = m_new_obj_with_finaliser(audio_recorder_obj_t); self->base.type = type; return MP_OBJ_FROM_PTR(self); } STATIC audio_element_handle_t audio_recorder_create_filter(int encoder_type) { rsp_filter_cfg_t rsp_cfg = DEFAULT_RESAMPLE_FILTER_CONFIG(); rsp_cfg.src_rate = 48000; rsp_cfg.src_ch = 2; rsp_cfg.dest_ch = 1; rsp_cfg.task_core = 1; switch (encoder_type) { case PCM: { rsp_cfg.dest_rate = 16000; break; } case AMR: { rsp_cfg.dest_rate = 8000; break; } case WAV: { rsp_cfg.dest_rate = 16000; break; } default: break; } return rsp_filter_init(&rsp_cfg); } STATIC audio_element_handle_t audio_recorder_create_encoder(int encoder_type) { audio_element_handle_t encoder = NULL; switch (encoder_type) { case AMR: { amrnb_encoder_cfg_t amr_enc_cfg = DEFAULT_AMRNB_ENCODER_CONFIG(); amr_enc_cfg.task_core = 1; encoder = amrnb_encoder_init(&amr_enc_cfg); break; } case WAV: { wav_encoder_cfg_t wav_cfg = DEFAULT_WAV_ENCODER_CONFIG(); wav_cfg.task_core = 1; encoder = wav_encoder_init(&wav_cfg); break; } default: break; } return encoder; } STATIC audio_element_handle_t audio_recorder_create_outstream(const char *uri) { audio_element_handle_t out_stream = NULL; if (strstr(uri, "/sdcard/") != NULL) { vfs_stream_cfg_t vfs_cfg = VFS_STREAM_CFG_DEFAULT(); vfs_cfg.type = AUDIO_STREAM_WRITER; vfs_cfg.task_core = 1; out_stream = vfs_stream_init(&vfs_cfg); } else if (strstr(uri, "/spiffs/") != NULL) { // TODO: spiffs } else { raw_stream_cfg_t raw_cfg = RAW_STREAM_CFG_DEFAULT(); raw_cfg.type = AUDIO_STREAM_WRITER; out_stream = raw_stream_init(&raw_cfg); } audio_element_set_uri(out_stream, uri); return out_stream; } STATIC void audio_recorder_create(audio_recorder_obj_t *self, const char *uri, int format) { // init audio board audio_board_handle_t board_handle = audio_board_init(); audio_hal_ctrl_codec(board_handle->audio_hal, AUDIO_HAL_CODEC_MODE_BOTH, AUDIO_HAL_CTRL_START); // pipeline audio_pipeline_cfg_t pipeline_cfg = DEFAULT_AUDIO_PIPELINE_CONFIG(); self->pipeline = audio_pipeline_init(&pipeline_cfg); // I2S i2s_stream_cfg_t i2s_cfg = I2S_STREAM_CFG_DEFAULT(); i2s_cfg.type = AUDIO_STREAM_READER; i2s_cfg.uninstall_drv = false; i2s_cfg.i2s_config.sample_rate = 48000; i2s_cfg.task_core = 1; self->i2s_stream = i2s_stream_init(&i2s_cfg); // filter self->filter = audio_recorder_create_filter(format); // encoder self->encoder = audio_recorder_create_encoder(format); // out stream self->out_stream = audio_recorder_create_outstream(uri); // register to pipeline audio_pipeline_register(self->pipeline, self->i2s_stream, "i2s"); if (self->filter) { audio_pipeline_register(self->pipeline, self->filter, "filter"); } if (self->encoder) { audio_pipeline_register(self->pipeline, self->encoder, "encoder"); } audio_pipeline_register(self->pipeline, self->out_stream, "out"); if (format == WAV) { audio_element_info_t out_stream_info; audio_element_getinfo(self->out_stream, &out_stream_info); out_stream_info.sample_rates = 16000; out_stream_info.channels = 1; audio_element_setinfo(self->out_stream, &out_stream_info); } // link if (self->filter && self->encoder) { const char *link_tag[4] = {"i2s", "filter", "encoder", "out"}; audio_pipeline_link(self->pipeline, &link_tag[0], 4); } else if (self->filter) { const char *link_tag[3] = {"i2s", "filter", "out"}; audio_pipeline_link(self->pipeline, &link_tag[0], 3); } else if (self->encoder) { const char *link_tag[3] = {"i2s", "encoder", "out"}; audio_pipeline_link(self->pipeline, &link_tag[0], 3); } else { const char *link_tag[2] = {"i2s", "out"}; audio_pipeline_link(self->pipeline, &link_tag[0], 2); } } static void audio_recorder_maxtime_cb(void *arg) { audio_recorder_stop(arg); audio_recorder_obj_t *self = (audio_recorder_obj_t *)arg; if (self->end_cb != mp_const_none) { mp_sched_schedule(self->end_cb, self); } } STATIC mp_obj_t audio_recorder_start(mp_uint_t n_args, const mp_obj_t *args_in, mp_map_t *kw_args) { enum { ARG_uri, ARG_format, ARG_maxtime, ARG_endcb }; static const mp_arg_t allowed_args[] = { { MP_QSTR_uri, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = mp_const_none } }, { MP_QSTR_format, MP_ARG_INT, { .u_int = PCM } }, { MP_QSTR_maxtime, MP_ARG_INT, { .u_int = 0 } }, { MP_QSTR_endcb, MP_ARG_OBJ, { .u_obj = mp_const_none } }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; audio_recorder_obj_t *self = args_in[0]; mp_arg_parse_all(n_args - 1, args_in + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); if (self->pipeline != NULL) { return mp_obj_new_bool(false); } audio_recorder_create(self, mp_obj_str_get_str(args[ARG_uri].u_obj), args[ARG_format].u_int); if (audio_pipeline_run(self->pipeline) == ESP_OK) { if (args[ARG_maxtime].u_int > 0) { esp_timer_create_args_t timer_conf = { .callback = &audio_recorder_maxtime_cb, .name = "maxtime", .arg = self, }; esp_timer_create(&timer_conf, &self->timer); esp_timer_start_once(self->timer, args[ARG_maxtime].u_int * 1000000); self->end_cb = args[ARG_endcb].u_obj; } return mp_obj_new_bool(true); } else { return mp_obj_new_bool(false); } } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(audio_recorder_start_obj, 1, audio_recorder_start); STATIC mp_obj_t audio_recorder_stop(mp_obj_t self_in) { audio_recorder_obj_t *self = self_in; if (self->timer) { esp_timer_stop(self->timer); esp_timer_delete(self->timer); self->timer = NULL; } if (self->pipeline != NULL) { audio_pipeline_stop(self->pipeline); audio_pipeline_wait_for_stop(self->pipeline); audio_pipeline_deinit(self->pipeline); } else { return mp_obj_new_bool(false); } self->i2s_stream = NULL; self->filter = NULL; self->encoder = NULL; self->out_stream = NULL; self->pipeline = NULL; return mp_obj_new_bool(true); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(audio_recorder_stop_obj, audio_recorder_stop); STATIC mp_obj_t audio_recorder_is_running(mp_obj_t self_in) { audio_recorder_obj_t *self = self_in; return mp_obj_new_bool(self->pipeline != NULL); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(audio_recorder_is_running_obj, audio_recorder_is_running); STATIC const mp_rom_map_elem_t recorder_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_start), MP_ROM_PTR(&audio_recorder_start_obj) }, { MP_ROM_QSTR(MP_QSTR_stop), MP_ROM_PTR(&audio_recorder_stop_obj) }, { MP_ROM_QSTR(MP_QSTR_is_running), MP_ROM_PTR(&audio_recorder_is_running_obj) }, { MP_ROM_QSTR(MP_QSTR_PCM), MP_ROM_INT(PCM) }, { MP_ROM_QSTR(MP_QSTR_AMR), MP_ROM_INT(AMR) }, { MP_ROM_QSTR(MP_QSTR_WAV), MP_ROM_INT(WAV) }, { MP_ROM_QSTR(MP_QSTR_MP3), MP_ROM_INT(MP3) }, }; STATIC MP_DEFINE_CONST_DICT(recorder_locals_dict, recorder_locals_dict_table); const mp_obj_type_t audio_recorder_type = { { &mp_type_type }, .name = MP_QSTR_Recorder, .make_new = audio_recorder_make_new, .locals_dict = (mp_obj_dict_t *)&recorder_locals_dict, }; #endif // MICROPY_PY_AUDIO
the_stack_data/170453145.c
#include <stdio.h> char case_arr[10]; void check_case(char mode, char max_idx); void make_case(char mode, char min_idx, char max_idx); void check_case(char mode, char max_idx){ char r=0, b=0, y=0; for(int i=0;i<max_idx;i++){ if(case_arr[i]==1) r++; else if(case_arr[i]==2) b++; else if(case_arr[i]==3) y++; } if(mode==0 && r==1 && b==1 && y==1){ for(int i=0;i<max_idx;i++) printf("%d ",case_arr[i]); printf("\n"); make_case(1,0,2); } if(mode==1 && r==1 && b==0 && y==0){ for(int i=0;i<max_idx;i++) printf("%d ",case_arr[i]); printf("\n"); } } void make_case(char mode, char min_idx, char max_idx){ if(min_idx==max_idx){ check_case(mode, max_idx); return; } for(int i=0;i<4;i++){ case_arr[min_idx]=i; make_case(mode, min_idx+1, max_idx); } } int main(){ make_case(0,0,3); }
the_stack_data/96728.c
#include <unistd.h> #include "syscall.h" int fchown(int fd, uid_t uid, gid_t gid) { return syscall(SYS_fchown, fd, uid, gid); }
the_stack_data/130953.c
#include <stdio.h> int binsearch(int x, int v[], int n); int main(void) { int i; int result; int n = 1000; int x = 889; int v[n]; // initialize for (i=0; i < n; ++i) v[i] = i; result = binsearch(x, v, n); printf("%d at index %d\n", x, result); return 0; } /* find index of array element x using binary search v it the array, n is its length. return -1 if not present */ int binsearch(int x, int v[], int n) { int low, high, mid; low = 0; high = n - 1; while (low <= high) { mid = (high + low) / 2; if (x < v[mid]) high = mid - 1; else if (x > v[mid]) low = mid + 1; else return mid; } return -1; }
the_stack_data/431286.c
#include <stdio.h> #include <stdlib.h> #include <string.h> /* entradas: 50463 Rafael Patricio de Souza 6.3 6 7 52525 Aline Cristine 10 9.5 9.2 66666 Gabriel Patricio 6 6 6.6 111 Fulaninho 0.8 3.2 1.4 2222 Ciclaninho 5.1 6.2 2.9 */ typedef struct alu{ int matricula; char nome[30]; float notas[3]; }ALUNO; void maiorNota(ALUNO a[5]){ int i; float maior=0.0; char alunoMaior[30]; for(i=0;i<5;i++) if(a[i].notas[0]>maior){ maior=a[i].notas[0]; strcpy(alunoMaior, a[i].nome); } printf("\nAluno(a) com maior nota na 1a prova: %s\n\n", alunoMaior); } void media(ALUNO a[5]){ int i, j; float media[5], maior=0.0, menor=0.0; char mediaMenor[30], mediaMaior[30]; printf("\nSituacao:"); for(i=0;i<5;i++){ media[i]=0.0; for(j=0;j<3;j++) media[i]+=a[i].notas[j]; media[i]/=3.0; printf("\n%s - %.2f - ", a[i].nome, media[i]); if(media[i]>=6) printf("Aprovado"); else printf("Reprovado"); if(i==0) menor=maior=media[i]; if(media[i]<menor){ menor=media[i]; strcpy(mediaMenor,a[i].nome); } if(media[i]>maior){ maior=media[i]; strcpy(mediaMaior,a[i].nome); } } printf("\nAluno(a) com menor media: %s\n", mediaMenor); printf("\nAluno(a) com maior media: %s\n\n", mediaMaior); } int main() { ALUNO a[5]; int i, j; for(i=0;i<5;i++){ printf("Digite os dados do %do aluno:", i+1); printf("\nMatricula: "); scanf("%d", &a[i].matricula); fflush(stdin); printf("\nNome: "); gets(a[i].nome); fflush(stdin); printf("\nNotas:"); for(j=0;j<3;j++){ printf("\n%da Prova: ", j+1); scanf("%f", &a[i].notas[j]); fflush(stdin); } printf("\n"); } printf("Dados dos alunos:\n"); for(i=0;i<5;i++){ printf("\naluno(a) %d\nMatricula: %d", i+1, a[i].matricula); printf("\nNome: %s\n", a[i].nome); } maiorNota(a); media(a); return 0; system("PAUSE"); }
the_stack_data/656792.c
typedef unsigned char uint8_t; typedef unsigned short uint16_t; typedef unsigned int uint32_t; struct iter { uint32_t i; }; struct point { uint32_t i, j; }; static void outb(uint8_t value, uint16_t port) { __builtin_outb(value, port); } static struct point mkpoint(void) { struct point p; p.i = 1000; p.j = 2000; return p; } static void main(void) { struct iter iter; for(iter.i = 0; iter.i < 32; iter.i++) { outb(iter.i, 0x80); } struct point p; p = mkpoint(); outb(p.i, 0x80); outb(p.j, 0x80); }
the_stack_data/51528.c
#include <stdio.h> #include <stdlib.h> #include <math.h> #define len(x) sizeof(x) / sizeof(x[0]) // gotta write a function to strip leading 0 int min(int a, int b){ if(a <= b){ return a; }else{ return b; } } int max(int a, int b){ if(a >= b){ return a; }else{ return b; } } int* convolve(int* c, int* a, int* b){ int s; int e0; int e1; int k = len(c); for(int m = 0; m < k; m++){ printf("%d\n", m); s = 0; e0 = max(0, m - len(b) + 1); e1 = min(m, len(a)); for(int i = min(e0, e1); i < max(e0, e1); i++){ printf("\t%d\n", i); s += a[i] * b[m - i]; } c[m] = s; } } int* multiply(int* c, int* a, int* b){ int k; int r; int x; k = len(c); convolve(c, a, b); /* for(int i = 0; i < k - 1; i++){ x = c[i] / 10; r = c[i] % 10; c[i] = r; c[i + 1] += x; } */ //return c[k - 1] == 0; } void main(){ /* int n = 15; unsigned long n_factorial = 1; for(int i = 1; i <= n; i++){ n_factorial = n_factorial * i; } printf("%ld\n", n_factorial); */ //printf("%zu\n", ); int a[1] = {1}; int b[1] = {2}; int k = len(a) + len(b); int c[k]; multiply(c, a, b); for(int i = 0; i < k; i++){ printf("%d,", c[i]); } printf("\n"); }
the_stack_data/237643520.c
/* # clove # # Copyright (C) 2016-2018 Muresan Vlad # # This project is free software; you can redistribute it and/or modify it # under the terms of the MIT license. See LICENSE.md for details. */ #ifdef USE_LUA #include "../include/system.h" #include "../include/system.h" #include "tools.h" #include <stdlib.h> #include <stdio.h> static int l_system_getOS(lua_State* state) { lua_pushstring (state, system_getOS()); return 1; } static int l_system_getPowerInfo(lua_State* state) { system_PowerState power = system_getPowerInfo(); lua_pushstring(state, power.state); lua_pushinteger(state, power.seconds); lua_pushinteger(state, power.percent); return 3; } static int l_system_getProcessorCount(lua_State* state) { lua_pushinteger(state, system_getProcessorCount()); return 1; } static int l_system_getClipboardText(lua_State* state) { lua_pushstring(state, system_getClipboardText()); return 1; } static int l_system_setClipboardText(lua_State* state) { const char* text = l_tools_toStringOrError(state, 1); system_setClipboardText(text); return 0; } static luaL_Reg const regFuncs[] = { {"getOS", l_system_getOS}, {"setClipboardText", l_system_setClipboardText}, {"getClipboardText", l_system_getClipboardText}, {"getProcessorCount", l_system_getProcessorCount}, {"getPowerInfo", l_system_getPowerInfo}, {NULL,NULL} }; int l_system_register(lua_State* state) { l_tools_registerModule(state, "system", regFuncs); return 0; } #endif
the_stack_data/248581959.c
/* * copyright 2015 Wink Saville * * licensed under the apache license, version 2.0 (the "license"); * you may not use this file except in compliance with the license. * you may obtain a copy of the license at * * http://www.apache.org/licenses/license-2.0 * * unless required by applicable law or agreed to in writing, software * distributed under the license is distributed on an "as is" basis, * without warranties or conditions of any kind, either express or implied. * see the license for the specific language governing permissions and * limitations under the license. */ #include <stdlib.h> void ac_stop(void) { exit(1); }
the_stack_data/20450258.c
void main() { signed char i, j; i = j; i = i + 1; }
the_stack_data/1271023.c
#include <curses.h> int ungetch(int ch) { return 0; } /* XOPEN(400) LINK(curses) */
the_stack_data/175143527.c
#include <dirent.h> #include <stdio.h> /** * 演示ls的功能,遍历展示目录下的文件列表 */ int main(int argc, char const *argv[]) { DIR *dir; struct dirent *dirp; printf("%s %s \n", argv[0], argv[1]); if (argc != 2) { puts("usage: ls directory_name"); return 0; } if ((dir = opendir(argv[1])) == NULL) { puts("cannot open this dir"); } while((dirp = readdir(dir)) != NULL) { printf("%s \n", dirp -> d_name); } closedir(dir); return 0; }
the_stack_data/446988.c
/* In computer science, a linked list is a linear collection of data elements, whose order is not given by their physical placement in memory. Instead, each element points to the next. It is a data structure consisting of a collection of nodes which together represent a sequence. In its most basic form, each node contains: data, and a reference (in other words, a link) to the next node in the sequence. This structure allows for efficient insertion or removal of elements from any position in the sequence during iteration. More complex variants add additional links, allowing more efficient insertion or removal of nodes at arbitrary positions. A drawback of linked lists is that access time is linear (and difficult to pipeline). Faster access, such as random access, is not feasible. Arrays have better cache locality compared to linked lists. */ #include<stdio.h> #include<stdlib.h> //Defining a node with two fields -> 1. data and 2. a node pointer next //A node pointer[root] is declared which always points to the first n struct node { int data; struct node *next; }*root; void appendNode(); //This Function adds a new node at the end of the list. void traverseNode(); //This Function traverses the node to print its stored values. void beginNode(); //This Function adds a new node at the begining of the list. void insertNthNode(); //This Function adds a new node at any nth position of the list. // Menu Driven Code to access different Singly Linked List operations void main() { int ch = 0; while(ch != 5) { printf("\n"); printf("Select Operation:\n"); printf("1.Append Node\n2.Traverse Node\n3.Add Node at the beginning\n4.Add Node at nth pos\n5.Quit:"); scanf("%d", &ch); switch (ch) { case 1: appendNode(); break; case 2: traverseNode(); break; case 3: beginNode(); break; case 4: insertNthNode(); break; default: printf("Invalid choice %d\n", ch); break; } } } void beginNode() { int val; struct node *current; printf("Enter Value at beginning:"); scanf("%d", &val); current = (struct node*)malloc(sizeof(struct node)); current->data = val; if(root == NULL) { current->next = NULL; root = current; } else { current->next = root; root = current; } } void appendNode() { int val; struct node *current, *tmp; printf("Enter the value to append:"); scanf("%d", &val); current = (struct node*)malloc(sizeof(struct node)); tmp = root; current->data = val; current->next = NULL; if(root == NULL) root = current; else { while(tmp->next!=NULL) { tmp = tmp->next; } tmp->next = current; } } void traverseNode() { struct node* tmp; printf("\n"); for(tmp = root; tmp != NULL; tmp = tmp->next) printf("%d ", tmp->data); printf("\n"); } void insertNthNode() { int n, val; struct node *tmp, *current; tmp = root; printf("Enter nth pos and value [space seperated]:"); scanf("%d %d", &n, &val); current = (struct node*)malloc(sizeof(struct node)); current->data = val; for(int i = 1; i<n-1; i++) tmp = tmp->next; current->next = tmp->next; tmp->next = current; }
the_stack_data/89664.c
#include<stdio.h> #include<stdlib.h> #include<ctype.h> #include<time.h> #include<string.h> #include<sys/time.h> #define MAX_STR_LEN 25 typedef struct Data_ { char *name; struct Data_ *nextData; }Data; typedef struct Timer_ { double start; double end; }Timer; // USED FOR BUBBLE SORT Data* bubble_sort(Data *list); //USED FOR MERGE SORT int length(Data* list); void move_node(Data** destRef, Data** sourceRef); void split_in_half(Data *source, Data **frontRef, Data** backRef); Data* merge(Data *a, Data* b); void merge_sort(Data **list); // USED FOR creating out list void push(Data **head, char *name); //USED FOR freeing our list void destroy(Data *list); //Allows us to open a file and create our linked list Data* read_from_file(const char* file, const int size); // shows to the user the linked list void display(Data *list); // USED FOR TIMING OUR CODE void start_timer(Timer* t); double get_time_diff(Timer* t); void end_timer(Timer *t); int main (int argc, char **argv) { /* * Error checking the number of passed in parameters * */ if (argc < 3) { printf("Not enough parameters bub!\n"); exit(0); } /* * Opening file for writng the timing output * */ FILE* fp = fopen("timing.out", "w"); Data *head = NULL; // Pulling the number of names needed to read into my program const int size = atoi(argv[2]); /* * Setting up timer structure * */ Timer *t = malloc(sizeof(Timer)); t->start = 0; t->end = 0; /* * Timing read from file * */ start_timer(t); head = read_from_file(argv[1], size); end_timer(t); fprintf(fp,"\nReading from the %s %d\ntook %lf seconds\n\n", argv[1], size,get_time_diff(t)); /* * Timing the time taken to sort with bubble sort * */ printf("Bubble Sort\n"); fprintf(fp,"Bubble Sort\n"); start_timer(t); head = bubble_sort(head); end_timer(t); fprintf(fp,"Sorting the linked list with bubble sort\ntook %lf seconds for %d nodes\n\n", get_time_diff(t), size); display(head); /* * Destroying current head and reassigning back to NULL * */ destroy(head); head = NULL; head = read_from_file(argv[1], size); /* * Timing the time taken to sort with merge sort * */ printf("Merge Sort\n"); fprintf(fp,"\nMerge Sort\n"); start_timer(t); merge_sort(&head); end_timer(t); fprintf(fp,"Sorting the linked list with merge sort\ntook %lf seconds for %d nodes\n\n", get_time_diff(t), size); display(head); /* * Clean up of allocations and open files * */ destroy(head); free(t); fclose(fp); // destroy list return 0; } /* * Timing functions (DO NOT DELETE THEM!) **/ void start_timer(Timer *t) { struct timeval tp; int rtn; rtn=gettimeofday(&tp, NULL); t->start = (double)tp.tv_sec+(1.e-6)*tp.tv_usec; } double get_time_diff(Timer *t) { return t->end - t->start; } void end_timer(Timer *t) { struct timeval tp; int rtn; rtn=gettimeofday(&tp, NULL); t->end = (double)tp.tv_sec+(1.e-6)*tp.tv_usec; } void destroy(Data* list) { Data *curr = list; Data *needs_freeing; while (curr) { needs_freeing = curr; curr = curr->nextData; free(needs_freeing->name); free(needs_freeing); } } Data* read_from_file(const char *file, const int size){ FILE *fp = fopen(file,"r"); if (!fp) { exit(1); } char name[MAX_STR_LEN]; Data *head = NULL; int i = 0; for ( ;i < size; ++i) { fscanf(fp,"%s", name); push(&head,name); } fclose(fp); return head; } void push(Data **head, char *name) { Data *new_node = malloc(sizeof(Data)); new_node->name = malloc(sizeof(char) * MAX_STR_LEN); strncpy(new_node->name,name, MAX_STR_LEN); new_node->nextData = *head; *head = new_node; } Data* bubble_sort(Data *list) { int num_nodes = length(list); int idx = 0; for (idx = 0; idx < num_nodes; ++idx) { Data* current = list; Data* next = current->nextData; Data* prev = NULL; while (next != NULL) { if (strcmp(current->name, current->nextData->name) < 0) { if (current == list) { list = next; } else { prev->nextData = next; } current->nextData = next->nextData; next->nextData = current; prev = next; next = current->nextData; } else { prev = current; current = current->nextData; next = current->nextData; } } } return list; /*Data *p = NULL; Data *q = NULL; Data *top = NULL; int changed = 1; top = malloc(sizeof(Data)); if (top == NULL) { exit(1); } top->nextData = list; if (list != NULL && list->nextData != NULL) { while (changed) { p = top; q = top->nextData; changed = 0; while(p->nextData != NULL) { if (strcmp(p->name, p->nextData->name) < 0) { q->nextData = swap(p,p->nextData); changed = 1; } q = p; if ( p->nextData != NULL) p = p->nextData; } } } p = top->nextData; free(top); return p;*/ } Data* swap(Data *left, Data *right) { left->nextData = right->nextData; right->nextData = left; } void display(Data *list) { if (!list) { printf("LIST IS EMPTY\n"); exit(1); } int i = 0; Data *current = list; for ( ; current ; current = current->nextData) { printf("%s\n", current->name); } } /* * Used to find the length of an array useful inside front back split function * */ int length(Data* list) { int count = 0; Data* current = list; while(current) { current = current->nextData; ++count; } return count; } void split_in_half(Data *source, Data **frontRef, Data** backRef) { int len = length(source); int i = 0; Data* current = source; if (len < 2){ *frontRef = source; *backRef = NULL; } else { int hopCount = (len - 1)/2; for (i = 0; i < hopCount;++i) { current = current->nextData; } *frontRef = source; *backRef = current->nextData; current->nextData = NULL; } } /* * Take the node from the front of the source, and move it to the front * of the dest. It is an error to call this with the sourceRef list is empty. * * before calling move_node(): * source == {1,2,3} * dest == {1,2,3} * * After calling move_node(): * source == {2,3} * dest == {1,1,2,3} * */ void move_node(Data** destRef, Data** sourceRef) { Data* newData = *sourceRef; *sourceRef = newData->nextData; newData->nextData = *destRef; *destRef = newData; } Data* merge(Data *a, Data* b) { Data *result = NULL; Data **lastPtrRef = &result; while (1) { if (a == NULL) { *lastPtrRef = b; break; } else if (b == NULL) { *lastPtrRef = a; break; } if (strcmp(a->name,b->name) > 0) { move_node(lastPtrRef, &a); } else { move_node(lastPtrRef,&b); } lastPtrRef = &((*lastPtrRef)->nextData); } return(result); } void merge_sort(Data **list) { Data* head = *list; Data* a; Data* b; if ((head == NULL) || (head->nextData == NULL)){ return; } split_in_half(head, &a, &b); merge_sort(&a); merge_sort(&b); *list = merge(a,b); }
the_stack_data/61074622.c
/* Author : Arnob Mahmud mail : [email protected] */ #include <stdio.h> int main(int argc, char const *argv[]) { int A[10][10], B[10][10], C[10][10], m, n; printf("Enter number of row : "); scanf("%d", &m); printf("Enter number of column : "); scanf("%d", &n); printf("\nEnter elements of matrix A : \n"); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { printf("A[%d][%d] = ", i, j); scanf("%d", &A[i][j]); } } printf("\nEnter elements of matrix B : \n"); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { printf("A[%d][%d] = ", i, j); scanf("%d", &B[i][j]); } } printf("\nC = A - B : \n"); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { C[i][j] = A[i][j] - B[i][j]; printf("%d\t", C[i][j]); } printf("\n"); } return 0; }
the_stack_data/1138204.c
/* httpd.c Copyright (c) 2004,2005 Minero Aoki This program is free software. Redistribution and use in source and binary forms, with or without modification, are permitted. */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/time.h> #include <sys/socket.h> #include <sys/wait.h> #include <netdb.h> #include <fcntl.h> #include <errno.h> #include <string.h> #include <time.h> #include <stdarg.h> #include <ctype.h> #include <signal.h> #include <pwd.h> #include <grp.h> #include <syslog.h> #define _GNU_SOURCE #include <getopt.h> /****** Constants ********************************************************/ #define SERVER_NAME "LittleHTTP" #define SERVER_VERSION "1.0" #define HTTP_MINOR_VERSION 0 #define BLOCK_BUF_SIZE 1024 #define LINE_BUF_SIZE 4096 #define MAX_REQUEST_BODY_LENGTH (1024 * 1024) #define MAX_BACKLOG 5 #define DEFAULT_PORT "80" /****** Data Type Definitions ********************************************/ struct HTTPHeaderField { char *name; char *value; struct HTTPHeaderField *next; }; struct HTTPRequest { int protocol_minor_version; char *method; char *path; struct HTTPHeaderField *header; char *body; long length; }; struct FileInfo { char *path; long size; int ok; }; /****** Function Prototypes **********************************************/ static void setup_environment(char *root, char *user, char *group); typedef void (*sighandler_t)(int); static void install_signal_handlers(void); static void trap_signal(int sig, sighandler_t handler); static void signal_exit(int sig); static void wait_child(int sig); static void become_daemon(void); static int listen_socket(char *port); static void server_main(int server, char *docroot); static void service(FILE *in, FILE *out, char *docroot); static struct HTTPRequest* read_request(FILE *in); static void read_request_line(struct HTTPRequest *req, FILE *in); static struct HTTPHeaderField* read_header_field(FILE *in); static void upcase(char *str); static void free_request(struct HTTPRequest *req); static long content_length(struct HTTPRequest *req); static char* lookup_header_field_value(struct HTTPRequest *req, char *name); static void respond_to(struct HTTPRequest *req, FILE *out, char *docroot); static void do_file_response(struct HTTPRequest *req, FILE *out, char *docroot); static void method_not_allowed(struct HTTPRequest *req, FILE *out); static void not_implemented(struct HTTPRequest *req, FILE *out); static void not_found(struct HTTPRequest *req, FILE *out); static void output_common_header_fields(struct HTTPRequest *req, FILE *out, char *status); static struct FileInfo* get_fileinfo(char *docroot, char *path); static char* build_fspath(char *docroot, char *path); static void free_fileinfo(struct FileInfo *info); static char* guess_content_type(struct FileInfo *info); static void* xmalloc(size_t sz); static void log_exit(const char *fmt, ...); /****** Functions ********************************************************/ #define USAGE "Usage: %s [--port=n] [--chroot --user=u --group=g] [--debug] <docroot>\n" static int debug_mode = 0; static struct option longopts[] = { {"debug", no_argument, &debug_mode, 1}, {"chroot", no_argument, NULL, 'c'}, {"user", required_argument, NULL, 'u'}, {"group", required_argument, NULL, 'g'}, {"port", required_argument, NULL, 'p'}, {"help", no_argument, NULL, 'h'}, {0, 0, 0, 0} }; int main(int argc, char *argv[]) { int server; char *port = NULL; char *docroot; int do_chroot = 0; char *user = NULL; char *group = NULL; int opt; while ((opt = getopt_long(argc, argv, "", longopts, NULL)) != -1) { switch (opt) { case 0: break; case 'c': do_chroot = 1; break; case 'u': user = optarg; break; case 'g': group = optarg; break; case 'p': port = optarg; break; case 'h': fprintf(stdout, USAGE, argv[0]); exit(0); case '?': fprintf(stderr, USAGE, argv[0]); exit(1); } } if (optind != argc - 1) { fprintf(stderr, USAGE, argv[0]); exit(1); } docroot = argv[optind]; if (do_chroot) { setup_environment(docroot, user, group); docroot = ""; } install_signal_handlers(); server = listen_socket(port); if (!debug_mode) { openlog(SERVER_NAME, LOG_PID|LOG_NDELAY, LOG_DAEMON); become_daemon(); } server_main(server, docroot); exit(0); } static void setup_environment(char *root, char *user, char *group) { struct passwd *pw; struct group *gr; if (!user || !group) { fprintf(stderr, "use both of --user and --group\n"); exit(1); } gr = getgrnam(group); if (!gr) { fprintf(stderr, "no such group: %s\n", group); exit(1); } if (setgid(gr->gr_gid) < 0) { perror("setgid(2)"); exit(1); } if (initgroups(user, gr->gr_gid) < 0) { perror("initgroups(2)"); exit(1); } pw = getpwnam(user); if (!pw) { fprintf(stderr, "no such user: %s\n", user); exit(1); } chroot(root); if (setuid(pw->pw_uid) < 0) { perror("setuid(2)"); exit(1); } } static void become_daemon(void) { int n; if (chdir("/") < 0) log_exit("chdir(2) failed: %s", strerror(errno)); freopen("/dev/null", "r", stdin); freopen("/dev/null", "w", stdout); freopen("/dev/null", "w", stderr); n = fork(); if (n < 0) log_exit("fork(2) failed: %s", strerror(errno)); if (n != 0) _exit(0); if (setsid() < 0) log_exit("setsid(2) failed: %s", strerror(errno)); } static void install_signal_handlers(void) { trap_signal(SIGTERM, signal_exit); trap_signal(SIGCHLD, wait_child); } static void trap_signal(int sig, sighandler_t handler) { struct sigaction act; act.sa_handler = handler; sigemptyset(&act.sa_mask); act.sa_flags = SA_RESTART; if (sigaction(sig, &act, NULL) < 0) log_exit("sigaction() failed: %s", strerror(errno)); } static void signal_exit(int sig) { log_exit("exit by signal %d", sig); } static void wait_child(int sig) { wait(NULL); } static int listen_socket(char *port) { struct addrinfo hints, *res, *ai; int err; memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_PASSIVE; if ((err = getaddrinfo(NULL, port, &hints, &res)) != 0) log_exit(gai_strerror(err)); for (ai = res; ai; ai = ai->ai_next) { int sock; sock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); if (sock < 0) continue; if (bind(sock, ai->ai_addr, ai->ai_addrlen) < 0) { close(sock); continue; } if (listen(sock, MAX_BACKLOG) < 0) { close(sock); continue; } freeaddrinfo(res); return sock; } log_exit("failed to listen socket"); return -1; /* NOT REACH */ } static void server_main(int server, char *docroot) { for (;;) { struct sockaddr_storage addr; socklen_t addrlen = sizeof addr; int sock; int pid; sock = accept(server, (struct sockaddr*)&addr, &addrlen); if (sock < 0) log_exit("accept(2) failed: %s", strerror(errno)); pid = fork(); if (pid < 0) exit(3); if (pid == 0) { /* child */ FILE *inf = fdopen(sock, "r"); FILE *outf = fdopen(sock, "w"); service(inf, outf, docroot); exit(0); } close(sock); } } static void service(FILE *in, FILE *out, char *docroot) { struct HTTPRequest *req; req = read_request(in); respond_to(req, out, docroot); free_request(req); } static struct HTTPRequest* read_request(FILE *in) { struct HTTPRequest *req; struct HTTPHeaderField *h; req = xmalloc(sizeof(struct HTTPRequest)); read_request_line(req, in); req->header = NULL; while (h = read_header_field(in)) { h->next = req->header; req->header = h; } req->length = content_length(req); if (req->length != 0) { if (req->length > MAX_REQUEST_BODY_LENGTH) log_exit("request body too long"); req->body = xmalloc(req->length); if (fread(req->body, req->length, 1, in) < 1) log_exit("failed to read request body"); } else { req->body = NULL; } return req; } static void read_request_line(struct HTTPRequest *req, FILE *in) { char buf[LINE_BUF_SIZE]; char *path, *p; if (!fgets(buf, LINE_BUF_SIZE, in)) log_exit("no request line"); p = strchr(buf, ' '); /* p (1) */ if (!p) log_exit("parse error on request line (1): %s", buf); *p++ = '\0'; req->method = xmalloc(p - buf); strcpy(req->method, buf); upcase(req->method); path = p; p = strchr(path, ' '); /* p (2) */ if (!p) log_exit("parse error on request line (2): %s", buf); *p++ = '\0'; req->path = xmalloc(p - path); strcpy(req->path, path); if (strncasecmp(p, "HTTP/1.", strlen("HTTP/1.")) != 0) log_exit("parse error on request line (3): %s", buf); p += strlen("HTTP/1."); /* p (3) */ req->protocol_minor_version = atoi(p); } static struct HTTPHeaderField* read_header_field(FILE *in) { struct HTTPHeaderField *h; char buf[LINE_BUF_SIZE]; char *p; if (!fgets(buf, LINE_BUF_SIZE, in)) log_exit("failed to read request header field: %s", strerror(errno)); if ((buf[0] == '\n') || (strcmp(buf, "\r\n") == 0)) return NULL; p = strchr(buf, ':'); if (!p) log_exit("parse error on request header field: %s", buf); *p++ = '\0'; h = xmalloc(sizeof(struct HTTPHeaderField)); h->name = xmalloc(p - buf); strcpy(h->name, buf); p += strspn(p, " \t"); h->value = xmalloc(strlen(p) + 1); strcpy(h->value, p); return h; } static void upcase(char *str) { char *p; for (p = str; *p; p++) { *p = (char)toupper((int)*p); } } static void free_request(struct HTTPRequest *req) { struct HTTPHeaderField *h, *head; head = req->header; while (head) { h = head; head = head->next; free(h->name); free(h->value); free(h); } free(req->method); free(req->path); free(req->body); free(req); } static long content_length(struct HTTPRequest *req) { char *val; long len; val = lookup_header_field_value(req, "Content-Length"); if (!val) return 0; len = atol(val); if (len < 0) log_exit("negative Content-Length value"); return len; } static char* lookup_header_field_value(struct HTTPRequest *req, char *name) { struct HTTPHeaderField *h; for (h = req->header; h; h = h->next) { if (strcasecmp(h->name, name) == 0) return h->value; } return NULL; } static void respond_to(struct HTTPRequest *req, FILE *out, char *docroot) { if (strcmp(req->method, "GET") == 0) do_file_response(req, out, docroot); else if (strcmp(req->method, "HEAD") == 0) do_file_response(req, out, docroot); else if (strcmp(req->method, "POST") == 0) method_not_allowed(req, out); else not_implemented(req, out); } static void do_file_response(struct HTTPRequest *req, FILE *out, char *docroot) { struct FileInfo *info; info = get_fileinfo(docroot, req->path); if (!info->ok) { free_fileinfo(info); not_found(req, out); return; } output_common_header_fields(req, out, "200 OK"); fprintf(out, "Content-Length: %ld\r\n", info->size); fprintf(out, "Content-Type: %s\r\n", guess_content_type(info)); fprintf(out, "\r\n"); if (strcmp(req->method, "HEAD") != 0) { int fd; char buf[BLOCK_BUF_SIZE]; ssize_t n; fd = open(info->path, O_RDONLY); if (fd < 0) log_exit("failed to open %s: %s", info->path, strerror(errno)); for (;;) { n = read(fd, buf, BLOCK_BUF_SIZE); if (n < 0) log_exit("failed to read %s: %s", info->path, strerror(errno)); if (n == 0) break; if (fwrite(buf, 1, n, out) < n) log_exit("failed to write to socket"); } close(fd); } fflush(out); free_fileinfo(info); } static void method_not_allowed(struct HTTPRequest *req, FILE *out) { output_common_header_fields(req, out, "405 Method Not Allowed"); fprintf(out, "Content-Type: text/html\r\n"); fprintf(out, "\r\n"); fprintf(out, "<html>\r\n"); fprintf(out, "<header>\r\n"); fprintf(out, "<title>405 Method Not Allowed</title>\r\n"); fprintf(out, "<header>\r\n"); fprintf(out, "<body>\r\n"); fprintf(out, "<p>The request method %s is not allowed</p>\r\n", req->method); fprintf(out, "</body>\r\n"); fprintf(out, "</html>\r\n"); fflush(out); } static void not_implemented(struct HTTPRequest *req, FILE *out) { output_common_header_fields(req, out, "501 Not Implemented"); fprintf(out, "Content-Type: text/html\r\n"); fprintf(out, "\r\n"); fprintf(out, "<html>\r\n"); fprintf(out, "<header>\r\n"); fprintf(out, "<title>501 Not Implemented</title>\r\n"); fprintf(out, "<header>\r\n"); fprintf(out, "<body>\r\n"); fprintf(out, "<p>The request method %s is not implemented</p>\r\n", req->method); fprintf(out, "</body>\r\n"); fprintf(out, "</html>\r\n"); fflush(out); } static void not_found(struct HTTPRequest *req, FILE *out) { output_common_header_fields(req, out, "404 Not Found"); fprintf(out, "Content-Type: text/html\r\n"); fprintf(out, "\r\n"); if (strcmp(req->method, "HEAD") != 0) { fprintf(out, "<html>\r\n"); fprintf(out, "<header><title>Not Found</title><header>\r\n"); fprintf(out, "<body><p>File not found</p></body>\r\n"); fprintf(out, "</html>\r\n"); } fflush(out); } #define TIME_BUF_SIZE 64 static void output_common_header_fields(struct HTTPRequest *req, FILE *out, char *status) { time_t t; struct tm *tm; char buf[TIME_BUF_SIZE]; t = time(NULL); tm = gmtime(&t); if (!tm) log_exit("gmtime() failed: %s", strerror(errno)); strftime(buf, TIME_BUF_SIZE, "%a, %d %b %Y %H:%M:%S GMT", tm); fprintf(out, "HTTP/1.%d %s\r\n", HTTP_MINOR_VERSION, status); fprintf(out, "Date: %s\r\n", buf); fprintf(out, "Server: %s/%s\r\n", SERVER_NAME, SERVER_VERSION); fprintf(out, "Connection: close\r\n"); } static struct FileInfo* get_fileinfo(char *docroot, char *urlpath) { struct FileInfo *info; struct stat st; info = xmalloc(sizeof(struct FileInfo)); info->path = build_fspath(docroot, urlpath); info->ok = 0; if (lstat(info->path, &st) < 0) return info; if (!S_ISREG(st.st_mode)) return info; info->ok = 1; info->size = st.st_size; return info; } static char * build_fspath(char *docroot, char *urlpath) { char *path; path = xmalloc(strlen(docroot) + 1 + strlen(urlpath) + 1); sprintf(path, "%s/%s", docroot, urlpath); return path; } static void free_fileinfo(struct FileInfo *info) { free(info->path); free(info); } static char* guess_content_type(struct FileInfo *info) { return "text/plain"; /* FIXME */ } static void* xmalloc(size_t sz) { void *p; p = malloc(sz); if (!p) log_exit("failed to allocate memory"); return p; } static void log_exit(const char *fmt, ...) { va_list ap; va_start(ap, fmt); if (debug_mode) { vfprintf(stderr, fmt, ap); fputc('\n', stderr); } else { vsyslog(LOG_ERR, fmt, ap); } va_end(ap); exit(1); }
the_stack_data/67326631.c
int sizeof_lex = 1 ; int sizeof_ind = 16 ; int sizeof_suff_add = 3478 ; int total_fe_info = 5378 ;
the_stack_data/853109.c
#include <stdio.h> #include <errno.h> void dosform(char *filename); int main(int argc,char *argv[]) { int i; for(i=1; i<argc; i++) { dosform(argv[i]); } } void dosform(char *filename) { char tempname[256]; FILE *file; FILE *tfile; int character; sprintf(tempname,"/tmp/%s",filename); if((file = fopen(filename,"r")) == NULL) { printf(" unable to open original file for input\n"); return; } if((tfile = fopen(tempname,"w")) == NULL) { printf(" unable to open temporary file for output\n"); fclose(file); return; } errno = 0; while((character = fgetc(file)) != EOF) { if(character == 0x0A) { if(fputc(0x0D,tfile) == EOF) { printf(" unable to write to temporary file\n"); fclose(file); fclose(tfile); return; } } if(fputc(character,tfile) == EOF) { printf(" unable to write to temporary file\n"); fclose(file); fclose(tfile); return; } errno = 0; } if(errno != 0) { printf(" error reading from original file\n"); fclose(file); fclose(tfile); return; } fclose(file); fclose(tfile); if((tfile = fopen(tempname,"r")) == NULL) { printf(" unable to open temporary file for input\n"); return; } if((file = fopen(filename,"w")) == NULL) { printf(" unable to open new file for output\n"); fclose(tfile); return; } errno = 0; while((character = fgetc(tfile)) != EOF) { if(fputc(character,file) == EOF) { printf(" unable to write to new file\n"); fclose(file); fclose(tfile); return; } errno = 0; } if(errno != 0) { printf(" error reading from temporary file\n"); fclose(file); fclose(tfile); return; } fclose(file); fclose(tfile); }
the_stack_data/69322.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <CL/cl.h> unsigned char *read_buffer(char *file_name, size_t *size_ptr) { FILE *f; unsigned char *buf; size_t size; /* Open file */ f = fopen(file_name, "rb"); if (!f) return NULL; /* Obtain file size */ fseek(f, 0, SEEK_END); size = ftell(f); fseek(f, 0, SEEK_SET); /* Allocate and read buffer */ buf = malloc(size + 1); fread(buf, 1, size, f); buf[size] = '\0'; /* Return size of buffer */ if (size_ptr) *size_ptr = size; /* Return buffer */ return buf; } void write_buffer(char *file_name, const char *buffer, size_t buffer_size) { FILE *f; /* Open file */ f = fopen(file_name, "w+"); /* Write buffer */ if(buffer) fwrite(buffer, 1, buffer_size, f); /* Close file */ fclose(f); } int main(int argc, char const *argv[]) { /* Get platform */ cl_platform_id platform; cl_uint num_platforms; cl_int ret = clGetPlatformIDs(1, &platform, &num_platforms); if (ret != CL_SUCCESS) { printf("error: call to 'clGetPlatformIDs' failed\n"); exit(1); } printf("Number of platforms: %d\n", num_platforms); printf("platform=%p\n", platform); /* Get platform name */ char platform_name[100]; ret = clGetPlatformInfo(platform, CL_PLATFORM_NAME, sizeof(platform_name), platform_name, NULL); if (ret != CL_SUCCESS) { printf("error: call to 'clGetPlatformInfo' failed\n"); exit(1); } printf("platform.name='%s'\n\n", platform_name); /* Get device */ cl_device_id device; cl_uint num_devices; ret = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &device, &num_devices); if (ret != CL_SUCCESS) { printf("error: call to 'clGetDeviceIDs' failed\n"); exit(1); } printf("Number of devices: %d\n", num_devices); printf("device=%p\n", device); /* Get device name */ char device_name[100]; ret = clGetDeviceInfo(device, CL_DEVICE_NAME, sizeof(device_name), device_name, NULL); if (ret != CL_SUCCESS) { printf("error: call to 'clGetDeviceInfo' failed\n"); exit(1); } printf("device.name='%s'\n", device_name); printf("\n"); /* Create a Context Object */ cl_context context; context = clCreateContext(NULL, 1, &device, NULL, NULL, &ret); if (ret != CL_SUCCESS) { printf("error: call to 'clCreateContext' failed\n"); exit(1); } printf("context=%p\n", context); /* Create a Command Queue Object*/ cl_command_queue command_queue; command_queue = clCreateCommandQueue(context, device, 0, &ret); if (ret != CL_SUCCESS) { printf("error: call to 'clCreateCommandQueue' failed\n"); exit(1); } printf("command_queue=%p\n", command_queue); printf("\n"); /* Program source */ unsigned char *source_code; size_t source_length; /* Read program from 'rhadd_int2int2.cl' */ source_code = read_buffer("rhadd_int2int2.cl", &source_length); /* Create a program */ cl_program program; program = clCreateProgramWithSource(context, 1, (const char **)&source_code, &source_length, &ret); if (ret != CL_SUCCESS) { printf("error: call to 'clCreateProgramWithSource' failed\n"); exit(1); } printf("program=%p\n", program); /* Build program */ ret = clBuildProgram(program, 1, &device, NULL, NULL, NULL); if (ret != CL_SUCCESS ) { size_t size; char *log; /* Get log size */ clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG,0, NULL, &size); /* Allocate log and print */ log = malloc(size); clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG,size, log, NULL); printf("error: call to 'clBuildProgram' failed:\n%s\n", log); /* Free log and exit */ free(log); exit(1); } printf("program built\n"); printf("\n"); /* Create a Kernel Object */ cl_kernel kernel; kernel = clCreateKernel(program, "rhadd_int2int2", &ret); if (ret != CL_SUCCESS) { printf("error: call to 'clCreateKernel' failed\n"); exit(1); } /* Create and allocate host buffers */ size_t num_elem = 10; /* Create and init host side src buffer 0 */ cl_int2 *src_0_host_buffer; src_0_host_buffer = malloc(num_elem * sizeof(cl_int2)); for (int i = 0; i < num_elem; i++) src_0_host_buffer[i] = (cl_int2){{2, 2}}; /* Create and init device side src buffer 0 */ cl_mem src_0_device_buffer; src_0_device_buffer = clCreateBuffer(context, CL_MEM_READ_ONLY, num_elem * sizeof(cl_int2), NULL, &ret); if (ret != CL_SUCCESS) { printf("error: could not create source buffer\n"); exit(1); } ret = clEnqueueWriteBuffer(command_queue, src_0_device_buffer, CL_TRUE, 0, num_elem * sizeof(cl_int2), src_0_host_buffer, 0, NULL, NULL); if (ret != CL_SUCCESS) { printf("error: call to 'clEnqueueWriteBuffer' failed\n"); exit(1); } /* Create and init host side src buffer 1 */ cl_int2 *src_1_host_buffer; src_1_host_buffer = malloc(num_elem * sizeof(cl_int2)); for (int i = 0; i < num_elem; i++) src_1_host_buffer[i] = (cl_int2){{2, 2}}; /* Create and init device side src buffer 1 */ cl_mem src_1_device_buffer; src_1_device_buffer = clCreateBuffer(context, CL_MEM_READ_ONLY, num_elem * sizeof(cl_int2), NULL, &ret); if (ret != CL_SUCCESS) { printf("error: could not create source buffer\n"); exit(1); } ret = clEnqueueWriteBuffer(command_queue, src_1_device_buffer, CL_TRUE, 0, num_elem * sizeof(cl_int2), src_1_host_buffer, 0, NULL, NULL); if (ret != CL_SUCCESS) { printf("error: call to 'clEnqueueWriteBuffer' failed\n"); exit(1); } /* Create host dst buffer */ cl_int2 *dst_host_buffer; dst_host_buffer = malloc(num_elem * sizeof(cl_int2)); memset((void *)dst_host_buffer, 1, num_elem * sizeof(cl_int2)); /* Create device dst buffer */ cl_mem dst_device_buffer; dst_device_buffer = clCreateBuffer(context, CL_MEM_WRITE_ONLY, num_elem *sizeof(cl_int2), NULL, &ret); if (ret != CL_SUCCESS) { printf("error: could not create dst buffer\n"); exit(1); } /* Set kernel arguments */ ret = CL_SUCCESS; ret |= clSetKernelArg(kernel, 0, sizeof(cl_mem), &src_0_device_buffer); ret |= clSetKernelArg(kernel, 1, sizeof(cl_mem), &src_1_device_buffer); ret |= clSetKernelArg(kernel, 2, sizeof(cl_mem), &dst_device_buffer); if (ret != CL_SUCCESS) { printf("error: call to 'clSetKernelArg' failed\n"); exit(1); } /* Launch the kernel */ size_t global_work_size = num_elem; size_t local_work_size = num_elem; ret = clEnqueueNDRangeKernel(command_queue, kernel, 1, NULL, &global_work_size, &local_work_size, 0, NULL, NULL); if (ret != CL_SUCCESS) { printf("error: call to 'clEnqueueNDRangeKernel' failed\n"); exit(1); } /* Wait for it to finish */ clFinish(command_queue); /* Read results from GPU */ ret = clEnqueueReadBuffer(command_queue, dst_device_buffer, CL_TRUE,0, num_elem * sizeof(cl_int2), dst_host_buffer, 0, NULL, NULL); if (ret != CL_SUCCESS) { printf("error: call to 'clEnqueueReadBuffer' failed\n"); exit(1); } /* Dump dst buffer to file */ char dump_file[100]; sprintf((char *)&dump_file, "%s.result", argv[0]); write_buffer(dump_file, (const char *)dst_host_buffer, num_elem * sizeof(cl_int2)); printf("Result dumped to %s\n", dump_file); /* Free host dst buffer */ free(dst_host_buffer); /* Free device dst buffer */ ret = clReleaseMemObject(dst_device_buffer); if (ret != CL_SUCCESS) { printf("error: call to 'clReleaseMemObject' failed\n"); exit(1); } /* Free host side src buffer 0 */ free(src_0_host_buffer); /* Free device side src buffer 0 */ ret = clReleaseMemObject(src_0_device_buffer); if (ret != CL_SUCCESS) { printf("error: call to 'clReleaseMemObject' failed\n"); exit(1); } /* Free host side src buffer 1 */ free(src_1_host_buffer); /* Free device side src buffer 1 */ ret = clReleaseMemObject(src_1_device_buffer); if (ret != CL_SUCCESS) { printf("error: call to 'clReleaseMemObject' failed\n"); exit(1); } /* Release kernel */ ret = clReleaseKernel(kernel); if (ret != CL_SUCCESS) { printf("error: call to 'clReleaseKernel' failed\n"); exit(1); } /* Release program */ ret = clReleaseProgram(program); if (ret != CL_SUCCESS) { printf("error: call to 'clReleaseProgram' failed\n"); exit(1); } /* Release command queue */ ret = clReleaseCommandQueue(command_queue); if (ret != CL_SUCCESS) { printf("error: call to 'clReleaseCommandQueue' failed\n"); exit(1); } /* Release context */ ret = clReleaseContext(context); if (ret != CL_SUCCESS) { printf("error: call to 'clReleaseContext' failed\n"); exit(1); } return 0; }
the_stack_data/24375.c
// Example for parameters void coucou(int hello, int goodbye) { } void boo() {}
the_stack_data/175141874.c
/* Test: Loops */ #include "stdint.h" #include "stdio.h" #include "stdlib.h" #include "string.h" int __attribute__((noinline)) bar(uint16_t x, uint16_t y) { if (x == y * y + 23) { return 1; } else { return 0; } } int foo1(uint16_t *arr) { for (int i = 0; i < arr[0]; i++) { printf(" "); if (arr[1] == 42) { printf(" "); } else { printf(" "); } } } int foo2(uint16_t *arr) { for (int i = 0; i < arr[0]; i++) { for (int j = 0; j < arr[1]; j++) { printf(" "); } for (int j = 0; j < arr[2]; j++) { printf(" "); if (arr[3] == 42) { continue; } else { printf(" "); } } } } int foo3(uint16_t *arr) { switch (arr[0]) { case 3: printf(" "); break; case 6: printf(" "); break; case 7: printf(" "); break; case 9: printf(" "); break; default: printf(" "); break; }; while (arr[2] > 0) { arr[2]--; switch (arr[0]) { case 3: printf(" "); break; case 9: printf(" "); continue; default: printf(" "); break; }; for (int i = 0; i < arr[3]; i++) { printf(" "); } } } int main(int argc, char **argv) { if (argc < 2) return 0; FILE *fp; char buf[255]; size_t ret; fp = fopen(argv[1], "rb"); if (!fp) { printf("st err\n"); return 0; } int len = 20; ret = fread(buf, sizeof *buf, len, fp); fclose(fp); if (ret < len) { printf("input fail \n"); return 0; } uint16_t a[4]; memcpy(&a[0], buf, 2); memcpy(&a[1], buf + 4, 2); memcpy(&a[2], buf + 10, 2); memcpy(&a[3], buf + 15, 2); for (int i = 0; i < a[0]; i++) { if (!bar(a[i], i)) { break; } if (a[2] == 42) { continue; } if (i == 3) { abort(); } } foo1(a); foo2(a); foo3(a); return 0; }
the_stack_data/877894.c
/* { dg-do run } */ /* { dg-options "-O2 -fno-early-inlining -fipa-pta" } */ static int *__attribute__((noinline,noclone)) pass_me (int *p) { return p; } /* When foo is inlined into main we have to make sure to adjust main()s IPA CLOBBERED set according to the decl remappings inlining does. */ static int foo (void) { int a = 0; int *p = pass_me (&a); *p = 1; return a; } extern void abort (void); int main() { if (foo () != 1) abort (); return 0; }
the_stack_data/237641873.c
/* We do not have hardware instructions which do a direct conversion between the 32 and 128 bit DFP types. But we can easily do it in two steps. Older libdfp implementations require this not to call into a lib in order to prevent an endless loop. */ /* { dg-do compile } */ /* { dg-options "-O3 -march=z10 -mzarch" } */ _Decimal32 foo (_Decimal128 a) { return (_Decimal32)a; } _Decimal128 bar (_Decimal32 a) { return (_Decimal128)a; } /* Make sure no library call is emitted. */ /* { dg-final { scan-assembler-not "brasl" } } */
the_stack_data/178265150.c
void recursive_add_num(int *num) { if ((*num) > 199999) return; (*num)++; recursive_add_num(num); } int main() { int num; recursive_add_num(&num); return 0; }
the_stack_data/45451523.c
/* * Copyright 2010 The Native Client Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can * be found in the LICENSE file. */ /* * Stub routine for `getuid' for porting support. */ #include <unistd.h> #include <sys/types.h> #include <errno.h> uid_t getuid(void) { errno = ENOSYS; return -1; }
the_stack_data/133788.c
/* Copyright (C) 1989, 1991, California Institute of Technology. U. S. Government Sponsorship under NASA Contract NAS7-918 is acknowledged. */ /* * $Log: SUN4comp.c,v $ * Revision 1.3 91/07/17 16:15:41 judy * New copyright notice. * * Revision 1.2 91/07/10 10:46:12 steve * Use bcmp system call. * * Revision 1.1 90/08/07 13:36:04 configtw * Initial revision * */ int bytcmp ( a, b, l ) register unsigned char *a, *b; register int l; { return bcmp ( b, a, l ); #if 0 while ( l-- ) { if ( *a < *b ) return ( -1 ); else if ( *a > *b ) return ( 1 ); a++; b++; } return ( 0 ); #endif }
the_stack_data/156393871.c
#include <stdio.h> #include <malloc.h> typedef struct _tree { unsigned long long int data; struct _tree *right; struct _tree *left; } tree; void append(tree **t, unsigned long long int data) { if(*t == NULL) { *t = (tree *)malloc(sizeof(tree)); (*t)->data = data; (*t)->left = NULL; (*t)->right = NULL; } else { if(data > (*t)->data) append(&(*t)->left, data); else append(&(*t)->right, data); } } unsigned long long int subtree(tree *bst, int low) { if((bst->data == low)) { return bst->data; } unsigned long long int tmp = bst->data, x; if(low < bst->data) x = subtree(bst->right, low); else x = subtree(bst->left, low); tmp = (x >= tmp)?x:tmp; return tmp; } int main() { tree *bst = NULL; int len, tmp, low, high; scanf("%d", &len); for(int i=1; i<=len; ++i) { scanf("%d", &tmp); append(&bst, tmp); } scanf("%d %d", &low, &high); long long int left = subtree(bst, low); long long int right = subtree(bst, high); if((left > right) && (left > bst->data)) printf("%lld\n", left); else if((right > left) && (right > bst->data)) printf("%lld\n", right); else printf("%lld\n", bst->data); return 0; }
the_stack_data/59513058.c
// ungetc_ex.c : ungetc() example // ------------------------------------------------------------- #include <stdio.h> // int ungetc( int c, FILE *fp ); #include <stdlib.h> #include <ctype.h> int main() { char file[ ] = "input.dat"; FILE *fp; int c; char numstr[64]; if (( fp = fopen( file, "r" )) == NULL ) fprintf( stderr, "Can't read the file %s\n", file), exit(1); while ( (c = getc(fp)) != EOF ) { if ( isdigit(c) ) // Collect a sequence of digits. { int i = 0; do { numstr[i++] = (char)c; c = getc(fp); }while ( isdigit(c) && i+1 < sizeof(numstr) ); numstr[i] = '\0'; // Terminate the numeral string. /* ... process the numeral string ... */ puts( numstr); if ( ungetc( c, fp) == EOF) // Put back the first non-digit. break; continue; } /* ... process any non-digit characters ... */ } if ( !feof( fp)) fprintf( stderr, "Error processing the file %s\n", file); return 0; }
the_stack_data/132400.c
// PROGRAM-NAME : fibonacci // By sruthi s // PROGRAM-CODE : #include<stdio.h> int main() { int n1=0,n2=1,n3,i,number; printf("Enter the number of elements:"); scanf("%d",&number); printf("\n%d %d",n1,n2);//printing 0 and 1 for(i=2;i<number;++i)//loop starts from 2 because 0 and 1 are already printed { n3=n1+n2; printf(" %d",n3); n1=n2; n2=n3; } return 0; }
the_stack_data/115346.c
#include <stdio.h> #include <stdbool.h> int n,m,t,len; int rowNbr[4] = {-1,0,1,0}; int colNbr[4] = {0,1,0,-1}; //int visited[1000][1000]; // 0 -> not visited , 1 -> visited /*void flush() { for(int a=0;a<1000;a++) { for(int b=0;b<1000;b++) visited[a][b]=0; } }*/ bool dfs(char input[],char arr[][m],int row,int col,int k) { if(input[k]!=arr[row][col]) return false; if(k>=len-1) return true; /*char t = arr[row][col]; arr[row][col] = '#';*/ // visited[row][col] = 1; for(int d=0;d<4;d++) { int new_row = row + rowNbr[d]; int new_col = col + colNbr[d]; if(new_row>=0 && new_row<n && new_col>=0 && new_col<m) { if(dfs(input,arr,new_row,new_col,k+1)) return true; } } return false; } bool search(char input[],char arr[][m]) { for(int i=0;i<n;i++) { //flush(); for(int j=0;j<m;j++) { if(dfs(input,arr,i,j,0)) return true; } } return false; } int main() { scanf("%d %d",&n,&m); char arr[n][m]; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { scanf(" %c",&arr[i][j]); } } scanf("%d",&t); while(t--) { char input[10000]; int lennn; scanf("%s",&input); for(lennn=0;lennn<10000;lennn++) if(input[lennn]=='\0') break; // i - has length len = lennn; if(search(input,arr)) printf("YES \n"); else printf("NO \n"); } return 0; }
the_stack_data/150140713.c
#include <stdio.h> int main() { float celsius,fahrenheit, kelvin; celsius=21; fahrenheit= celsius * 9 / 5 + 32; kelvin = celsius + 273.15f;/* 273.15f is the same 273.15 */ printf("%.2f C = %.2f F = %.2f K\n", celsius, fahrenheit, kelvin);/* %i or %d for integer and %f for float */ }
the_stack_data/132952339.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_ultimate_div_mod.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: akharrou <[email protected]> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/10/25 16:05:12 by akharrou #+# #+# */ /* Updated: 2018/10/25 16:12:52 by akharrou ### ########.fr */ /* */ /* ************************************************************************** */ void ft_ultimate_div_mod(int *a, int *b) { int temp1; temp1 = *a / *b; *b = *a % *b; *a = temp1; }
the_stack_data/9564.c
#include <stdint.h> extern void main(void); void reset_handler(void) { /* jump to C entry point */ main(); } __attribute((section(".isr_vector"))) uint32_t *isr_vectors[] = { 0, (uint32_t *) reset_handler, /* code entry point */ };
the_stack_data/130818.c
//quartz2962_37414/_tests/_group_4/_test_6.c //+1.8768E-306 5 -1.3896E-307 +1.2460E-307 -1.4722E306 -0.0 -1.7470E-322 +1.7072E-307 -1.9009E-307 +1.6022E137 +1.3969E306 +1.8813E34 -1.9422E-99 -1.2666E305 +0.0 -1.2316E-314 +1.5805E-323 +1.7072E208 +1.9220E-307 +1.6811E-306 // /* This is a automatically generated test. Do not modify */ #include <stdio.h> #include <stdlib.h> #include <math.h> void compute(double comp, int var_1,double var_2,double var_3,double var_4,double var_5,double var_6,double var_7,double var_8,double* var_9,double var_10,double var_11,double var_12,double var_13,double var_14,double var_15,double var_16,double var_17,double var_18,double var_19) { double tmp_1 = -0.0; comp += tmp_1 - +0.0 / (-0.0 / var_2 * (-1.2958E-306 + asin(var_3 * +1.2843E17 - +0.0))); if (comp > var_4 * var_5 / (-1.2741E-310 + (+1.1382E305 * (var_6 * var_7)))) { double tmp_2 = -1.6107E305; double tmp_3 = -1.2242E-323 - var_8; comp = tmp_3 - tmp_2 / -1.8314E-317 + (-1.4494E-319 / -1.2734E-311 + -0.0); } for (int i=0; i < var_1; ++i) { comp = sinh(exp((+1.1960E-312 + (-0.0 + (var_10 + var_11))))); comp = -1.8509E-316 - (+1.9042E-307 / +1.3519E115); var_9[i] = var_12 - cosh(+1.7332E-320); comp += var_9[i] * (-0.0 * (var_13 + sinh((var_14 + -1.7608E-316)))); } if (comp < (var_15 / (-1.7258E-230 - (-1.7956E-307 / var_16)))) { comp = -1.3825E83 + var_17 / tanh(fabs((-1.1478E248 / (+1.7477E-311 - var_18 * var_19)))); } printf("%.17g\n", comp); } double* initPointer(double v) { double *ret = (double*) malloc(sizeof(double)*10); for(int i=0; i < 10; ++i) ret[i] = v; return ret; } int main(int argc, char** argv) { /* Program variables */ double tmp_1 = atof(argv[1]); int tmp_2 = atoi(argv[2]); double tmp_3 = atof(argv[3]); double tmp_4 = atof(argv[4]); double tmp_5 = atof(argv[5]); double tmp_6 = atof(argv[6]); double tmp_7 = atof(argv[7]); double tmp_8 = atof(argv[8]); double tmp_9 = atof(argv[9]); double* tmp_10 = initPointer( atof(argv[10]) ); double tmp_11 = atof(argv[11]); double tmp_12 = atof(argv[12]); double tmp_13 = atof(argv[13]); double tmp_14 = atof(argv[14]); double tmp_15 = atof(argv[15]); double tmp_16 = atof(argv[16]); double tmp_17 = atof(argv[17]); double tmp_18 = atof(argv[18]); double tmp_19 = atof(argv[19]); double tmp_20 = atof(argv[20]); compute(tmp_1,tmp_2,tmp_3,tmp_4,tmp_5,tmp_6,tmp_7,tmp_8,tmp_9,tmp_10,tmp_11,tmp_12,tmp_13,tmp_14,tmp_15,tmp_16,tmp_17,tmp_18,tmp_19,tmp_20); return 0; }
the_stack_data/51463.c
int a; void main() { int a; // Global and local variable 'a' name is same int b, c, d; a = 3; c = 5; b = a; a = c; }
the_stack_data/7949954.c
/* vi: set sw=4 ts=4: */ /* * wait4() for uClibc * * Copyright (C) 2000-2006 Erik Andersen <[email protected]> * * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. */ #include <sys/syscall.h> #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED #include <sys/wait.h> #include <sys/resource.h> #define __NR___syscall_wait4 __NR_wait4 static __inline__ _syscall4(int, __syscall_wait4, __kernel_pid_t, pid, int *, status, int, opts, struct rusage *, rusage) pid_t wait4(pid_t pid, int *status, int opts, struct rusage *rusage) { return (__syscall_wait4(pid, status, opts, rusage)); } libc_hidden_def(wait4) #endif
the_stack_data/170452386.c
#include <stdio.h> /* Each of the n elements of array elements, is the address of an * array of n integers. * Return 0 if every integer is between 1 and n^2 and all * n^2 integers are unique, otherwise return 1. */ int check_group(int **elements, int n) { int *first_three = elements[0]; int *second_three = elements[1]; int *last_three = elements[2]; int all_nine[9]; for (int i = 0; i < n; i++) { all_nine[i] = first_three[i]; all_nine[i+3] = second_three[i]; all_nine[i+6] = last_three[i]; } // Check if all integers in array are unique. // Credit for algorithm. // https://www.dreamincode.net/forums/topic/87748-finding-if-elements-in-array-are-distinct/ int l; int k; int ogi_val = 0; int new_val = 0; for (l = 0; l < 9; l++) { ogi_val = all_nine[l]; for (k = l+1; k < 10; k++) { if (ogi_val == all_nine[k]) { new_val = 1; } } } if (new_val == 1) { return 1; } return 0; } /* puzzle is a 9x9 sudoku, represented as a 1D array of 9 pointers * each of which points to a 1D array of 9 integers. * Return 0 if puzzle is a valid sudoku and 1 otherwise. You must * only use check_group to determine this by calling it on * each row, each column and each of the 9 inner 3x3 squares */ int check_regular_sudoku(int **puzzle) { int first_three[3]; int second_three[3]; int last_three[3]; int *arr_ptr[3]; // Uniqueness in rows. int *a_row; // Select a row from the puzzle for (int row_indx = 0; row_indx < 9; row_indx++) { // Assign row to a varialbe for (int count = 0; count < 9; count++) { a_row = puzzle[row_indx]; // Break each row into a 3 columns/ subrows for (int i = 0; i < 9; i++) { if(i<3) { first_three[i%3] = a_row[i]; } if(i>=3 && i<6) { second_three[i%3] = a_row[i]; } if(i>=6 && i<9) { last_three[i%3] = a_row[i]; } } // Add each pointer each sub row // to an array to array of pointers arr_ptr[0] = first_three; arr_ptr[1] = second_three; arr_ptr[2] = last_three; } // Call to check group if all numbers // in row row_index are unique. if(check_group(arr_ptr, 3)) { return 1; } } // Uniqueness in columns. int *a_col; // Select column col_indx in a row for (int col_indx = 0; col_indx < 9; col_indx++) { // Select row at row_indx for (int row_indx = 0; row_indx < 9; row_indx++ ) { a_col = puzzle[row_indx]; if (row_indx < 3) { first_three[row_indx%3] = a_col[col_indx]; } if (row_indx < 6) { second_three[row_indx%3] = a_col[col_indx]; } if (row_indx < 9) { last_three[row_indx%3] = a_col[col_indx]; } } // Add each pointer ro each sub column // to an array to array of pointers arr_ptr[0] = first_three; arr_ptr[1] = second_three; arr_ptr[2] = last_three; // Call to check group if all numbers // in row row_index are unique. if(check_group(arr_ptr, 3)) { return 1; } } //Uniquness in boxes int *a_box1; int *a_box2; int *a_box3; for (int box_indx = 0; box_indx < 9; box_indx++) { if (box_indx < 3) { a_box1 = puzzle[0]; a_box2 = puzzle[1]; a_box3 = puzzle[2]; } if (box_indx >= 3 && box_indx < 6) { a_box1 = puzzle[3]; a_box2 = puzzle[4]; a_box3 = puzzle[5]; } if (box_indx >= 6) { a_box1 = puzzle[6]; a_box2 = puzzle[7]; a_box3 = puzzle[8]; } // Build box at box_indx first_three[0] = a_box1[3*(box_indx%3)]; first_three[1] = a_box1[3*(box_indx%3) + 1]; first_three[2] = a_box1[3*(box_indx%3) + 2]; second_three[0] = a_box2[3*(box_indx%3)]; second_three[1] = a_box2[3*(box_indx%3) + 1]; second_three[2] = a_box2[3*(box_indx%3) + 2]; last_three[0] = a_box3[3*(box_indx%3)]; last_three[1] = a_box3[3*(box_indx%3) + 1]; last_three[2] = a_box3[3*(box_indx%3) + 2]; // Add each pointer to each triplet // in a box an array to array of pointers arr_ptr[0] = first_three; arr_ptr[1] = second_three; arr_ptr[2] = last_three; // Call to check group if all numbers // in row row_index are unique. if(check_group(arr_ptr, 3)) { return 1; } } return 0; }
the_stack_data/76325.c
# include<stdio.h> int main(){ int n, p[n]; scanf("%d",&n); int q[n]; printf("p:%lu and q:%lu",sizeof(p),sizeof(q)); return 0; }
the_stack_data/62637090.c
/* * count_word_v1.c * * 单词计数 */ #include <stdio.h> #include <stdlib.h> #define IN 1 #define OUT 0 int main(int argc, char **argv) { int c, nl, nw, nc, state; state = OUT; nl = nw = nc = 0; while ((c = getchar()) != EOF) { ++nc; if (c == '\n') ++nl; if (c == ' ' || c == '\t' || c == '\n') state = OUT; else if (state == OUT) { state = IN; ++nw; } } printf("%d %d %d\n", nl, nw, nc); return EXIT_SUCCESS; }
the_stack_data/220456042.c
// Check that the new static variables are properly declared void constant_array_scalarization04() { int a[3], b[3]; static int c[3]; b[2] = 1; a[0] = 1; c[1] = 1; a[2] = 1; c[0] = 1; c[2] = 1; b[1] = 1; a[1] = 1; b[0] = 1; }
the_stack_data/1127203.c
#include <stdio.h> #include <string.h> #include <stdlib.h> int main() { char name[512]; char num[512]; char help[512]; char def[512]; char args[512]; char buf[512]; char *defines[512]; int i = 0, max; printf("/* this file is auto generated, edit textevents.in instead! */\n\nstruct text_event te[] = {\n"); while(fgets(name, sizeof(name), stdin)) { name[strlen(name)-1] = 0; fgets(num, sizeof(num), stdin); num[strlen(num)-1] = 0; fgets(help, sizeof(help), stdin); help[strlen(help)-1] = 0; fgets(def, sizeof(def), stdin); def[strlen(def)-1] = 0; fgets(args, sizeof(args), stdin); args[strlen(args)-1] = 0; fgets(buf, sizeof(buf), stdin); printf("\n{\"%s\", %s, %d, 0,\nN_(\"%s\")},\n", name, help, atoi(args), def); defines[i] = strdup (num); i++; } printf("};\n"); fprintf(stderr, "/* this file is auto generated, edit textevents.in instead! */\n\nenum\n{\n"); max = i; i = 0; while (i < max) { if (i + 1 < max) { fprintf(stderr, "\t%s,\t\t%s,\n", defines[i], defines[i+1]); i++; } else fprintf(stderr, "\t%s,\n", defines[i]); i++; } fprintf(stderr, "\tNUM_XP\n};\n"); return 0; }
the_stack_data/96663.c
int mx_sqrt(int x) { for (int i = 1; i <= x / i; ++i) if (i * i == x) return i; return 0; }
the_stack_data/150143883.c
#include <math.h> #include <stdio.h> int nhap(char *s) { int n; printf("Nhap do dai canh thu %s: ", s); scanf("%i", &n); while (n < 0) { printf("Du lieu khong hop le. Vui long nhap do dai canh thu %s: ", s); scanf("%i", &n); } return n; } int chuvi(int a, int b, int c) { return (a + b + c); } float dientich(int a, int b, int c) { float p = (float)(a + b + c) / 2; return (sqrt(p * (p - a) * (p - b) * (p - c))); } void inra(int cv, float dt) { printf("Chu vi cua tam giac tren la %i don vi do dai.\n", cv); printf("Dien tich cua tam giac tren la %f don vi dien tich.\n", dt); } int main() { int a = nhap("nhat"); int b = nhap("hai"); int c = nhap("ba"); inra(chuvi(a, b, c), dientich(a, b, c)); return 0; }
the_stack_data/206394425.c
/* Kenneth Adair K&R pg. 22 Counts the number of occurrences of each digit, of white space characters (blank, tab, newline), and of all other characters. EOF is End of File and is ctrl + d. */ #include <stdio.h> /* count digits, white space, others */ main() { int c, i, nwhite, nother; int ndigit[10]; nwhite = nother = 0; for(i = 0; i < 10; ++i) ndigit[i] = 0; while((c = getchar()) != EOF) if(c >= '0' && c <= '9') ++ndigit[c-'0']; else if(c == ' ' || c == '\n' || c == '\t') ++nwhite; else ++nother; printf("digits ="); for(i = 0; i < 10; ++i) printf(" %d", ndigit[i]); printf(", white space = %d, other = %d\n", nwhite, nother); }
the_stack_data/212643884.c
/* * heimdal3.c: * This file is automatically generated; please do not edit it. */ #include <stdlib.h> static const char * const text[] = { "Test message 1", "Test message 2", 0 }; struct error_table { char const * const * msgs; long base; int n_msgs; }; struct et_list { struct et_list *next; const struct error_table * table; }; extern struct et_list *_et_list; const struct error_table et_h3test_error_table = { text, 43787520L, 2 }; static struct et_list link = { 0, 0 }; void initialize_h3test_error_table_r(struct et_list **list); void initialize_h3test_error_table(void); void initialize_h3test_error_table(void) { initialize_h3test_error_table_r(&_et_list); } /* For Heimdal compatibility */ void initialize_h3test_error_table_r(struct et_list **list) { struct et_list *et, **end; for (end = list, et = *list; et; end = &et->next, et = et->next) if (et->table->msgs == text) return; et = malloc(sizeof(struct et_list)); if (et == 0) { if (!link.table) et = &link; else return; } et->table = &et_h3test_error_table; et->next = 0; *end = et; }
the_stack_data/167331774.c
/* * Write a program that fits the following recipe: * * a. Externally define a name structure template with two members: a string to * hold the first name and a string to hold the second name. * * b. Externally define a student structure template with three members: a name * structure, a grade array to hold three floating-point scores, and a variable * to hold the average of those three scores. * * c. Have the main() function declare an array of CSIZE (with CSIZE = 4) * student structures and initialize the name portions to names of your choice. * Use functions to perform the tasks described in parts d., e., f., and g. * * d. Interactively acquire scores for each student by prompting the user with a * student name and a request for scores. Place the scores in the grade array * portion of the appropriate structure. The required looping can be done in * main() or in the function, as you prefer. * * e. Calculate the average score value for each structure and assign it to the proper member. * * f. Print the information in each structure. * * g. Print the class average for each of the numeric structure members. */ #include <stdio.h> #include <stdlib.h> #include <string.h> #define CSIZE 4 #define MAXLEN 256 struct name { char first[MAXLEN]; char last[MAXLEN]; }; struct student { struct name name; double grade[3]; double avg; }; void get_scores(struct student * inp); void calc_average(struct student * inp); void print_student(struct student * inp); double calc_class_average(struct student inp[], int n, int idx); int main (void) { struct student class[CSIZE] = { {{"Michael", "Scott"}, {90, 95, 100}, 0}, {{"Dwight", "Schrute"}, {80, 85, 90}, 0}, {{"Pam", "Beesly"}, {70, 75, 80}, 0}, {{"Jim", "Halpert"}, {60, 65, 70}, 0}, }; for (int i = 0; i < CSIZE; i++) { calc_average(&class[i]); print_student(&class[i]); } for (int i = 0; i < 3; i++) printf("Class Average on #%d: %lf\n", (i+1), calc_class_average(class, CSIZE, i)); return 0; } void get_scores(struct student * inp) { printf("Enter 3 scores for %s %s: ", inp->name.first, inp->name.last); scanf("%lf %lf %lf", &(inp->grade[0]), &(inp->grade[1]), &(inp->grade[2])); while (getchar() != '\n') continue; return; } void calc_average(struct student * inp) { double tot = 0; for (int i = 0; i < 3; i++) tot += inp->grade[i]; tot = tot / 3; inp->avg = tot; return; } void print_student(struct student * inp) { printf("%s %s\nGrades: %.2lf %.2lf %.2lf\nAverage: %.2lf\n", inp->name.first, inp->name.last, inp->grade[0], inp->grade[1], inp->grade[2], inp->avg ); return; } double calc_class_average(struct student inp[], int n, int idx) { double tot = 0; for (int i = 0; i < n; i++) tot += inp[i].grade[idx]; tot = tot / n; return tot; }
the_stack_data/69269.c
/* * strtol.c -- * * Source code for the "strtol" library procedure. * * Copyright (c) 1988 The Regents of the University of California. * All rights reserved. * * Permission is hereby granted, without written agreement and without * license or royalty fees, to use, copy, modify, and distribute this * software and its documentation for any purpose, provided that the * above copyright notice and the following two paragraphs appear in * all copies of this software. * * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. */ #if !defined(lint) static char rcsid[] = "$Header: /home/vandys/src/utils/rh-3.0-beta/RCS/strtol.c,v 1.2 2011/12/31 02:41:07 vandys Exp $ SPRITE (Berkeley)"; #endif /* not lint */ #include <ctype.h> /* *---------------------------------------------------------------------- * * strtol -- * * Convert an ASCII string into an integer. * * Results: * The return value is the integer equivalent of string. If endPtr * is non-NULL, then *endPtr is filled in with the character * after the last one that was part of the integer. If string * doesn't contain a valid integer value, then zero is returned * and *endPtr is set to string. * * Side effects: * None. * *---------------------------------------------------------------------- */ long int strtol(string, endPtr, base) char *string; /* String of ASCII digits, possibly * preceded by white space. For bases * greater than 10, either lower- or * upper-case digits may be used. */ char **endPtr; /* Where to store address of terminating * character, or NULL. */ int base; /* Base for conversion. Must be less * than 37. If 0, then the base is chosen * from the leading characters of string: * "0x" means hex, "0" means octal, anything * else means decimal. */ { char *p; int result; extern unsigned long strtoul(char *, char **, int); /* * Skip any leading blanks. */ p = string; while (isspace(*p)) { p += 1; } /* * Check for a sign. */ if (*p == '-') { p += 1; result = -(strtoul(p, endPtr, base)); } else { if (*p == '+') { p += 1; } result = strtoul(p, endPtr, base); } if ((result == 0) && (endPtr != 0) && (*endPtr == p)) { *endPtr = string; } return result; }
the_stack_data/853042.c
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> double raiseto(double x,double a) { return(exp(a*log(x))); } int main() { int NI,ndims,niter; double dt, pi = 4.0*atan(1.0), gamma = 1.4; FILE *in, *out; double rho_inf = 1.0, u_inf = 1.0, p_inf = 1.0/gamma; /* default values */ ndims = 1; NI = 64; niter = 1000; dt = 0.001; printf("Reading file \"solver.inp\"...\n"); in = fopen("solver.inp","r"); if (!in) printf("Error: Input file \"solver.inp\" not found. Default values will be used.\n"); else { char word[500]; fscanf(in,"%s",word); if (!strcmp(word, "begin")) { while (strcmp(word, "end")) { fscanf(in,"%s",word); if (!strcmp(word, "ndims")) fscanf(in,"%d",&ndims); else if (!strcmp(word, "size")) fscanf(in,"%d",&NI); else if (!strcmp(word, "n_iter")) fscanf(in,"%d",&niter); else if (!strcmp(word, "dt")) fscanf(in,"%lf",&dt); } } else printf("Error: Illegal format in solver.inp. Crash and burn!\n"); } fclose(in); if (ndims != 1) { printf("ndims is not 1 in solver.inp. Make sure the correct solver.inp file is present.\n"); return(0); } printf("Grid: %d\n",NI); printf("Input maximum wavenumber (typically NI/2): "); int limit; scanf("%d",&limit); printf("Max wavenumber: %d\n",limit); int i,k; double dx = 1.0 / ((double)NI); double tf = ((double)niter) * dt; printf("Final Time: %lf\n",tf); double factor = 0.01; srand(time(NULL)); double *phi = (double*) calloc (limit+1,sizeof(double)); for (k=1; k<=limit; k++) { phi[k] = -pi + 2*pi*(((double) rand()) / ((double) RAND_MAX)); // phi[k] = pi/2.0;; } double *x, *rho,*rhou,*e; x = (double*) calloc (NI, sizeof(double)); rho = (double*) calloc (NI, sizeof(double)); rhou = (double*) calloc (NI, sizeof(double)); e = (double*) calloc (NI, sizeof(double)); for (i = 0; i < NI; i++){ x[i] = -0.5 + i*dx; double RHO,U,P,drho=0; for (k=1; k<=limit; k++) { double Ak = factor * raiseto(((double)k),-5.0/6.0); drho += (Ak * cos(2*pi*((double)k)*(x[i]-u_inf*tf)+phi[k])); } RHO = rho_inf + drho; U = u_inf; P = p_inf; rho[i] = RHO; rhou[i] = RHO*U; e[i] = P/0.4 + 0.5*RHO*U*U; printf("%d: %f\n",i,rho[i]); } out = fopen("exact.inp","w"); for (i = 0; i < NI; i++) fprintf(out,"%1.16E ",x[i]); fprintf(out,"\n"); for (i = 0; i < NI; i++) fprintf(out,"%1.16E ",rho[i]); fprintf(out,"\n"); for (i = 0; i < NI; i++) fprintf(out,"%1.16E ",rhou[i]); fprintf(out,"\n"); for (i = 0; i < NI; i++) fprintf(out,"%1.16E ",e[i]); fprintf(out,"\n"); fclose(out); free(x); free(rho); free(rhou); free(e); x = (double*) calloc (NI, sizeof(double)); rho = (double*) calloc (NI, sizeof(double)); rhou = (double*) calloc (NI, sizeof(double)); e = (double*) calloc (NI, sizeof(double)); for (i = 0; i < NI; i++){ x[i] = -0.5 + i*dx; double RHO,U,P,drho=0; for (k=1; k<=limit; k++) { double Ak = factor * raiseto(((double)k),-5.0/6.0); drho += (Ak * cos(2*pi*((double)k)*(x[i])+phi[k])); } RHO = rho_inf + drho; U = u_inf; P = p_inf; rho[i] = RHO; rhou[i] = RHO*U; e[i] = P/0.4 + 0.5*RHO*U*U; } out = fopen("initial.inp","w"); for (i = 0; i < NI; i++) fprintf(out,"%1.16E ",x[i]); fprintf(out,"\n"); for (i = 0; i < NI; i++) fprintf(out,"%1.16E ",rho[i]); fprintf(out,"\n"); for (i = 0; i < NI; i++) fprintf(out,"%1.16E ",rhou[i]); fprintf(out,"\n"); for (i = 0; i < NI; i++) fprintf(out,"%1.16E ",e[i]); fprintf(out,"\n"); fclose(out); free(x); free(rho); free(rhou); free(e); free(phi); return(0); }
the_stack_data/147316.c
/************************** The fork call basically makes a duplicate of the current process, identical in almost every way The new process (child) gets a different process ID (PID) and has the the PID of the old process (parent) as its parent PID (PPID). Because the two processes are now running exactly the same code, they can tell which is which by the return code of fork: The child gets 0 The parent gets the PID of the child. The exec call is a way to basically replace the entire current process with a new program. It loads the program into the current process space and runs it from the entry point. IE: +--------+ | pid=7 | | ppid=4 | | bash | +--------+ | | calls fork V +--------+ +--------+ | pid=7 | forks | pid=22 | | ppid=4 | ----------> | ppid=7 | | bash | | bash | +--------+ +--------+ | | | waits for pid 22 | calls exec to run ls | V | +--------+ | | pid=22 | | | ppid=7 | | | ls | V +--------+ +--------+ | | pid=7 | | exits | ppid=4 | <---------------+ | bash | +--------+ | | continues V *************************/ #include <sys/types.h> #include <stdio.h> #include <unistd.h> #include <errno.h> #include <sys/wait.h> #include <stdlib.h> int main() { pid_t pid; /* fork a child process */ pid = fork(); if (pid < 0) { /* error occurred */ fprintf(stderr, "Fork Failed"); exit (-1) ; } else if (pid == 0) { /* child process */ execlp("./hello","hello",NULL); printf("hi there !!!! \n"); } /* fork a child process */ pid = fork(); if (pid < 0) { /* error occurred */ fprintf(stderr, "Fork Failed"); exit (-1) ; } else if (pid == 0) { /* child process */ execlp("/bin/pwd","pwd",NULL); } else { /* parent process */ /* parent will wait for the child to complete */ wait(NULL); printf("Child Complete\n"); exit(0); } }
the_stack_data/173576936.c
/// \addtogroup module_scif_osal //@{ #ifdef SENSOR_AHT10 #ifdef SCIF_INCLUDE_OSAL_C_FILE #include <ti/devices/DeviceFamily.h> #include DeviceFamily_constructPath(inc/hw_nvic.h) #include DeviceFamily_constructPath(driverlib/cpu.h) #include <Application/sensor_controller/AHT10/scif_osal_tirtos.h> #include <ti/sysbios/knl/Semaphore.h> #include <ti/sysbios/knl/Clock.h> #include <ti/sysbios/family/arm/m3/Hwi.h> /// MCU wakeup source to be used with the Sensor Controller control READY event, must not conflict with OS #define OSAL_CTRL_READY_MCUWUSEL_WU_EV_INDEX 6 /// MCU wakeup source to be used with the Sensor Controller task ALERT event, must not conflict with OS #define OSAL_TASK_ALERT_MCUWUSEL_WU_EV_INDEX 7 /// The READY interrupt is implemented using INT_AON_AUX_SWEV0 #define INT_SCIF_CTRL_READY INT_AON_AUX_SWEV0 /// The ALERT interrupt is implemented using INT_AON_AUX_SWEV1 #define INT_SCIF_TASK_ALERT INT_AON_AUX_SWEV1 /// Calculates the NVIC register offset for the specified interrupt #define NVIC_OFFSET(i) (((i) - 16) / 32) /// Calculates the bit-vector to be written or compared against for the specified interrupt #define NVIC_BV(i) (1 << ((i - 16) % 32)) // Function prototypes static void osalCtrlReadyIsr(UArg arg); static void osalTaskAlertIsr(UArg arg); /// HWI object for the control READY interrupt static Hwi_Struct hwiCtrlReady; /// HWI object for the task ALERT interrupt static Hwi_Struct hwiTaskAlert; /// Semaphore for control READY waiting static Semaphore_Struct semCtrlReady; /// Has the \ref scifOsalInit() function been called? static volatile bool osalInitDone = false; /** \brief Registers the control READY interrupt * * This registers the \ref osalCtrlReadyIsr() function with the \ref INT_SCIF_CTRL_READY interrupt * vector. * * The interrupt occurs at initial startup, and then after each control request has been serviced by the * Sensor Controller. The interrupt is pending (including source event flag) and disabled while the task * control interface is idle. */ static void osalRegisterCtrlReadyInt(void) { Hwi_Params hwiParams; Hwi_Params_init(&hwiParams); // Do not enable interrupt yet hwiParams.enableInt = false; // Create the HWI object for the control READY interrupt Hwi_construct(&hwiCtrlReady, INT_SCIF_CTRL_READY, osalCtrlReadyIsr, &hwiParams, NULL); } // osalRegisterCtrlReadyInt /** \brief Unregisters the control READY interrupt * * This detaches the \ref osalCtrlReadyIsr() function from the \ref INT_SCIF_CTRL_READY interrupt * vector. */ static void osalUnregisterCtrlReadyInt(void) { // Destroy the HWI object Hwi_destruct(&hwiCtrlReady); } // osalUnregisterCtrlReadyInt /** \brief Enables the control READY interrupt * * This function is called when sending a control REQ event to the Sensor Controller to enable the READY * interrupt. This is done after clearing the event source and then the READY interrupt, using * \ref osalClearCtrlReadyInt(). */ static void osalEnableCtrlReadyInt(void) { Hwi_enableInterrupt(INT_SCIF_CTRL_READY); } // osalEnableCtrlReadyInt /** \brief Disables the control READY interrupt * * This function is called when by the control READY ISR, \ref osalCtrlReadyIsr(), so that the interrupt * is disabled but still pending (including source event flag) while the task control interface is * idle/ready. */ static void osalDisableCtrlReadyInt(void) { Hwi_disableInterrupt(INT_SCIF_CTRL_READY); } // osalDisableCtrlReadyInt /** \brief Clears the task control READY interrupt * * This is done when sending a control request, after clearing the READY source event. */ static void osalClearCtrlReadyInt(void) { Hwi_clearInterrupt(INT_SCIF_CTRL_READY); } // osalClearCtrlReadyInt /** \brief Registers the task ALERT interrupt * * This registers the \ref osalTaskAlertIsr() function with the \ref INT_SCIF_TASK_ALERT interrupt * vector. * * The interrupt occurs whenever a sensor controller task alerts the driver, to request data exchange, * indicate an error condition or that the task has stopped spontaneously. */ static void osalRegisterTaskAlertInt(void) { Hwi_Params hwiParams; Hwi_Params_init(&hwiParams); // Do not enable interrupt yet hwiParams.enableInt = false; // Create HWI object for the task ALERT interrupt Hwi_construct(&hwiTaskAlert, INT_SCIF_TASK_ALERT, osalTaskAlertIsr, &hwiParams, NULL); } // osalRegisterTaskAlertInt /** \brief Unregisters the task ALERT interrupt * * This detaches the \ref osalTaskAlertIsr() function from the \ref INT_SCIF_TASK_ALERT interrupt * vector. */ static void osalUnregisterTaskAlertInt(void) { // Destroy the HWI object Hwi_destruct(&hwiTaskAlert); } // osalUnregisterTaskAlertInt /** \brief Enables the task ALERT interrupt * * The interrupt is enabled at startup. It is disabled upon reception of a task ALERT interrupt and re- * enabled when the task ALERT is acknowledged. */ void scifOsalEnableTaskAlertInt(void) { Hwi_enableInterrupt(INT_SCIF_TASK_ALERT); } // scifOsalEnableTaskAlertInt /** \brief Disables the task ALERT interrupt * * The interrupt is enabled at startup. It is disabled upon reception of a task ALERT interrupt and re- * enabled when the task ALERT is acknowledged. * * Note that there can be increased current consumption in System CPU standby mode if the ALERT * interrupt is disabled, but wake-up is enabled (see \ref scifSetWakeOnAlertInt()). This is because the * wake-up signal will remain asserted until \ref scifAckAlertEvents() has been called for all pending * ALERT events. */ void scifOsalDisableTaskAlertInt(void) { Hwi_disableInterrupt(INT_SCIF_TASK_ALERT); } // scifOsalDisableTaskAlertInt /** \brief Clears the task ALERT interrupt * * This is done when acknowledging the alert, after clearing the ALERT source event. */ static void osalClearTaskAlertInt(void) { Hwi_clearInterrupt(INT_SCIF_TASK_ALERT); } // osalClearTaskAlertInt /** \brief Enters a critical section by disabling hardware interrupts * * \return * Whether interrupts were enabled at the time this function was called */ uint32_t scifOsalEnterCriticalSection(void) { return Hwi_disable(); } // scifOsalEnterCriticalSection /** \brief Leaves a critical section by reenabling hardware interrupts if previously enabled * * \param[in] key * The value returned by the previous corresponding call to \ref scifOsalEnterCriticalSection() */ void scifOsalLeaveCriticalSection(uint32_t key) { Hwi_restore(key); } // scifOsalLeaveCriticalSection /// Stores whether task control non-blocking functions have been locked static volatile bool osalCtrlTaskNblLocked = false; /** \brief Locks use of task control non-blocking functions * * This function is used by the non-blocking task control to allow safe operation from multiple threads. * * The function shall attempt to set the \ref osalCtrlTaskNblLocked flag in a critical section. * Implementing a timeout is optional (the task control's non-blocking behavior is not associated with * this critical section, but rather with completion of the task control request). * * \return * Whether the critical section could be entered (true if entered, false otherwise) */ static bool osalLockCtrlTaskNbl(void) { uint32_t key = Hwi_disable(); if (osalCtrlTaskNblLocked) { Hwi_restore(key); return false; } else { osalCtrlTaskNblLocked = true; Hwi_restore(key); return true; } } // osalLockCtrlTaskNbl /** \brief Unlocks use of task control non-blocking functions * * This function will be called once after a successful \ref osalLockCtrlTaskNbl(). */ static void osalUnlockCtrlTaskNbl(void) { osalCtrlTaskNblLocked = false; } // osalUnlockCtrlTaskNbl /// Stores whether \ref semCtrlReady is being pended on in osalWaitOnCtrlReady() static volatile bool osalWaitOnNblLocked = false; /** \brief Waits until the task control interface is ready/idle * * This indicates that the task control interface is ready for the first request or that the last * request has been completed. * * \param[in] timeoutUs * Minimum timeout, in microseconds * * \return * \ref SCIF_SUCCESS if the last call has completed, otherwise \ref SCIF_NOT_READY (the timeout * expired) or \ref SCIF_ILLEGAL_OPERATION (the OSAL does not allow this function to be called with * non-zero \a timeoutUs from multiple threads of execution). */ static SCIF_RESULT_T osalWaitOnCtrlReady(uint32_t timeoutUs) { SCIF_RESULT_T result; // If ready now ... uint32_t key = Hwi_disable(); if (HWREG(AUX_EVCTL_BASE + AUX_EVCTL_O_EVTOAONFLAGS) & AUX_EVCTL_EVTOAONFLAGS_SWEV0_M) { // Immediate success Hwi_restore(key); result = SCIF_SUCCESS; // If no timeout has been specified ... } else if (timeoutUs == 0) { // Immediate failure Hwi_restore(key); result = SCIF_NOT_READY; // If another osalWaitOnCtrlReady() call is in progress ... } else if (osalWaitOnNblLocked) { // This call to osalWaitOnCtrlReady() has interrupted another call to osalWaitOnCtrlReady() Hwi_restore(key); result = SCIF_ILLEGAL_OPERATION; // Otherwise ... } else { // The control READY interrupt has not yet occurred, so it is safe to reset the semaphore and // pend on it because we know the interrupt will happen. Semaphore_reset(Semaphore_handle(&semCtrlReady), 0); osalWaitOnNblLocked = true; Hwi_restore(key); // Enable wake-up on READY interrupt scifSetMcuwusel(OSAL_CTRL_READY_MCUWUSEL_WU_EV_INDEX, AON_EVENT_MCUWUSEL_WU0_EV_AUX_SWEV0); // Return whether the semaphore was released within the timeout if (Semaphore_pend(Semaphore_handle(&semCtrlReady), timeoutUs / Clock_tickPeriod)) { osalWaitOnNblLocked = false; result = SCIF_SUCCESS; } else { osalWaitOnNblLocked = false; result = SCIF_NOT_READY; } // Disable wake-up on READY interrupt scifSetMcuwusel(OSAL_CTRL_READY_MCUWUSEL_WU_EV_INDEX, AON_EVENT_MCUWUSEL_WU0_EV_NONE); } return result; } // osalWaitOnCtrlReady /// OSAL "TI-RTOS": Application-registered callback function for the task control READY interrupt static SCIF_VFPTR osalIndicateCtrlReadyCallback = NULL; /// OSAL "TI-RTOS": Application-registered callback function for the task ALERT interrupt static SCIF_VFPTR osalIndicateTaskAlertCallback = NULL; /** \brief Called by \ref osalCtrlReadyIsr() to notify the application * * This shall trigger a callback, generate a message/event etc. */ static void osalIndicateCtrlReady(void) { // If the OSAL has been initialized, release the sempahore if (osalInitDone) { Semaphore_post(Semaphore_handle(&semCtrlReady)); } // Call callback function if (osalIndicateCtrlReadyCallback) { osalIndicateCtrlReadyCallback(); } } // osalIndicateCtrlReady /** \brief Called by \ref osalTaskAlertIsr() to notify the application * * This shall trigger a callback, generate a message/event etc. */ static void osalIndicateTaskAlert(void) { if (osalIndicateTaskAlertCallback) { osalIndicateTaskAlertCallback(); } } // osalIndicateTaskAlert /** \brief Sensor Controller READY interrupt service routine * * The ISR simply disables the interrupt and notifies the application. * * The interrupt flag is cleared and reenabled when sending the next task control request (by calling * \ref scifExecuteTasksOnceNbl(), \ref scifStartTasksNbl() or \ref scifStopTasksNbl()). * * \param[in] arg * Unused */ static void osalCtrlReadyIsr(UArg arg) { osalDisableCtrlReadyInt(); osalIndicateCtrlReady(); } // osalCtrlReadyIsr /** \brief Sensor Controller ALERT interrupt service routine * * The ISR disables further interrupt generation and notifies the application. To clear the interrupt * source, the application must call \ref scifClearAlertIntSource. The CPU interrupt flag is cleared and * the interrupt is reenabled when calling \ref scifAckAlertEvents() to generate ACK. * * \param[in] arg * Unused */ static void osalTaskAlertIsr(UArg arg) { scifOsalDisableTaskAlertInt(); osalIndicateTaskAlert(); } // osalTaskAlertIsr /** \brief OSAL "TI-RTOS": Registers the task control READY interrupt callback * * Using this callback is normally optional. See \ref osalIndicateCtrlReady() for details. * * \param[in] callback * Callback function pointer "void func(void)" */ void scifOsalRegisterCtrlReadyCallback(SCIF_VFPTR callback) { osalIndicateCtrlReadyCallback = callback; } // scifOsalRegisterCtrlReadyCallback /** \brief OSAL "TI-RTOS": Registers the task ALERT interrupt callback * * Using this callback is normally required. See \ref osalIndicateTaskAlert() for details. * * \param[in] callback * Callback function pointer "void func(void)" */ void scifOsalRegisterTaskAlertCallback(SCIF_VFPTR callback) { osalIndicateTaskAlertCallback = callback; } // scifOsalRegisterTaskAlertCallback /** \brief OSAL "TI-RTOS": Initializes the OSAL * * This creates a binary semaphore used to wait on the task control interface. * * This function must be called once at startup before using the task control functions: * - \ref scifStartTasksNbl() * - \ref scifStopTasksNbl() * - \ref scifWaitOnNbl() */ void scifOsalInit(void) { // If the OSAL has not yet been initialized ... if (!osalInitDone) { osalInitDone = true; // Create a binary semaphore, initially blocked. Semaphore_Params semParams; Semaphore_Params_init(&semParams); semParams.mode = Semaphore_Mode_BINARY; Semaphore_construct(&semCtrlReady, 0, &semParams); } } // scifOsalInit #endif #endif //@} // Generated by DESKTOP-MMLJVDE at 2021-03-04 21:30:12.252
the_stack_data/61074769.c
// possible deadlock in ovl_write_iter // https://syzkaller.appspot.com/bug?id=5a9a2222721209075f5c34688bbcbb9d0c23d1b3 // status:dup // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include <endian.h> #include <pthread.h> #include <setjmp.h> #include <signal.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/syscall.h> #include <sys/types.h> #include <time.h> #include <unistd.h> #include <linux/futex.h> static __thread int skip_segv; static __thread jmp_buf segv_env; static void segv_handler(int sig, siginfo_t* info, void* ctx) { uintptr_t addr = (uintptr_t)info->si_addr; const uintptr_t prog_start = 1 << 20; const uintptr_t prog_end = 100 << 20; if (__atomic_load_n(&skip_segv, __ATOMIC_RELAXED) && (addr < prog_start || addr > prog_end)) { _longjmp(segv_env, 1); } exit(sig); } static void install_segv_handler(void) { struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_handler = SIG_IGN; syscall(SYS_rt_sigaction, 0x20, &sa, NULL, 8); syscall(SYS_rt_sigaction, 0x21, &sa, NULL, 8); memset(&sa, 0, sizeof(sa)); sa.sa_sigaction = segv_handler; sa.sa_flags = SA_NODEFER | SA_SIGINFO; sigaction(SIGSEGV, &sa, NULL); sigaction(SIGBUS, &sa, NULL); } #define NONFAILING(...) \ { \ __atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); \ if (_setjmp(segv_env) == 0) { \ __VA_ARGS__; \ } \ __atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); \ } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); if (pthread_create(&th, &attr, fn, arg)) exit(1); pthread_attr_destroy(&attr); } typedef struct { int state; } event_t; static void event_init(event_t* ev) { ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { if (ev->state) exit(1); __atomic_store_n(&ev->state, 1, __ATOMIC_RELEASE); syscall(SYS_futex, &ev->state, FUTEX_WAKE | FUTEX_PRIVATE_FLAG); } static void event_wait(event_t* ev) { while (!__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE)) syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, 0); } static int event_isset(event_t* ev) { return __atomic_load_n(&ev->state, __ATOMIC_ACQUIRE); } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; for (;;) { uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, &ts); if (__atomic_load_n(&ev->state, __ATOMIC_RELAXED)) return 1; now = current_time_ms(); if (now - start > timeout) return 0; } } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void loop(void) { int i, call, thread; int collide = 0; again: for (call = 0; call < 9; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); if (collide && (call % 2) == 0) break; event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); if (!collide) { collide = 1; goto again; } } uint64_t r[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { long res; switch (call) { case 0: NONFAILING(memcpy((void*)0x20000140, "./file1", 8)); syscall(__NR_mkdir, 0x20000140, 0); break; case 1: NONFAILING(memcpy((void*)0x20000180, "./file0", 8)); syscall(__NR_mkdir, 0x20000180, 0); break; case 2: NONFAILING(memcpy((void*)0x20000000, "./file0", 8)); NONFAILING(memcpy((void*)0x200000c0, "overlay", 8)); NONFAILING(memcpy((void*)0x20000c40, "upperdir=./file0,lowerdir=./file1,workdir=./file1", 49)); syscall(__NR_mount, 0x400000, 0x20000000, 0x200000c0, 0, 0x20000c40); break; case 3: res = syscall(__NR_pipe, 0x20000240); if (res != -1) { NONFAILING(r[0] = *(uint32_t*)0x20000240); NONFAILING(r[1] = *(uint32_t*)0x20000244); } break; case 4: NONFAILING(memcpy((void*)0x200000c0, "memory.events", 14)); syscall(__NR_openat, 0xffffff9c, 0x200000c0, 0x26e1, 0); break; case 5: NONFAILING(memcpy((void*)0x20000140, "memory.events", 14)); res = syscall(__NR_openat, 0xffffff9c, 0x20000140, 0x7a05, 0x1700); if (res != -1) r[2] = res; break; case 6: syscall(__NR_write, r[1], 0x20000140, 0xfffffc8f); break; case 7: syscall(__NR_splice, r[0], 0, r[2], 0, 0x100000000000a, 7); break; case 8: NONFAILING(memcpy((void*)0x20000280, "./file0", 8)); syscall(__NR_chdir, 0x20000280); break; } } int main(void) { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); install_segv_handler(); loop(); return 0; }
the_stack_data/248581812.c
#include<stdio.h> int main() { //Introduction to Pointers in C: int a; //how much memory allocated depends on data type and compiler //number = 4 bytes // float = 4 bytes // character = 1 byte char c; a = 5; a++; //modifies [a = 5] at that time in time //pointers = variables that store address of another variable int *p; // prints 5 --> put asterick to define pointer p = &a; // p now has address of a and points to it --> get address of it a = 5; // has address of 204 and value of 5 printf("%d\n", p); // 204 printf("%d\n", &a); // 204 because [p = &a] printf("%d\n", &p); // 64 which is the address of p printf("%d\n", *p); // gives value of starting location it points to => deferencing *p = 8; //value at p now modified to 8 printf("%d\n", a); // 8 // p -> address // *p -> value at address }
the_stack_data/20450313.c
#include <stdio.h> /* Usage: cat file_name.txt | a.out */ void symbol_counter() { int c; int p; int t = 0; // \t tab ansii code 9 int nl = 0; // \n newline ansii code 8 int bl = 0; // \n\n blank lines int s = 0; // spaces ansii 32 while ((c = getchar()) != EOF) { switch (c) { case '\n': if (p == '\n') ++bl; ++nl; case '\t': ++t; case 32: ++s; } p = c; } printf("%8s %s\n", "Number", "Symbol"); printf("%8d %s\n", nl, "New lines"); printf("%8d %s\n", t, "Tabs"); printf("%8d %s\n", bl, "Blanks"); printf("%8d %s\n", s, "Spaces"); } void remove_multiple_blanks() { int c, p; while ((c = getchar()) != EOF) { if (c == '\n' && p == '\n') continue; p = c; putchar(c); } } void appear_tabs_and_backslashes() { int c; while((c = getchar()) != EOF) { switch (c) { case '\t': printf("%s", "\\t"); case '\b': printf("%s", "\\b"); case '\\': printf("%s", "\\"); break; default: putchar(c); } } } int main(int argc, char const *argv[]) { // symbol_counter(); // remove_multiple_blanks(); appear_tabs_and_backslashes(); return 0; }
the_stack_data/45451468.c
#define _Noreturn #undef __BLOCKS__ #include <stdio.h> #include <stdlib.h> #include <stdarg.h> #include <ctype.h> #if defined(__GNUC__) || defined(__WATCOMC__) || defined(__WIN32__) #include <time.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #endif #if defined(__unix__) || defined(__APPLE__) #include <utime.h> #endif #if defined(__WIN32__) #define WIN32_LEAN_AND_MEAN #define UNICODE #include <windows.h> #include <io.h> #else #include <unistd.h> #endif typedef int bool; typedef unsigned char byte; typedef unsigned short uint16; typedef unsigned int uint; typedef unsigned int FileSize; typedef long long int64; typedef unsigned long long uint64; #define false 0 #define true 1 #define null ((void *)0) #define MAX_LOCATION 797 #define MAX_FILENAME 274 void __ecereNameSpace__ecere__com__eSystem_Delete(void * memory); void * __ecereNameSpace__ecere__com__eSystem_New0(unsigned int size); void * __ecereNameSpace__ecere__com__eSystem_Renew(void * memory, unsigned int size); void * __ecereNameSpace__ecere__com__eSystem_Renew0(void * memory, unsigned int size); unsigned short * __ecereNameSpace__ecere__sys__UTF8toUTF16(const char * source, int * wordCount); unsigned short * __ecereNameSpace__ecere__sys__UTF8toUTF16Buffer(const char * source, uint16 * dest, int max); char * __ecereNameSpace__ecere__sys__UTF16toUTF8(const uint16 * source); void __ecereNameSpace__ecere__sys__ChangeCh(char * string, char ch1, char ch2); #if defined(__WIN32__) || defined(__WATCOMC__) #include <direct.h> __declspec(dllimport) BOOL WINAPI GetVolumePathName(LPCTSTR lpszFileName,LPTSTR lpszVolumePathName,DWORD cchBufferLength); #else #include <dirent.h> #endif typedef unsigned int FileAttribs; typedef int64 SecSince1970; typedef SecSince1970 TimeStamp; typedef enum { FOM_read = 1, FOM_write, FOM_append, FOM_readWrite, FOM_writeRead, FOM_appendRead } FileOpenMode; typedef enum { unlocked = 0, // LOCK_UN _SH_DENYNO shared = 1, // LOCK_SH _SH_DENYWR exclusive = 2 // LOCK_EX _SH_DENYRW } FileLock; #define isFile 0x0001 #define isArchive 0x0002 #define isHidden 0x0004 #define isReadOnly 0x0008 #define isSystem 0x0010 #define isTemporary 0x0020 #define isDirectory 0x0040 #define isDrive 0x0080 #define isCDROM 0x0100 #define isRemote 0x0200 #define isRemovable 0x0400 #define isServer 0x0800 #define isShare 0x1000 typedef struct { FileAttribs attribs; FileSize size; SecSince1970 accessed; SecSince1970 modified; SecSince1970 created; } FileStats; char * __ecereNameSpace__ecere__sys__GetLastDirectory(const char * string, char * output); bool __ecereNameSpace__ecere__sys__SplitArchivePath(const char * fileName, char * archiveName, char ** archiveFile); #if defined(__WIN32__) && !defined(ECERE_BOOTSTRAP) void __ecereMethod___ecereNameSpace__ecere__sys__EARFileSystem_FixCase(const char * archive, char * name); static BOOL CALLBACK EnumThreadWindowsProc(HWND hwnd, LPARAM lParam) { DWORD pid; if(IsWindowVisible(hwnd) && GetWindowThreadProcessId(hwnd, &pid) && pid == GetCurrentProcessId()) { *(void **)lParam = hwnd; return FALSE; } return TRUE; } bool WinReviveNetworkResource(uint16 * _wfileName) { bool result = false; HWND windowHandle = null; NETRESOURCE nr = { 0 }; nr.dwType = RESOURCETYPE_DISK; nr.lpRemoteName = _wfileName; if(_wfileName[0] != '\\' || _wfileName[1] == '\\') { uint16 volumePathName[MAX_LOCATION]; if(GetVolumePathName(_wfileName, volumePathName, MAX_LOCATION)) { uint16 remoteName[MAX_LOCATION]; DWORD size = MAX_LOCATION; volumePathName[wcslen(volumePathName)-1] = 0; if(WNetGetConnection(volumePathName, remoteName, &size) == ERROR_CONNECTION_UNAVAIL) { nr.lpRemoteName = remoteName; nr.lpLocalName = volumePathName; } else return false; } else return false; } EnumThreadWindows(GetCurrentThreadId(), EnumThreadWindowsProc, (LPARAM)&windowHandle); if(!windowHandle) { EnumWindows(EnumThreadWindowsProc, (LPARAM)&windowHandle); } if(WNetAddConnection3(windowHandle, &nr, null, null, CONNECT_INTERACTIVE|CONNECT_PROMPT) == NO_ERROR) result = true; return result; } TimeStamp Win32FileTimeToTimeStamp(FILETIME * fileTime); void TimeStampToWin32FileTime(TimeStamp t, FILETIME * fileTime); #endif uint FILE_GetSize(FILE * input) { if(input) { struct stat s; int fd = fileno(input); if(!fstat(fd, &s)) return s.st_size; } return 0; } bool FILE_Lock(FILE * input, FILE * output, FileLock type, uint64 start, uint64 length, bool wait) { if(!output && !input) return true; else { #if defined(__WIN32__) int handle = fileno(output ? output : input); HANDLE hFile = (HANDLE)_get_osfhandle(handle); OVERLAPPED overlapped = { 0 }; overlapped.Offset = (uint)(start & 0xFFFFFFFF); overlapped.OffsetHigh = (uint)((start & 0xFFFFFFFF00000000LL) >> 32); if(type == unlocked) return UnlockFileEx(hFile, 0, (uint)(length ? (length & 0xFFFFFFFF) : 0xFFFFFFFF), (uint)(length ? ((length & 0xFFFFFFFF00000000LL) >> 32) : 0xFFFFFFFF), &overlapped) != 0; else return LockFileEx(hFile, ((type == exclusive) ? LOCKFILE_EXCLUSIVE_LOCK : 0) | (wait ? 0 : LOCKFILE_FAIL_IMMEDIATELY), 0, (uint)(length ? (length & 0xFFFFFFFF) : 0xFFFFFFFF), (uint)(length ? ((length & 0xFFFFFFFF00000000LL) >> 32) : 0xFFFFFFFF), &overlapped) != 0; #else struct flock fl; int fd; fl.l_type = (type == unlocked) ? F_UNLCK : ((type == exclusive) ? F_WRLCK : F_RDLCK); fl.l_whence = SEEK_SET; fl.l_start = start; fl.l_len = length; fl.l_pid = getpid(); fd = fileno(output ? output : input); return fcntl(fd, wait ? F_SETLKW : F_SETLK, &fl) != -1; #endif } } void FILE_set_buffered(FILE * input, FILE * output, bool value) { #if !defined(__WIN32__) && !defined(ECERE_BOOTSTRAP) if(input) setvbuf(input, null, value ? _IOFBF : _IONBF, 0); if(output && output != input) setvbuf(output, null, value ? _IOFBF : _IONBF, 0); #endif } FileAttribs FILE_FileExists(const char * fileName) { #ifdef __WIN32__ FileAttribs result = 0; uint attribute = 0; // Initialization isn't actually required here but GCC complains about it. uint16 * _wfileName = __ecereNameSpace__ecere__sys__UTF8toUTF16(fileName, null); if(!strcmp(fileName, "/") || !strcmp(fileName, "\\\\")) { result = (FileAttribs)(isDirectory); } else attribute = GetFileAttributes(_wfileName); #if !defined(ECERE_BOOTSTRAP) if(!result && attribute == 0xFFFFFFFF) { if(WinReviveNetworkResource(_wfileName)) attribute = GetFileAttributes(_wfileName); if(attribute == 0xFFFFFFFF) { if(fileName[0] == '\\' && fileName[1] == '\\') { NETRESOURCE nr = { 0 }; NETRESOURCE * buffer = null; unsigned int size = sizeof(NETRESOURCE); uint16 * dir; nr.dwScope = RESOURCE_GLOBALNET; nr.dwType = RESOURCETYPE_DISK; nr.lpRemoteName = _wfileName; nr.lpProvider = L"Microsoft Windows Network"; buffer = (NETRESOURCE *)__ecereNameSpace__ecere__com__eSystem_New0(size); while(true) { int returnCode = WNetGetResourceInformationW(&nr, buffer, (DWORD *)&size, &dir); if(returnCode == WN_MORE_DATA) buffer = (NETRESOURCE *)__ecereNameSpace__ecere__com__eSystem_Renew0(buffer, size); else { if(returnCode == WN_SUCCESS) { if(!_wcsicmp(buffer->lpRemoteName, _wfileName)) result = (FileAttribs)( isDirectory | isServer ); } break; } } __ecereNameSpace__ecere__com__eSystem_Delete(buffer); } } } #endif if(!result && attribute != 0xFFFFFFFF) { if(attribute & FILE_ATTRIBUTE_DIRECTORY) result = (FileAttribs)( isDirectory ); else result = (FileAttribs)(isFile); } __ecereNameSpace__ecere__com__eSystem_Delete(_wfileName); return result; #else if(!access(fileName, F_OK)) { struct stat s; stat(fileName, &s); return S_ISDIR(s.st_mode) ? (FileAttribs) ( isDirectory ) : (FileAttribs) ( isFile ); } else { // TODO: Check this return (FileAttribs) 0; } #endif } bool FILE_FileGetSize(const char * fileName, FileSize * size) { bool result = false; #if defined(__WIN32__) struct _stat s; uint16 * _wfileName = __ecereNameSpace__ecere__sys__UTF8toUTF16(fileName, null); if(!_wstat(_wfileName, &s)) #else struct stat s; if(!stat(fileName, &s)) #endif { *size = s.st_size; result = true; } #if defined(__WIN32__) __ecereNameSpace__ecere__com__eSystem_Delete(_wfileName); #endif return result; } bool FILE_FileGetStats(const char * fileName, FileStats * stats) { bool result = false; #if defined(__WIN32__) uint16 * _wfileName = __ecereNameSpace__ecere__sys__UTF8toUTF16(fileName, null); struct _stat s; if(!_wstat(_wfileName, &s)) #else struct stat s; if(!stat(fileName, &s)) #endif { stats->size = s.st_size; stats->attribs = (s.st_mode & S_IFDIR) ? ((FileAttribs) (isDirectory)): ((FileAttribs) 0); #if defined(__WIN32__) { HANDLE hFile = CreateFile(_wfileName, 0, FILE_SHARE_READ, null, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, null); if(hFile != INVALID_HANDLE_VALUE) { #if defined(ECERE_BOOTSTRAP) stats->created = 0; stats->accessed = 0; stats->modified = 0; #else FILETIME c, a, m; GetFileTime(hFile, &c, &a, &m); stats->created = Win32FileTimeToTimeStamp(&c); stats->accessed = Win32FileTimeToTimeStamp(&a); stats->modified = Win32FileTimeToTimeStamp(&m); #endif CloseHandle(hFile); } } #else stats->accessed = s.st_atime; // UNIX st_ctime is 'status change' time, not creation time // Marking created as 0, as ctime changes cause unreproducible builds stats->created = 0; stats->modified = s.st_mtime; #endif /* stats->attribs.isArchive = (winFile.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE) ? true : false; stats->attribs.isHidden = (winFile.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) ? true : false; stats->attribs.isReadOnly = (winFile.dwFileAttributes & FILE_ATTRIBUTE_READONLY) ? true : false; stats->attribs.isSystem = (winFile.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) ? true : false; stats->attribs.isTemporary = (winFile.dwFileAttributes & FILE_ATTRIBUTE_TEMPORARY) ? true : false; stats->attribs.isDirectory = (winFile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? true : false; */ result = true; } #if defined(__WIN32__) __ecereNameSpace__ecere__com__eSystem_Delete(_wfileName); #endif return result; } void FILE_FileFixCase(char * file) { #if defined(__WIN32__) #ifndef ECERE_BOOTSTRAP char archive[MAX_LOCATION], * name; if(__ecereNameSpace__ecere__sys__SplitArchivePath(file, archive, &name)) { char fileName[MAX_LOCATION]; strcpy(fileName, name); __ecereMethod___ecereNameSpace__ecere__sys__EARFileSystem_FixCase(archive, fileName); if(archive[0] != ':') FILE_FileFixCase(archive); sprintf(file, "<%s>%s", archive, fileName); } else #endif { int c = 0; char parent[MAX_LOCATION] = ""; // Skip network protocols if(strstr(file, "http://") == file) return; // Copy drive letter to new path if(file[0] && file[1] == ':') { parent[0] = (char)toupper(file[0]); parent[1] = ':'; parent[2] = '\0'; c = 2; } // Copy Microsoft Network string to new path else if(file[0] == '\\' && file[1] == '\\') { parent[0] = parent[1] = '\\'; parent[2] = '\0'; c = 2; } else if(file[0] == '/' && file[1] == '/') { parent[0] = parent[1] = '\\'; parent[2] = '\0'; c = 2; } // Copy Entire Computer to new path else if(file[0] == '/' && !file[1]) { parent[0] = '/'; parent[1] = '\0'; c = 1; } while(file[c]) { // Get next directory char directory[MAX_FILENAME]; int len = 0; char ch; for(;(ch = file[c]) && (ch == '/' || ch == '\\'); c++); for(;(ch = file[c]) && (ch != '/' && ch != '\\'); c++) { if(len < MAX_FILENAME) directory[len++] = ch; } directory[len] = '\0'; // Normal file if(parent[0] != '\\' || parent[1] != '\\' || strstr(parent+2, "\\")) { if(strcmp(directory, "..") && strcmp(directory, ".")) { WIN32_FIND_DATA winFile; uint16 dir[MAX_PATH]; HANDLE handle; __ecereNameSpace__ecere__sys__UTF8toUTF16Buffer(parent, dir, MAX_PATH); if(dir[0]) wcscat(dir, L"\\"); { uint16 * _wdirectory = __ecereNameSpace__ecere__sys__UTF8toUTF16(directory, null); wcscat(dir, _wdirectory); __ecereNameSpace__ecere__com__eSystem_Delete(_wdirectory); } handle = FindFirstFile(dir, &winFile); if(parent[0] || (file[0] == '\\' || file[0] == '/')) strcat(parent, "\\"); if(handle != INVALID_HANDLE_VALUE) { char * utf8 = __ecereNameSpace__ecere__sys__UTF16toUTF8(winFile.cFileName); strcat(parent, utf8); __ecereNameSpace__ecere__com__eSystem_Delete(utf8); FindClose(handle); } else strcat(parent, directory); } else { if(parent[0] || (file[0] == '\\' || file[0] == '/')) strcat(parent, "\\"); strcat(parent, directory); } } #ifndef ECERE_BOOTSTRAP else { // Network server if(parent[2]) { HANDLE handle = 0; DWORD count = 0xFFFFFFFF; DWORD size = 512 * sizeof(NETRESOURCE); NETRESOURCE * buffer = (NETRESOURCE *)__ecereNameSpace__ecere__com__eSystem_New0(size); NETRESOURCE nr = {0}; int c; nr.dwScope = RESOURCE_GLOBALNET; nr.dwType = RESOURCETYPE_DISK; // UNICODE FIX nr.lpRemoteName = __ecereNameSpace__ecere__sys__UTF8toUTF16(parent, null); nr.lpProvider = L"Microsoft Windows Network"; // Server WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_DISK, 0, &nr, &handle); if(handle) { while(true) { int returnCode = WNetEnumResource(handle, &count, buffer, &size); if(returnCode != ERROR_MORE_DATA) break; count = 0xFFFFFFFF; buffer = (NETRESOURCE *)__ecereNameSpace__ecere__com__eSystem_Renew0(buffer, size); } WNetCloseEnum(handle); } else count = 0; for(c = 0; c<count; c++) { char shareName[MAX_FILENAME]; char * remoteName = __ecereNameSpace__ecere__sys__UTF16toUTF8(buffer[c].lpRemoteName); __ecereNameSpace__ecere__sys__GetLastDirectory(remoteName, shareName); __ecereNameSpace__ecere__com__eSystem_Delete(remoteName); if(!strcmpi(directory, shareName)) { strcpy(directory, shareName); break; } } if(c == count) strlwr(directory); __ecereNameSpace__ecere__com__eSystem_Delete(nr.lpRemoteName); __ecereNameSpace__ecere__com__eSystem_Delete(buffer); strcat(parent, "\\"); strcat(parent, directory); } // Network share else { strlwr(directory); directory[0] = (char)toupper(directory[0]); strcat(parent, directory); } } #endif } strcpy(file, parent); } #else __ecereNameSpace__ecere__sys__ChangeCh(file, '\\', '/'); #endif } void FILE_FileOpen(const char * fileName, FileOpenMode mode, FILE ** input, FILE **output) { #if defined(__WIN32__) && !defined(ECERE_BOOTSTRAP) uint16 * _wfileName = __ecereNameSpace__ecere__sys__UTF8toUTF16(fileName, null); /* file.handle = CreateFile(_wfileName, ((mode == FOM_read || mode == FOM_readWrite || mode == FOM_writeRead || mode == FOM_appendRead) ? GENERIC_READ : 0) | ((mode == FOM_write || mode == FOM_append || mode == FOM_readWrite || mode == FOM_writeRead || mode == FOM_appendRead) ? GENERIC_WRITE: 0), FILE_SHARE_READ|FILE_SHARE_WRITE, null, (mode == write || mode == writeRead) ? TRUNCATE_EXISTING : ((mode == read || mode == readWrite) ? OPEN_EXISTING : OPEN_ALWAYS), 0, null); if(file.handle) { int flags; int handle; switch(mode) { case FOM_read: handle = _open_osfhandle((int)file.handle, _O_RDONLY); break; case FOM_write: handle = _open_osfhandle((int)file.handle, _O_WRONLY | _O_CREAT | _O_TRUNC); break; case FOM_append: handle = _open_osfhandle((int)file.handle, _O_WRONLY | _O_CREAT | _O_APPEND); break; case FOM_readWrite: handle = _open_osfhandle((int)file.handle, _O_RDWR); break; case FOM_writeRead: handle = _open_osfhandle((int)file.handle, _O_RDWR | _O_CREAT | _O_TRUNC); break; case FOM_appendRead: handle = _open_osfhandle((int)file.handle, _O_RDWR | _O_APPEND | _O_CREAT); break; } if(handle) { switch(mode) { case FOM_read: *input = _fdopen(handle, "rb"); break; case FOM_write: *output = _fdopen(handle, "wb"); break; case FOM_append: *output = _fdopen(handle, "ab"); break; case FOM_readWrite: *input = *output = _fdopen(handle, "r+b"); break; case FOM_writeRead: *input = *output = _fdopen(handle, "w+b"); break; case FOM_appendRead: *input = *output = _fdopen(handle, "a+b"); break; } } } */ switch(mode) { case FOM_read: *input = _wfopen(_wfileName, L"rb"); break; case FOM_write: *output = _wfopen(_wfileName, L"wb"); break; case FOM_append: *output = _wfopen(_wfileName, L"ab"); break; case FOM_readWrite: *input = *output = _wfopen(_wfileName, L"r+b"); break; case FOM_writeRead: *input = *output = _wfopen(_wfileName, L"w+b"); break; case FOM_appendRead: *input = *output = _wfopen(_wfileName, L"a+b"); break; } if(!mode && WinReviveNetworkResource(_wfileName)) { switch(mode) { case FOM_read: *input = _wfopen(_wfileName, L"rb"); break; case FOM_write: *output = _wfopen(_wfileName, L"wb"); break; case FOM_append: *output = _wfopen(_wfileName, L"ab"); break; case FOM_readWrite: *input = *output = _wfopen(_wfileName, L"r+b"); break; case FOM_writeRead: *input = *output = _wfopen(_wfileName, L"w+b"); break; case FOM_appendRead: *input = *output = _wfopen(_wfileName, L"a+b"); break; } } __ecereNameSpace__ecere__com__eSystem_Delete(_wfileName); #else switch(mode) { case FOM_read: *input = fopen(fileName, "rb"); break; case FOM_write: *output = fopen(fileName, "wb"); break; case FOM_append: *output = fopen(fileName, "ab"); break; case FOM_readWrite: *input = *output = fopen(fileName, "r+b"); break; case FOM_writeRead: *input = *output = fopen(fileName, "w+b"); break; case FOM_appendRead: *input = *output = fopen(fileName, "a+b"); break; } #endif }
the_stack_data/182954402.c
#include <stdio.h> #include <sys/mman.h> #include <fcntl.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> // PMU register info #define PMU_BASE_ADDRESS ( 0x01C25400 ) #define PMU_DVFS_CTRL_REG0 ( 0x00 ) #define PMU_DVFS_CTRL_REG1 ( 0x0004 ) #define PMU_DVFS_CTRL_REG2 ( 0x000C ) #define PMU_DVFS_CTRL_REG3 ( 0x0018 ) #define PMU_DVFS_TIMEOUT_CTRL_REG ( 0x001C) #define PMU_VF_TABLE_REG0 ( 0x0080) #define PMU_VF_TABLE_INDEX_REG ( 0xD0 ) #define PMU_IRQ_STATUS_REG ( 0x44 ) // SID register info #define SID_BASE_ADDRESS ( 0x01c23800 ) static int mem_fd = -1; static void* mem_ptr = 0; static unsigned int mem_offset = 0; int mem_init( int base_address ) { unsigned int pages_size = sysconf(_SC_PAGESIZE); unsigned int page_mask = (~(pages_size-1)); unsigned int addr_start = base_address & page_mask; unsigned int addr_offset = base_address & ~page_mask; /* Open /dev/mem */ if ((mem_fd = open ("/dev/mem", O_RDWR | O_SYNC)) == -1) fprintf(stderr, "Cannot open /dev/mem\n"), exit(1); mem_ptr = mmap ( 0, pages_size*2, PROT_READ|PROT_WRITE, MAP_SHARED, mem_fd, addr_start ); mem_offset = addr_offset; if(mem_ptr == (void *) -1) { printf("Memory map failed. error %i\n", mem_ptr); perror("mmap"); return -1; } return 0; } int mem_close() { if( mem_fd < 0 ) { return -1; } close( mem_fd ); mem_ptr = 0; mem_offset = 0; } int mem_read_register( unsigned int reg, unsigned int* out ) { void *ptr = mem_ptr; if( mem_ptr == (void *) -1 ) return -1; *out = *(unsigned int *)(mem_ptr + mem_offset + reg); return 0; } int mem_write_register( unsigned int reg, unsigned int value ) { void *ptr = mem_ptr; if( mem_ptr == (void *) -1 ) return -1; *(unsigned int *)(mem_ptr + mem_offset + reg) = value; return 0; } int main( int argc, int argv ) { unsigned int value = 0; /*mem_init( SID_BASE_ADDRESS ); mem_read_register( 0x00, &value ); printf("SID_KEY0 = 0x%08X\n", value); mem_read_register( 0x0C, &value ); printf("SID_KEY3 = 0x%08X\n", value); mem_close();*/ mem_init( PMU_BASE_ADDRESS ); mem_write_register( PMU_DVFS_CTRL_REG0, 0x00); mem_read_register( PMU_VF_TABLE_INDEX_REG, &value ); printf("PMU_VF_TABLE_INDEX_REG = 0x%08X\n", value); mem_read_register( PMU_DVFS_CTRL_REG0, &value ); printf("PMU_DVFS_CTRL_REG0 = 0x%08X\n", value); mem_read_register( PMU_VF_TABLE_REG0, &value ); printf("PMU_VF_TABLE_REG0 = 0x%08X\n", value); mem_read_register( PMU_DVFS_CTRL_REG1, &value ); printf("PMU_DVFS_CTRL_REG1 = 0x%08X\n", value); mem_read_register( PMU_DVFS_CTRL_REG2, &value ); printf("PMU_DVFS_CTRL_REG2 = 0x%08X\n", value); mem_read_register( PMU_DVFS_CTRL_REG3, &value ); printf("PMU_DVFS_CTRL_REG3 = 0x%08X\n", value); mem_close(); return 0; }
the_stack_data/237641938.c
#include <stdio.h> #include <stdlib.h> int c(int m, int n) { if (m == n) return 1; if (n == 1) return m; return c(m - 1, n - 1) + c(m - 1, n); } int main() { int m, n; scanf("%d %d", &m, &n); printf("%d", c(m, n)); return 0; }
the_stack_data/623084.c
#include <stdio.h> #include <stdlib.h> #include <math.h> long long int a(long long int x); int main() { long long int m,n; scanf("%lld%lld",&m,&n); if(m==0||n==0) printf("0"); else { long long int l; l=a(m)/(a(n)*a(m-n)); printf("%lld",l); } return 0; } long long int a(long long int x) { long long int i=1,j=1; for(i;i<=x;++i) j*=i; return j; }
the_stack_data/178264393.c
#include <stdio.h> #include <stdlib.h> #include <time.h> #define CLOCKS_TO_MILLISEC(t) (t*1000)/CLOCKS_PER_SEC /* There's not a ton to say about this program. Reading and writing with bin-files has several advantages, speed notwithstanding. The binary data format is essentially identical to how the data is stored in memory, so it's just a matter of copying data from one place to another. As well, converting floating point numbers to text induces some slight roundoff error. There are some drawbacks, of course, mainly to do with safety. Even simple mistakes like reading as a float array a file that has been stored as a double array can potentially render the data unreadable. Worse, it's conceivable that different computers interpret data differently. And since the data is unreadable to a human, it's not like you can open the file and check what's appropriate One compromise is to store the data in binary format, but include an ASCII file with some basic info. Anyway, that was a great big old digression. Enjoy the code, in all its quick-and-dirty glory. */ // This function is just here to confuse you. void initialise(double *arr, int len) { for (int i = 0; i < len; i ++) arr[i] = i; } int main(int narg, char **argv) { clock_t start, ascii_read_timer, ascii_write_timer, bin_read_timer, bin_write_timer; int n = 1e5; double *data, *fromfile; FILE *binfile, *asciifile; data = (double *)malloc(n * sizeof(double)); initialise(data, n); // Write to ASCII file asciifile = fopen("data.txt", "w"); start = clock(); for (int i = 0; i < n; i ++) fprintf(asciifile, "%lf\n", data[i]); ascii_write_timer = clock() - start; fclose(asciifile); // Read from ASCII file asciifile = fopen("data.txt", "r"); fromfile = (double *)malloc(n * sizeof(double)); start = clock(); for (int i = 0; i < n; i ++) fscanf(asciifile,"%lf", &fromfile[i]); ascii_read_timer = clock() - start; fclose(asciifile); free(fromfile); // Write to bin file binfile = fopen("data.bin", "wb"); start = clock(); fwrite(data, sizeof(double), n, binfile); bin_write_timer = clock() - start; fclose(binfile); // Read from bin file fromfile = (double *)malloc(n * sizeof(double)); binfile = fopen("data.bin", "rb"); start = clock(); fread(fromfile, sizeof(double), n, binfile); bin_write_timer = clock() - start; fclose(binfile); free(fromfile); // printf("Time elapsed writing to ASCII file: %lu ms.\n", CLOCKS_TO_MILLISEC(ascii_write_timer)); printf("Time elapsed writing to binary file: %lu ms.\n", CLOCKS_TO_MILLISEC(bin_write_timer)); printf("Time elapsed reading from ASCII file: %lu ms.\n", CLOCKS_TO_MILLISEC(ascii_read_timer)); printf("Time elapsed reading from binary file: %lu ms.\n", CLOCKS_TO_MILLISEC(bin_read_timer)); // And that's it free(data); }
the_stack_data/150140658.c
#define _XOPEN_SOURCE #include <sys/types.h> #include <sys/wait.h> #include <errno.h> #include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <stdbool.h> #include <signal.h> #include <limits.h> #define WAIT_FOR_PROC_DEATH_TIMEOUT 10 #define SEP "---" #ifndef NDEBUG #define DPRINTF(format, ...) fprintf(stderr, "smell-baron: " format "\n", ##__VA_ARGS__) #else #define DPRINTF(...) #endif // used as boolean by signal handlers to tell process it should exit static volatile bool running = true; typedef struct { /* args that form command, sent to execvp */ char **args; /* see -f */ bool watch; /* see -c */ bool configuring; pid_t pid; } Cmd; typedef struct { /* number of commands to run */ int n_cmds; /* all commands (watched and unwatched) */ Cmd *cmds; } ChildProcs; typedef struct { bool signal_everything; } Opts; static int wait_for_requested_commands_to_exit(int n_watch_cmds, Cmd **watch_cmds) { int cmds_left = n_watch_cmds; int error_code = 0; int error_code_idx = INT_MAX; for (;;) { int status; if (! running) return error_code; pid_t waited_pid = waitpid(-1, &status, 0); if (waited_pid == -1) { if (errno == EINTR) { DPRINTF("waitpid interrupted by signal"); } else { DPRINTF("waitpid returned unhandled error state"); } } if (! running) return error_code; // check for pid in list of child pids for (int i = 0; i < n_watch_cmds; ++i) { if (watch_cmds[i]->pid == waited_pid) { if (WIFEXITED(status)) { int exit_status = WEXITSTATUS(status); DPRINTF("process exit with status: %d", exit_status); if (exit_status != 0 && i < error_code_idx) { error_code = exit_status; error_code_idx = i; } } DPRINTF("process exit: %d in command list, %d left", waited_pid, cmds_left - 1); if (--cmds_left == 0) { DPRINTF("all processes exited"); return error_code; } break; } else if (i == n_watch_cmds - 1) { DPRINTF("process exit: %d not in watched commands list", waited_pid); } } } return error_code; } static int alarm_exit_code = 0; static void wait_for_all_processes_to_exit(int error_code) { int status; alarm_exit_code = error_code; for (;;) { if (waitpid(-1, &status, 0) == -1 && errno == ECHILD) return; } } static pid_t run_proc(char **argv) { pid_t pid = fork(); if (pid != 0) return pid; execvp(*argv, argv); fprintf(stderr, "failed to execute `%s'\n", *argv); exit(1); } static void on_signal(int signum) { DPRINTF("got signal %d", signum); running = false; } static void on_alarm(int signum) { DPRINTF("timeout waiting for child processes to die"); exit(alarm_exit_code); } static void perror_die(char *msg) { perror(msg); exit(1); } static void install_term_and_int_handlers() { struct sigaction sa; sa.sa_handler = on_signal; sa.sa_flags = 0; sigemptyset(&sa.sa_mask); if (sigaction(SIGINT, &sa, NULL)) perror_die("could not catch SIGINT"); if (sigaction(SIGTERM, &sa, NULL)) perror_die("could not catch SIGTERM"); sa.sa_handler = on_alarm; if (sigaction(SIGALRM, &sa, NULL)) perror_die("could not catch SIGALRM"); } static void remove_term_and_int_handlers() { struct sigaction sa; sa.sa_handler = SIG_IGN; sa.sa_flags = 0; sigemptyset(&sa.sa_mask); if (sigaction(SIGINT, &sa, NULL)) return; if (sigaction(SIGTERM, &sa, NULL)) return; } /** * Runs all commands marked with -c and waits for them to exit. */ static void run_configure_cmds(int n_cmds, Cmd *cmds) { int run_configure_cmds = 0; for (int i = 0; i < n_cmds; ++i) { if (! cmds[i].configuring) continue; cmds[i].pid = run_proc(cmds[i].args); ++run_configure_cmds; } if (run_configure_cmds) { DPRINTF("waiting for configuration commands to exit"); int status; for (;;) { if (waitpid(-1, &status, 0) == -1 && errno == ECHILD) break; } DPRINTF("all configuration commands have exited"); } } static void run_cmds(int n_cmds, Cmd *cmds) { for (int i = 0; i < n_cmds; ++i) { if (! cmds[i].configuring) cmds[i].pid = run_proc(cmds[i].args); } } static void parse_cmd_args(Opts *opts, Cmd *cmd, char **arg_it, char **args_end) { int c; optind = 1; // reset global used as pointer by getopt while ((c = getopt(args_end - arg_it, arg_it - 1, "+acf")) != -1) { switch(c) { case 'a': if (getpid() != 1) { fprintf(stderr, "-a can only be used from the init process (a process with pid 1)\n"); exit(1); } opts->signal_everything = true; break; case 'c': cmd->configuring = true; break; case 'f': cmd->watch = true; break; } } if (cmd->configuring && cmd->watch) { DPRINTF("cannot use -c and -w together for a single command"); exit(1); } cmd->args = arg_it + optind - 1; } static void parse_argv(ChildProcs *child_procs, Opts *opts, int argc, char *argv[]) { child_procs->n_cmds = 1; char **args_end = argv + argc; for (char **i = argv + 1; i < args_end; ++i) { if (! strcmp(*i, SEP)) ++child_procs->n_cmds; } child_procs->cmds = calloc(child_procs->n_cmds, sizeof(Cmd)); *opts = (Opts) { .signal_everything = false }; parse_cmd_args(opts, child_procs->cmds, argv + 1, args_end); char **arg_it = child_procs->cmds->args; int cmd_idx = 0; for (; arg_it < args_end; ++arg_it) { if (! strcmp(*arg_it, SEP)) { *arg_it = 0; // replace with null to terminate when passed to execvp if (arg_it + 1 == args_end) { fprintf(stderr, "command must follow `---'\n"); exit(1); } parse_cmd_args(opts, child_procs->cmds + (++cmd_idx), arg_it + 1, args_end); Cmd *cmd = child_procs->cmds + cmd_idx; arg_it = cmd->args - 1; } } } int main(int argc, char *argv[]) { if (argc == 1) { fprintf(stderr, "please supply at least one command to run\n"); return 1; } ChildProcs child_procs; Opts opts; parse_argv(&child_procs, &opts, argc, argv); int n_watch_cmds = 0; for (int i = 0; i < child_procs.n_cmds; ++i) { if (child_procs.cmds[i].watch) ++n_watch_cmds; } // if -f hasn't been used then watch every command if (0 == n_watch_cmds) { for (int i = 0; i < child_procs.n_cmds; ++i) { if (! child_procs.cmds[i].configuring) { ++n_watch_cmds; child_procs.cmds[i].watch = true; } } } Cmd **watch_cmds = calloc(n_watch_cmds, sizeof(Cmd *)); { int watch_cmd_end = 0; for (int i = 0; i < child_procs.n_cmds; ++i) { if (child_procs.cmds[i].watch) watch_cmds[watch_cmd_end++] = child_procs.cmds + i; } } install_term_and_int_handlers(); int error_code; run_configure_cmds(child_procs.n_cmds, child_procs.cmds); if (running) { run_cmds(child_procs.n_cmds, child_procs.cmds); error_code = wait_for_requested_commands_to_exit(n_watch_cmds, watch_cmds); remove_term_and_int_handlers(); alarm(WAIT_FOR_PROC_DEATH_TIMEOUT); kill(opts.signal_everything ? -1 : 0, SIGTERM); wait_for_all_processes_to_exit(error_code); DPRINTF("all processes exited cleanly"); } free(watch_cmds); free(child_procs.cmds); return error_code; }
the_stack_data/132952272.c
#include <stdio.h> int main() { char ch; printf("Enter any character: "); scanf("%c", &ch); if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) { printf("'%c' is alphabet.", ch); } else if(ch%2 == 0) { printf("'%c' is even.", ch); } else if(ch%2 != 0) { printf("'%c' is odd.", ch); } else { printf("'%c' is special character.", ch); } return 0; }
the_stack_data/64201311.c
#include <stdint.h> struct foo { int64_t bar; uint64_t ubar; }; void test(struct foo *f) //@ requires foo_bar(f, _) &*& foo_ubar(f, _); //@ ensures llong_integer(&f->bar, _) &*& u_llong_integer(&f->ubar, _); { }
the_stack_data/53930.c
// read 10 numbers into an array then print the 10 numbers #include <stdio.h> int numbers[10] = { 0 }; int main(void) { int i; i = 0; while (i < 10) { printf("Enter a number: "); scanf("%d", &numbers[i]); i++; } i = 0; while (i < 10) { printf("%d\n", numbers[i]); i++; } return 0; }
the_stack_data/87636717.c
#include <byteswap.h> #include <netinet/in.h> uint16_t ntohs(uint16_t n) { union { int i; char c; } u = {1}; return u.c ? bswap_16(n) : n; }
the_stack_data/64200099.c
#include<stdio.h> #include<omp.h> #include<stdlib.h> #include<time.h> #define n 40000 int main(){ time_t start_time, end_time; //create matrix double ** a; a = (double **)malloc(sizeof(double*)*n); for (int i=0;i<n;i++) { a[i] = (double*) malloc(sizeof(double)*n); } for (int i=0;i<n;i++) { for (int j=0;j<n;j++) { a[i][j] = i + j; } } double * b, * c; b = (double *)malloc(sizeof(double) * n); c = (double *)malloc(sizeof(double) * n); for (int i = 0; i < n; i++){ b[i] = i * 2; c[i] = i; } // Example 1 puts("Example 1"); // Before Interchange time(&start_time); for (int i = 1; i < n/5; i++){ for (int j = 0; j < n/5; j++){ a[i][j] = a[i - 1][j]; } } time(&end_time); printf("Simple Loop: %ld\n", end_time - start_time); // After Interchange time(&start_time); #pragma omp parallel shared(a) { #pragma omp for nowait for (int j = 0; j < n/5; j++){ for (int i = 1; i < n/5; i++){ a[i][j] = a[i - 1][j]; } } } time(&end_time); printf("After Interchange: %ld\n", end_time - start_time); // Example 2 puts("Example 2"); // Before Interchange time(&start_time); for (int i = 1; i < n; i++){ for (int j = 0; j < n; j++){ b[i] = i * 3; c[j] = b[i - 1]; } } time(&end_time); printf("Simple Loop: %ld\n", end_time - start_time); // After Interchange time(&start_time); #pragma omp parallel shared(b, c) { #pragma omp for nowait for (int j = 1; j < n; j++){ for (int i = 1; j < n; j++){ b[i] = i * 3; c[j] = c[i - 1]; } } } time(&end_time); printf("After Interchange: %ld\n", end_time - start_time); // Example 3 puts("Example 3"); // Before Interchange time(&start_time); for (int i = 1; i < n; i++){ for (int j = 0; j < n; j++){ a[j][i] = a[j][i - 1]; } } time(&end_time); printf("Simple Loop: %ld\n", end_time - start_time); // After Interchange time(&start_time); #pragma omp parallel shared(a) { #pragma omp for nowait for (int j = 0; j < n; j++){ for (int i = 1; i < n; i++){ a[j][i] = a[j][i - 1]; } } } time(&end_time); printf("After Interchange: %ld\n", end_time - start_time); }
the_stack_data/59513113.c
#include <stdio.h> #include <errno.h> #include <fcntl.h> #include <string.h> #include <unistd.h> #define BUFFER_LENGTH 256 static char receive[BUFFER_LENGTH]; int main() { char message[BUFFER_LENGTH]; int fd = open("/dev/lkmDevice", O_RDWR); if (fd < 0) { perror("Failed to open the device"); return errno; } printf("Please type your message to the kernel module:\n"); scanf("%[^\n]%*c", message); if (write(fd, message, strlen(message)) < 0) { perror("Failed to write the message to the device"); return errno; } printf("Sent message: %s\n", message); if (read(fd, receive, BUFFER_LENGTH) < 0) { perror("Failed to read the message from the device"); return errno; } printf("Received message: %s\n", receive); close(fd); return 0; }
the_stack_data/114185.c
int* max(int*, int*); int main() { } int* max(int *x, int *y) { if (*x < *y) { return y; } else { return x; } }
the_stack_data/373491.c
extern const unsigned char Pods_CSMobileBase_TestsVersionString[]; extern const double Pods_CSMobileBase_TestsVersionNumber; const unsigned char Pods_CSMobileBase_TestsVersionString[] __attribute__ ((used)) = "@(#)PROGRAM:Pods_CSMobileBase_Tests PROJECT:Pods-1" "\n"; const double Pods_CSMobileBase_TestsVersionNumber __attribute__ ((used)) = (double)1.;
the_stack_data/72013975.c
/* hw11_4 */ #include <stdio.h> #include <stdlib.h> int main(void) { struct time { int hour; int minutes; double second; }start={12,32,25.49},end={15,12,17.53},elapse={0,0,0.0}; printf("start=%2d:%2d:%2.2lf\n",start.hour,start.minutes,start.second); printf("end=%2d:%2d:%2.2lf\n",end.hour,end.minutes,end.second); elapse.second=end.second-start.second; if(elapse.second<0) { elapse.second+=60.0; end.minutes--; } if(elapse.minutes<0) { elapse.minutes+=60; end.hour--; } elapse.minutes=end.minutes-start.minutes; if(elapse.minutes<0) { elapse.minutes+=60; end.hour--; } elapse.hour=end.hour-start.hour; printf("elapse=%2d:%2d:%2.2lf\n",elapse.hour,elapse.minutes,elapse.second); system("pause"); return 0; } /* start=12:32:25.49 end=15:12:17.53 elapse= 2:39:52.04 Press any key to continue . . . */
the_stack_data/34364.c
#include <stdio.h> #include <stdlib.h> struct Node { int data; struct Node *next; }*Head; void create(int A[],int n) { int i; struct Node *t,*last; Head=(struct Node*)malloc(sizeof(struct Node)); Head->data=A[0]; Head->next=Head; last=Head; for(i=1;i<n;i++) { t=(struct Node*)malloc(sizeof(struct Node)); t->data=A[i]; t->next=last->next; last->next=t; last=t; } } void Display(struct Node *h) { do { printf("%d ",h->data); h=h->next; }while(h!=Head); printf("\n"); } void RDisplay(struct Node *h) { static int flag=0; if(h!=Head || flag==0) { flag=1; printf("%d ",h->data); RDisplay(h->next); } flag=0; } int Length(struct Node *p) { int len=0; do { len++; p=p->next; }while(p!=Head); return len; } void Insert(struct Node *p,int index, int x) { struct Node *t; int i; if(index<0 || index > Length(p)) return; if(index==0) { t=(struct Node *)malloc(sizeof(struct Node)); t->data=x; if(Head==NULL) { Head=t; Head->next=Head; } else { while(p->next!=Head)p=p->next; p->next=t; t->next=Head; Head=t; } } else { for(i=0;i<index-1;i++)p=p->next; t=(struct Node *)malloc(sizeof(struct Node)); t->data=x; t->next=p->next; p->next=t; } } int Delete(struct Node *p,int index) { struct Node *q; int i,x; if(index <0 || index >Length(Head)) return -1; if(index==1) { while(p->next!=Head)p=p->next; x=Head->data; if(Head==p) { free(Head); Head=NULL; } else { p->next=Head->next; free(Head); Head=p->next; } } else { for(i=0;i<index-2;i++) p=p->next; q=p->next; p->next=q->next; x=q->data; free(q); } return x; } int main() { int A[]={2,3,4,5,6}; create(A,5); Delete(Head,4); RDisplay(Head); return 0; }
the_stack_data/13422.c
int main(){ int a[2]; a[0] = 1; a[1] = 2; int *p; p = a; return p[0] + p[1]; }
the_stack_data/87638489.c
/*@author: Divyesh Patel *@filename: writer.c *@brief: ASsignment 2: File Operations and Cross Compiler */ #include<stdio.h> #include<syslog.h> #include<sys/types.h> #include<sys/stat.h> #include<fcntl.h> #include<errno.h> #include<unistd.h> #include<string.h> int main(int argc, char* argv[]) { //opens a connection to system logger and uses LOG_USER facility openlog(NULL,0,LOG_USER); //check is 3 arguments are provided or not if(argc!=3) { syslog(LOG_ERR,"Invalid Number of arguments: %d",argc); syslog(LOG_ERR,"1.File Path"); syslog(LOG_ERR,"2.String to be entered in the file"); return 1; } //check if empty string is not passed as filename if(*argv[1]=='\0') { printf("Invalid File name \n"); syslog(LOG_ERR,"Invalid File name"); return 1; } int fd, wrbytes, closestat; //creates a new file or rewrites an existing one fd = creat (argv[1], 0777); //check for errors if file not created if(fd == -1) { syslog(LOG_ERR,"File cannot be created: %s",argv[1]); printf("File not created\n"); return 1; } else { syslog(LOG_DEBUG,"File created successfully: %s",argv[1]); printf("File created successfully\n"); //write to file (fd) wrbytes = write(fd, argv[2], strlen(argv[2])); //check if write fail if(wrbytes == -1) { syslog(LOG_ERR,"Write not completed"); return 1; } syslog(LOG_DEBUG,"Writing %s to %s",argv[2],argv[1]); printf("Writing to %s to %s\n",argv[2],argv[1]); //close fd closestat = close(fd); //check for errors if file failed to close if(closestat == -1) { syslog(LOG_ERR,"File not closed"); return 1; } printf("close status %d\n",closestat); } //close log closelog(); return 0; }
the_stack_data/4821.c
// https://issues.dlang.org/show_bug.cgi?id=22607 float x = 0.f + 0.F + 0.l + 0.L; float y = 1.f + 2.F + 3.l + 4.L;
the_stack_data/6386571.c
#include<stdio.h> #include<string.h> int main() { int i,j,T,len,count=0; char str[1000],str_new[1000]; scanf("%d", &T); for(i=0; i<T; i++) { scanf(" %[^\n]", str);//Dhaka is the capital of Bangladesh len = strlen(str); for(i=len-1,j=0; i>=0; i--) { str_new[j] = str[i]; j=j+1; } str_new[j]='\0'; printf("%s\n", str_new); } return 0; }
the_stack_data/90764287.c
/* Generated by CIL v. 1.7.0 */ /* print_CIL_Input is false */ struct _IO_FILE; struct timeval; extern void signal(int sig , void *func ) ; extern float strtof(char const *str , char const *endptr ) ; typedef struct _IO_FILE FILE; extern int atoi(char const *s ) ; extern double strtod(char const *str , char const *endptr ) ; extern int fclose(void *stream ) ; extern void *fopen(char const *filename , char const *mode ) ; extern void abort() ; extern void exit(int status ) ; extern int raise(int sig ) ; extern int fprintf(struct _IO_FILE *stream , char const *format , ...) ; extern int strcmp(char const *a , char const *b ) ; extern int rand() ; extern unsigned long strtoul(char const *str , char const *endptr , int base ) ; void RandomFunc(unsigned char input[1] , unsigned char output[1] ) ; extern int strncmp(char const *s1 , char const *s2 , unsigned long maxlen ) ; extern int gettimeofday(struct timeval *tv , void *tz , ...) ; extern int printf(char const *format , ...) ; int main(int argc , char *argv[] ) ; void megaInit(void) ; extern unsigned long strlen(char const *s ) ; extern long strtol(char const *str , char const *endptr , int base ) ; extern unsigned long strnlen(char const *s , unsigned long maxlen ) ; extern void *memcpy(void *s1 , void const *s2 , unsigned long size ) ; struct timeval { long tv_sec ; long tv_usec ; }; extern void *malloc(unsigned long size ) ; extern int scanf(char const *format , ...) ; void megaInit(void) { { } } void RandomFunc(unsigned char input[1] , unsigned char output[1] ) { unsigned char state[1] ; unsigned char local2 ; unsigned char local1 ; { state[0UL] = (input[0UL] + 914778474UL) * (unsigned char)22; local1 = 0UL; while (local1 < (unsigned char)0) { local2 = 0UL; while (local2 < (unsigned char)0) { if (state[0UL] < local2 + local1) { state[local2] += state[0UL]; } else { state[0UL] *= state[0UL]; } local2 ++; } local1 ++; } output[0UL] = (state[0UL] - 304314215UL) + (unsigned char)127; } } int main(int argc , char *argv[] ) { unsigned char input[1] ; unsigned char output[1] ; int randomFuns_i5 ; unsigned char randomFuns_value6 ; int randomFuns_main_i7 ; { megaInit(); if (argc != 2) { printf("Call this program with %i arguments\n", 1); exit(-1); } else { } randomFuns_i5 = 0; while (randomFuns_i5 < 1) { randomFuns_value6 = (unsigned char )strtoul(argv[randomFuns_i5 + 1], 0, 10); input[randomFuns_i5] = randomFuns_value6; randomFuns_i5 ++; } RandomFunc(input, output); if (output[0] == 26) { printf("You win!\n"); } else { } randomFuns_main_i7 = 0; while (randomFuns_main_i7 < 1) { printf("%u\n", output[randomFuns_main_i7]); randomFuns_main_i7 ++; } } }
the_stack_data/48574184.c
#include <stdio.h> int main(){ while(1){ printf("helloworld\n"); } //return 0; }
the_stack_data/123799.c
a, b; c(d, e, f) { c(f); switch (g()) { case 7: b = a; return c(); case 6: while (d && e) ; return !(d || e); } }
the_stack_data/231392147.c
/********************************** (C) COPYRIGHT ******************************* * File Name : core_riscv.c * Author : WCH * Version : V1.0.1 * Date : 2021/10/28 * Description : CH583 RISC-V Core Peripheral Access Layer Source File * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ #include <stdint.h> /* define compiler specific symbols */ #if defined(__CC_ARM) #define __ASM __asm /*!< asm keyword for ARM Compiler */ #define __INLINE __inline /*!< inline keyword for ARM Compiler */ #elif defined(__ICCARM__) #define __ASM __asm /*!< asm keyword for IAR Compiler */ #define __INLINE inline /*!< inline keyword for IAR Compiler. Only avaiable in High optimization mode! */ #elif defined(__GNUC__) #define __ASM __asm /*!< asm keyword for GNU Compiler */ #define __INLINE inline /*!< inline keyword for GNU Compiler */ #elif defined(__TASKING__) #define __ASM __asm /*!< asm keyword for TASKING Compiler */ #define __INLINE inline /*!< inline keyword for TASKING Compiler */ #endif /** * @brief Return the Floating-Point Accrued Exceptions */ uint32_t __get_FFLAGS(void) { uint32_t result; __ASM volatile("csrr %0," "fflags" : "=r"(result)); return (result); } /** * @brief Set the Floating-Point Accrued Exceptions */ void __set_FFLAGS(uint32_t value) { __ASM volatile("csrw fflags, %0" : : "r"(value)); } /** * @brief Return the Floating-Point Dynamic Rounding Mode */ uint32_t __get_FRM(void) { uint32_t result; __ASM volatile("csrr %0," "frm" : "=r"(result)); return (result); } /** * @brief Set the Floating-Point Dynamic Rounding Mode */ void __set_FRM(uint32_t value) { __ASM volatile("csrw frm, %0" : : "r"(value)); } /** * @brief Return the Floating-Point Control and Status Register */ uint32_t __get_FCSR(void) { uint32_t result; __ASM volatile("csrr %0," "fcsr" : "=r"(result)); return (result); } /** * @brief Set the Floating-Point Control and Status Register */ void __set_FCSR(uint32_t value) { __ASM volatile("csrw fcsr, %0" : : "r"(value)); } /** * @brief Return the Machine Status Register */ uint32_t __get_MSTATUS(void) { uint32_t result; __ASM volatile("csrr %0," "mstatus" : "=r"(result)); return (result); } /** * @brief Set the Machine Status Register */ void __set_MSTATUS(uint32_t value) { __ASM volatile("csrw mstatus, %0" : : "r"(value)); } /** * @brief Return the Machine ISA Register */ uint32_t __get_MISA(void) { uint32_t result; __ASM volatile("csrr %0," "misa" : "=r"(result)); return (result); } /** * @brief Set the Machine ISA Register */ void __set_MISA(uint32_t value) { __ASM volatile("csrw misa, %0" : : "r"(value)); } /** * @brief Return the Machine Interrupt Enable Register */ uint32_t __get_MIE(void) { uint32_t result; __ASM volatile("csrr %0," "mie" : "=r"(result)); return (result); } /** * @brief Set the Machine ISA Register */ void __set_MIE(uint32_t value) { __ASM volatile("csrw mie, %0" : : "r"(value)); } /** * @brief Return the Machine Trap-Vector Base-Address Register */ uint32_t __get_MTVEC(void) { uint32_t result; __ASM volatile("csrr %0," "mtvec" : "=r"(result)); return (result); } /** * @brief Set the Machine Trap-Vector Base-Address Register */ void __set_MTVEC(uint32_t value) { __ASM volatile("csrw mtvec, %0" : : "r"(value)); } /** * @brief Return the Machine Seratch Register */ uint32_t __get_MSCRATCH(void) { uint32_t result; __ASM volatile("csrr %0," "mscratch" : "=r"(result)); return (result); } /** * @brief Set the Machine Seratch Register */ void __set_MSCRATCH(uint32_t value) { __ASM volatile("csrw mscratch, %0" : : "r"(value)); } /** * @brief Return the Machine Exception Program Register */ uint32_t __get_MEPC(void) { uint32_t result; __ASM volatile("csrr %0," "mepc" : "=r"(result)); return (result); } /** * @brief Set the Machine Exception Program Register */ void __set_MEPC(uint32_t value) { __ASM volatile("csrw mepc, %0" : : "r"(value)); } /** * @brief Return the Machine Cause Register */ uint32_t __get_MCAUSE(void) { uint32_t result; __ASM volatile("csrr %0," "mcause" : "=r"(result)); return (result); } /** * @brief Set the Machine Cause Register */ void __set_MCAUSE(uint32_t value) { __ASM volatile("csrw mcause, %0" : : "r"(value)); } /** * @brief Return the Machine Trap Value Register */ uint32_t __get_MTVAL(void) { uint32_t result; __ASM volatile("csrr %0," "mtval" : "=r"(result)); return (result); } /** * @brief Set the Machine Trap Value Register */ void __set_MTVAL(uint32_t value) { __ASM volatile("csrw mtval, %0" : : "r"(value)); } /** * @brief Return the Machine Interrupt Pending Register */ uint32_t __get_MIP(void) { uint32_t result; __ASM volatile("csrr %0," "mip" : "=r"(result)); return (result); } /** * @brief Set the Machine Interrupt Pending Register */ void __set_MIP(uint32_t value) { __ASM volatile("csrw mip, %0" : : "r"(value)); } /** * @brief Return Lower 32 bits of Cycle counter */ uint32_t __get_MCYCLE(void) { uint32_t result; __ASM volatile("csrr %0," "mcycle" : "=r"(result)); return (result); } /** * @brief Set Lower 32 bits of Cycle counter */ void __set_MCYCLE(uint32_t value) { __ASM volatile("csrw mcycle, %0" : : "r"(value)); } /** * @brief Return Upper 32 bits of Cycle counter */ uint32_t __get_MCYCLEH(void) { uint32_t result; __ASM volatile("csrr %0," "mcycleh" : "=r"(result)); return (result); } /** * @brief Set Upper 32 bits of Cycle counter */ void __set_MCYCLEH(uint32_t value) { __ASM volatile("csrw mcycleh, %0" : : "r"(value)); } /** * @brief Return Lower 32 bits of Instructions-retired counter */ uint32_t __get_MINSTRET(void) { uint32_t result; __ASM volatile("csrr %0," "minstret" : "=r"(result)); return (result); } /** * @brief Set Lower 32 bits of Instructions-retired counter */ void __set_MINSTRET(uint32_t value) { __ASM volatile("csrw minstret, %0" : : "r"(value)); } /** * @brief Return Upper 32 bits of Instructions-retired counter */ uint32_t __get_MINSTRETH(void) { uint32_t result; __ASM volatile("csrr %0," "minstreth" : "=r"(result)); return (result); } /** * @brief Set Upper 32 bits of Instructions-retired counter */ void __set_MINSTRETH(uint32_t value) { __ASM volatile("csrw minstreth, %0" : : "r"(value)); } /** * @brief Return Vendor ID Register */ uint32_t __get_MVENDORID(void) { uint32_t result; __ASM volatile("csrr %0," "mvendorid" : "=r"(result)); return (result); } /** * @brief Return Machine Architecture ID Register */ uint32_t __get_MARCHID(void) { uint32_t result; __ASM volatile("csrr %0," "marchid" : "=r"(result)); return (result); } /** * @brief Return Machine Implementation ID Register */ uint32_t __get_MIMPID(void) { uint32_t result; __ASM volatile("csrr %0," "mimpid" : "=r"(result)); return (result); } /** * @brief Return Hart ID Register */ uint32_t __get_MHARTID(void) { uint32_t result; __ASM volatile("csrr %0," "mhartid" : "=r"(result)); return (result); }
the_stack_data/57949842.c
/* */ #include <stddef.h> int main(void){return 0;}
the_stack_data/122411.c
#include <stdio.h> #include <string.h> double pi() { return 3.14159265; } int one() { return 1; } int main(int argc, char *argv[]) { printf("How did you call this program: %s\n", argv[0]); // argv[0] = 0th argument of the calling command if (argc >= 2) { printf("First argument: %s\n", argv[1]); // argv[1] = first argument if (argc >= 3) { printf("Second argument: %s\n", argv[2]); // argv[2] = second argument } } // let's just show args because why not lol printf("Command result: "); if (strcmp(argv[0], "pi") == 0 || strcmp(argv[0], "./pi") == 0) { printf("%f\n", pi()); } else if (strcmp(argv[0], "one") == 0 || strcmp(argv[0], "./one") == 0) { printf("%d\n", one()); } else { printf("%s is unknown\n", argv[0]); } // here we just give function results using 0th argument return 0; }
the_stack_data/162644411.c
extern void __VERIFIER_error() __attribute__ ((__noreturn__)); void __VERIFIER_assert(int cond) { if(!(cond)) { ERROR: __VERIFIER_error(); } } #define SIZE 100 // implements a set and checks that the insert and remove function maintain the structure int insert( int set [] , int size , int value ) { set[ size ] = value; return size + 1; } int elem_exists( int set [ ] , int size , int value ) { int i; for ( i = 0 ; i < size ; i++ ) { if ( set[ i ] == value ) return 1; } return 0; } int main( ) { int n = 0; int set[ SIZE ]; // this is trivial int x; int y; for ( x = 0 ; x < n ; x++ ) { for ( y = x + 1 ; y < n ; y++ ) { __VERIFIER_assert( set[ x ] != set[ y ] ); } } // we have an array of values to insert int values[ SIZE ]; // insert them in the array -- note that nothing ensures that values is not containing duplicates! int v; for ( v = 0 ; v < SIZE ; v++ ) { // check if the element exists, if not insert it. if ( !elem_exists( set , n , values[ v ] ) ) { // parametes are passed by reference n = insert( set , n , values[ v ] ); } } // this is not trivial! for ( x = 0 ; x < n ; x++ ) { for ( y = x + 1 ; y < n ; y++ ) { __VERIFIER_assert( set[ x ] != set[ y ] ); } } return 0; }
the_stack_data/105357.c
#include <stdio.h> int fact(int n) { int f=1; for(int i=2;i<=n;i++) f=f*i; return f; } int main() { int n; scanf("%d",&n); //int s=0; int k=n; int s=0; while(k!=0) { int m=k%10; s+=fact(m); k=k/10; } if(s==n) printf("%d is a Strong Number",n); else printf("\nNot a strong Number "); return 0; }
the_stack_data/86739.c
extern void __VERIFIER_error() __attribute__ ((__noreturn__)); #include "pthread.h" int count = 0; #define assume(e) __VERIFIER_assume(e) #define assert_nl(e) { if(!(e)) { goto ERROR; } } #define assert(e) { if(!(e)) { ERROR: __VERIFIER_error();(void)0; } } void __VERIFIER_atomic_acquire(int * m) { /* reachable */ assume(*m==0); *m = 1; } void __VERIFIER_atomic_release(int * m) { assume(*m==1); *m = 0; } int mutexa = 0; int mutexb = 0; inline void my_thread1() { __VERIFIER_atomic_acquire(&mutexa); count++; count--; __VERIFIER_atomic_release(&mutexa); __VERIFIER_atomic_acquire(&mutexa); count--; count++; __VERIFIER_atomic_release(&mutexa); return; } void* thr1(void* arg) { /* reachable */ while(1) { __VERIFIER_atomic_acquire(&mutexa); /* assert OK */ assert(count >= -1); __VERIFIER_atomic_release(&mutexa); } return 0; /* UNREACHABLE */ } void* thr2(void* arg) { if(/* reachable */ __VERIFIER_nondet_int()) my_thread1(); //else //my_thread2(); /* reachable */ return 0; } int main(void) { pthread_t t; /* reachable */ pthread_create(&t, 0, thr1, 0); while(1) { /* reachable */ pthread_create(&t, 0, thr2, 0); } /* UNREACHABLE */ }
the_stack_data/681583.c
#include <stdio.h> #include <time.h> void merge(int a[],int low,int mid,int high) { int p,q,k=0; p=low; q=mid+1; int b[100000]; int i; for(i=low; i<=high; i++) { if(p>mid) b[k++]=a[q++]; else if(q>high) b[k++]=a[p++]; else if(a[p]>a[q]) b[k++]=a[q++]; else b[k++]=a[p++]; } for(p=0; p<k; p++) a[low++]=b[p]; } void mergeSort(int a[],int low,int high) { int mid; if(low<high) { mid=(low+high)/2; mergeSort(a,low,mid); mergeSort(a,mid+1,high); merge(a,low,mid,high); } } void main() { int n; printf("enter array size\n"); scanf("%d",&n); printf("enter array elements\n"); int i,a[n]; for(i=n; i>0; i--) a[n-i]=i; printf("unsorted array is \n"); for(i=0; i<n; i++) printf("%d",a[i]); clock_t start,end; start=clock(); printf("sorted array is \n"); mergesort(a,0,n-1); end=clock(); for(i=0; i<n; i++) printf("%d",a[i]); float time=(float)(end-start)/CLOCKS_PER_SEC; printf("time takenis = %f",time); }
the_stack_data/1137359.c
/*----------------------------------------------------------------- vprintf.c - formatted output conversion Copyright (C) 1999, Martijn van Balen <aed AT iae.nl> Refactored by - Maarten Brock (2004) This library 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 library 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 library; see the file COPYING. If not, write to the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. As a special exception, if you link this library with other files, some of which are compiled with SDCC, to produce an executable, this library does not by itself cause the resulting executable to be covered by the GNU General Public License. This exception does not however invalidate any other reasons why the executable file might be covered by the GNU General Public License. kio 2014-11-16 split file into separate files for each defined symbol _printf.c _vprintf.c _put_char_to_stdout.c (was static) kio 2014-11-26 removed keyword REENTRANT because functions in the z80 port are always reentrant */ #include <stdarg.h> #include <stdio.h> void put_char_to_stdout (char c, void* p) { p; /*make compiler happy*/ putchar (c); }