file
stringlengths
18
26
data
stringlengths
3
1.04M
the_stack_data/28263049.c
#include<stdio.h> #include<string.h> //didn't write this with a lot of consideration //alot might be hard to get //get to me in case of any difficuties gn int calc11(char isbn[]); int calc13(char isbn[]); int main(){ printf("\t\tProgram to calculate check digit of ISBN\n\n"); printf("Enter 1. For 11 digit ISBN, 2. For 13-dgit ISBN\n\n"); int choice; scanf("%d", &choice); char isbn[20]; printf("Enter the ISBN number : "); fflush(stdin); gets(isbn); if(choice==1) printf("\tCheck digit=%d\n", calc11(isbn)); else if(choice==2) printf("\tCheck digit=%d\n",calc13(isbn)); else printf("No ISBN conversion for these number of digits\n\n"); system("pause"); } int calc11(char isbn[]){ if(strlen(isbn)!=10){ perror("Wrong Number of digits"); return -1; } int sum=0, i=0;; for(;i<strlen(isbn)-1;++i)sum+=(isbn[i]-'0')*(10-i); return 11-sum%11;//sometimes sum%11 } int calc13(char isbn[]){ if(strlen(isbn)!=13){ perror("Wrong Number of digits"); return -2; } int sum=0, i=0;; for(;i<strlen(isbn)-1;++i)sum+=(isbn[i]-'0')*(i%2?3:1); return sum%10;//sometimes 10-sum%10 }
the_stack_data/36074609.c
/* FPR - Fundamentos de Programação Marília Silva | https://maliarte.com.br * Apoie o projeto de educação tecnológica no Brasil * deixe uma estrela e saiba mais no instagram @barbarostecnologicos! MATRIZES Exemplos (apresentação ppt): Dada uma matriz M10x20 de inteiros, desenvolver uma função para cada item a seguir: - Zerar os elementos de uma matriz; - Armazenar o valor 1 em todas as posições da 1ª linha, o número 2 na 2ª, e assim por diante; - Preencher a matriz com números aleatórios (função rand); - Exibir os elementos da matriz (respeitando a configuração linha por linha); - Determinar o número de ocorrências de um número na matriz; - Determinar o número de ocorrências de um número na linha L da matriz. */ //importação de bibliotecas #include <stdio.h> //declaração de constantes #define L 10 #define C 20 //declaração de protótipos void zerarMatriz (int matriz[L][C]); void preencherMatriz1a10 (int matriz[L][C]); void preencherAleatorio (int matriz[L][C]); void exibirMatriz (int matriz[L][C]); int buscarNaMatriz (int matriz[L][C], int numero); int buscarNaLinha (int matriz[L][C], int linha, int numero); //main void main () { //declaração da matriz int m[L][C]; int valor, resp, linha; //teste1: zerando a matriz zerarMatriz (m); exibirMatriz (m); //teste2: preenchendo cada linha com valores fixos (de 1 a 10) preencherMatriz1a10 (m); exibirMatriz (m); //teste3: geração de números aleatórios preencherAleatorio (m); exibirMatriz (m); //teste4: buscar um número na matriz printf ("\n\nEntre com um valor a ser buscado na matriz: "); scanf ("%d", &valor); resp = buscarNaMatriz (m, valor); printf ("\nO numero %d aparece %d vezes na matriz.\n", valor, resp); //teste5: buscar 'valor' em determinada linha da matriz printf ("\n\nAgora, em qual linha da matriz deseja buscar o numero %d? ", valor); scanf ("%d", &linha); resp = buscarNaLinha (m, linha, valor); printf ("\nO numero %d aparece %d vezes na linha %d da matriz.\n", valor, resp, linha); } //implementação das funções //Preencher a matriz com números aleatórios (função rand) void preencherAleatorio (int matriz[L][C]) { //declaração de variáveis int i, j; srand(time(NULL)); for (i=0;i<L;i++) { for (j=0;j<C;j++) { matriz[i][j] = 1 + rand()%100; //gerando números aleatórios no intervalo de 1 a 100 } } } //Exibir os elementos da matriz (respeitando a configuração linha por linha) void exibirMatriz (int matriz[L][C]) { //declaração de variáveis int i, j; printf ("\n\nElementos da matriz:\n"); for (i=0;i<L;i++) { for (j=0;j<C;j++) { printf ("%3d ", matriz[i][j]); } printf ("\n"); } } //Zerar os elementos de uma matriz void zerarMatriz (int matriz[L][C]) { //declaração de variáveis int i, j; for (i=0;i<L;i++) { for (j=0;j<C;j++) { matriz[i][j] = 0; //zerando cada posição da matriz } } } //Armazenar o valor 1 em todas as posições da 1ª linha, o número 2 na 2ª, e assim por diante void preencherMatriz1a10 (int matriz[L][C]) { //declaração de variáveis int i, j; for (i=0;i<L;i++) { for (j=0;j<C;j++) { matriz[i][j] = i+1; } } } //Determinar o número de ocorrências de um número na matriz int buscarNaMatriz (int matriz[L][C], int numero) { //declaração de variáveis int i, j, cont = 0; //percorrendo todas as posições da matriz for (i=0;i<L;i++) { for (j=0;j<C;j++) { //comparando cada elemento da matriz com o valor sendo buscado if (matriz[i][j] == numero) { cont++; } } } //retornando a quantidade de ocorrências do número na matriz return cont; } //Determinar o número de ocorrências de um número na linha L da matriz /* //Esta solução é cara, pois deveria percorrer apenas os elementos da linha, porém acessa todos da matriz int buscarNaLinha (int matriz[L][C], int linha, int numero) { //declaração de variáveis int i, j, cont = 0; //percorrendo todas as posições da matriz for (i=0;i<L;i++) { for (j=0;j<C;j++) { //verificando se estamos na linha desejada if (i == linha) { //comparando cada elemento da matriz com o valor sendo buscado if (matriz[i][j] == numero) { cont++; } } } } //retornando a quantidade de ocorrências do número na matriz return cont; } */ int buscarNaLinha (int matriz[L][C], int linha, int numero) { //declaração de variáveis int j, cont = 0; //percorrendo todas as posições da LINHA desejada for (j=0;j<C;j++) { //comparando cada elemento da matriz com o valor sendo buscado if (matriz[linha][j] == numero) { cont++; } } //retornando a quantidade de ocorrências do número na matriz return cont; }
the_stack_data/350310.c
#include <stdio.h> void butler(void); int fathm_ft(int); int main() { int num; num = 1; printf("I am a simplee\b "); printf("computer.\n"); printf("My favorite number\t is %d because it is first.\n", num); //fathm_ft int feet,fathmos; fathmos = 2; feet = fathm_ft(fathmos); printf("There are %d feet in %d fathmos!\n",feet,fathmos); printf("Yes, I said %d feet!\n", 6 * fathmos); //two_func printf("I will summon the butler function.\n"); butler(); printf("Yes, Bring me some tea and writeable CD-ROMS.\n"); return 0; } void butler (void){ printf("You rang, sir?\n"); } /** * 把英寻转换为英尺 * @param fathoms 英寻 * @return 英尺 */ int fathm_ft(int fathoms){ int feet; feet = 6 * fathoms; return feet; }
the_stack_data/137604.c
/* * Copyright (c) 2009-2013 Xilinx, Inc. All rights reserved. * * Xilinx, Inc. * XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS" AS A * COURTESY TO YOU. BY PROVIDING THIS DESIGN, CODE, OR INFORMATION AS * ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE, APPLICATION OR * STANDARD, XILINX IS MAKING NO REPRESENTATION THAT THIS IMPLEMENTATION * IS FREE FROM ANY CLAIMS OF INFRINGEMENT, AND YOU ARE RESPONSIBLE * FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE FOR YOUR IMPLEMENTATION. * XILINX EXPRESSLY DISCLAIMS ANY WARRANTY WHATSOEVER WITH RESPECT TO * THE ADEQUACY OF THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO * ANY WARRANTIES OR REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE * FROM CLAIMS OF INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE. * */ #if __MICROBLAZE__ || __PPC__ #include "arch/cc.h" #include "platform.h" #include "platform_config.h" #include "xil_cache.h" #include "xparameters.h" #include "xintc.h" #include "xil_exception.h" #ifdef STDOUT_IS_16550 #include "xuartns550_l.h" #endif #include "lwip/tcp.h" void timer_callback() { /* we need to call tcp_fasttmr & tcp_slowtmr at intervals specified by lwIP. * It is not important that the timing is absoluetly accurate. */ static int odd = 1; tcp_fasttmr(); odd = !odd; if (odd) tcp_slowtmr(); } static XIntc intc; void platform_setup_interrupts() { XIntc *intcp; intcp = &intc; XIntc_Initialize(intcp, XPAR_INTC_0_DEVICE_ID); XIntc_Start(intcp, XIN_REAL_MODE); /* Start the interrupt controller */ XIntc_MasterEnable(XPAR_INTC_0_BASEADDR); #ifdef __PPC__ Xil_ExceptionInit(); Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT, (XExceptionHandler)XIntc_DeviceInterruptHandler, (void*) XPAR_INTC_0_DEVICE_ID); #elif __MICROBLAZE__ microblaze_register_handler((XInterruptHandler)XIntc_InterruptHandler, intcp); #endif platform_setup_timer(); #ifdef XPAR_ETHERNET_MAC_IP2INTC_IRPT_MASK /* Enable timer and EMAC interrupts in the interrupt controller */ XIntc_EnableIntr(XPAR_INTC_0_BASEADDR, #ifdef __MICROBLAZE__ PLATFORM_TIMER_INTERRUPT_MASK | #endif XPAR_ETHERNET_MAC_IP2INTC_IRPT_MASK); #endif #ifdef XPAR_INTC_0_LLTEMAC_0_VEC_ID #ifdef __MICROBLAZE__ XIntc_Enable(intcp, PLATFORM_TIMER_INTERRUPT_INTR); #endif XIntc_Enable(intcp, XPAR_INTC_0_LLTEMAC_0_VEC_ID); #endif #ifdef XPAR_INTC_0_AXIETHERNET_0_VEC_ID XIntc_Enable(intcp, PLATFORM_TIMER_INTERRUPT_INTR); XIntc_Enable(intcp, XPAR_INTC_0_AXIETHERNET_0_VEC_ID); #endif #ifdef XPAR_INTC_0_EMACLITE_0_VEC_ID #ifdef __MICROBLAZE__ XIntc_Enable(intcp, PLATFORM_TIMER_INTERRUPT_INTR); #endif XIntc_Enable(intcp, XPAR_INTC_0_EMACLITE_0_VEC_ID); #endif } void enable_caches() { #ifdef __PPC__ Xil_ICacheEnableRegion(CACHEABLE_REGION_MASK); Xil_DCacheEnableRegion(CACHEABLE_REGION_MASK); #elif __MICROBLAZE__ #ifdef XPAR_MICROBLAZE_USE_ICACHE Xil_ICacheEnable(); #endif #ifdef XPAR_MICROBLAZE_USE_DCACHE Xil_DCacheEnable(); #endif #endif } void disable_caches() { Xil_DCacheDisable(); Xil_ICacheDisable(); } void init_platform() { enable_caches(); #ifdef STDOUT_IS_16550 XUartNs550_SetBaud(STDOUT_BASEADDR, XPAR_XUARTNS550_CLOCK_HZ, 9600); XUartNs550_SetLineControlReg(STDOUT_BASEADDR, XUN_LCR_8_DATA_BITS); #endif platform_setup_interrupts(); } void cleanup_platform() { disable_caches(); } #endif
the_stack_data/110142.c
/* * "Optimize" a list of dependencies as spit out by gcc -MD * for the kernel build * =========================================================================== * * Author Kai Germaschewski * Copyright 2002 by Kai Germaschewski <[email protected]> * * This software may be used and distributed according to the terms * of the GNU General Public License, incorporated herein by reference. * * * Introduction: * * gcc produces a very nice and correct list of dependencies which * tells make when to remake a file. * * To use this list as-is however has the drawback that virtually * every file in the kernel includes autoconf.h. * * If the user re-runs make *config, autoconf.h will be * regenerated. make notices that and will rebuild every file which * includes autoconf.h, i.e. basically all files. This is extremely * annoying if the user just changed CONFIG_HIS_DRIVER from n to m. * * So we play the same trick that "mkdep" played before. We replace * the dependency on autoconf.h by a dependency on every config * option which is mentioned in any of the listed prerequisites. * * kconfig populates a tree in include/config/ with an empty file * for each config symbol and when the configuration is updated * the files representing changed config options are touched * which then let make pick up the changes and the files that use * the config symbols are rebuilt. * * So if the user changes his CONFIG_HIS_DRIVER option, only the objects * which depend on "include/config/his/driver.h" will be rebuilt, * so most likely only his driver ;-) * * The idea above dates, by the way, back to Michael E Chastain, AFAIK. * * So to get dependencies right, there are two issues: * o if any of the files the compiler read changed, we need to rebuild * o if the command line given to the compile the file changed, we * better rebuild as well. * * The former is handled by using the -MD output, the later by saving * the command line used to compile the old object and comparing it * to the one we would now use. * * Again, also this idea is pretty old and has been discussed on * kbuild-devel a long time ago. I don't have a sensibly working * internet connection right now, so I rather don't mention names * without double checking. * * This code here has been based partially based on mkdep.c, which * says the following about its history: * * Copyright abandoned, Michael Chastain, <mailto:[email protected]>. * This is a C version of syncdep.pl by Werner Almesberger. * * * It is invoked as * * fixdep <depfile> <target> <cmdline> * * and will read the dependency file <depfile> * * The transformed dependency snipped is written to stdout. * * It first generates a line * * cmd_<target> = <cmdline> * * and then basically copies the .<target>.d file to stdout, in the * process filtering out the dependency on autoconf.h and adding * dependencies on include/config/my/option.h for every * CONFIG_MY_OPTION encountered in any of the prerequisites. * * It will also filter out all the dependencies on *.ver. We need * to make sure that the generated version checksum are globally up * to date before even starting the recursive build, so it's too late * at this point anyway. * * We don't even try to really parse the header files, but * merely grep, i.e. if CONFIG_FOO is mentioned in a comment, it will * be picked up as well. It's not a problem with respect to * correctness, since that can only give too many dependencies, thus * we cannot miss a rebuild. Since people tend to not mention totally * unrelated CONFIG_ options all over the place, it's not an * efficiency problem either. * * (Note: it'd be easy to port over the complete mkdep state machine, * but I don't think the added complexity is worth it) */ #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <fcntl.h> #include <string.h> #include <stdlib.h> #include <stdio.h> #include <ctype.h> static void usage(void) { fprintf(stderr, "Usage: fixdep [-e] <depfile> <target> <cmdline>\n"); fprintf(stderr, " -e insert extra dependencies given on stdin\n"); exit(1); } /* * Print out a dependency path from a symbol name */ static void print_dep(const char *m, int slen, const char *dir) { int c, i; printf(" $(wildcard %s/", dir); for (i = 0; i < slen; i++) { c = m[i]; if (c == '_') c = '/'; else c = tolower(c); putchar(c); } printf(".h) \\\n"); } static void do_extra_deps(void) { char buf[80]; while (fgets(buf, sizeof(buf), stdin)) { int len = strlen(buf); if (len < 2 || buf[len - 1] != '\n') { fprintf(stderr, "fixdep: bad data on stdin\n"); exit(1); } print_dep(buf, len - 1, "include/ksym"); } } struct item { struct item *next; unsigned int len; unsigned int hash; char name[0]; }; #define HASHSZ 256 static struct item *hashtab[HASHSZ]; static unsigned int strhash(const char *str, unsigned int sz) { /* fnv32 hash */ unsigned int i, hash = 2166136261U; for (i = 0; i < sz; i++) hash = (hash ^ str[i]) * 0x01000193; return hash; } /* * Lookup a value in the configuration string. */ static int is_defined_config(const char *name, int len, unsigned int hash) { struct item *aux; for (aux = hashtab[hash % HASHSZ]; aux; aux = aux->next) { if (aux->hash == hash && aux->len == len && memcmp(aux->name, name, len) == 0) return 1; } return 0; } /* * Add a new value to the configuration string. */ static void define_config(const char *name, int len, unsigned int hash) { struct item *aux = malloc(sizeof(*aux) + len); if (!aux) { perror("fixdep:malloc"); exit(1); } memcpy(aux->name, name, len); aux->len = len; aux->hash = hash; aux->next = hashtab[hash % HASHSZ]; hashtab[hash % HASHSZ] = aux; } /* * Record the use of a CONFIG_* word. */ static void use_config(const char *m, int slen) { unsigned int hash = strhash(m, slen); if (is_defined_config(m, slen, hash)) return; define_config(m, slen, hash); print_dep(m, slen, "include/config"); } /* test if s ends in sub */ static int str_ends_with(const char *s, int slen, const char *sub) { int sublen = strlen(sub); if (sublen > slen) return 0; return !memcmp(s + slen - sublen, sub, sublen); } static void parse_config_file(const char *p) { const char *q, *r; const char *start = p; while ((p = strstr(p, "CONFIG_"))) { if (p > start && (isalnum(p[-1]) || p[-1] == '_')) { p += 7; continue; } p += 7; q = p; while (*q && (isalnum(*q) || *q == '_')) q++; if (str_ends_with(p, q - p, "_MODULE")) r = q - 7; else r = q; if (r > p) use_config(p, r - p); p = q; } } static void *read_file(const char *filename) { struct stat st; int fd; char *buf; fd = open(filename, O_RDONLY); if (fd < 0) { fprintf(stderr, "fixdep: error opening file: "); perror(filename); exit(2); } if (fstat(fd, &st) < 0) { fprintf(stderr, "fixdep: error fstat'ing file: "); perror(filename); exit(2); } buf = malloc(st.st_size + 1); if (!buf) { perror("fixdep: malloc"); exit(2); } if (read(fd, buf, st.st_size) != st.st_size) { perror("fixdep: read"); exit(2); } buf[st.st_size] = '\0'; close(fd); return buf; } /* Ignore certain dependencies */ static int is_ignored_file(const char *s, int len) { return str_ends_with(s, len, "include/generated/autoconf.h") || str_ends_with(s, len, "include/generated/autoksyms.h") || str_ends_with(s, len, ".ver"); } /* * Important: The below generated source_foo.o and deps_foo.o variable * assignments are parsed not only by make, but also by the rather simple * parser in scripts/mod/sumversion.c. */ static void parse_dep_file(char *m, const char *target, int insert_extra_deps) { char *p; int is_last, is_target; int saw_any_target = 0; int is_first_dep = 0; void *buf; while (1) { /* Skip any "white space" */ while (*m == ' ' || *m == '\\' || *m == '\n') m++; if (!*m) break; /* Find next "white space" */ p = m; while (*p && *p != ' ' && *p != '\\' && *p != '\n') p++; is_last = (*p == '\0'); /* Is the token we found a target name? */ is_target = (*(p-1) == ':'); /* Don't write any target names into the dependency file */ if (is_target) { /* The /next/ file is the first dependency */ is_first_dep = 1; } else if (!is_ignored_file(m, p - m)) { *p = '\0'; /* * Do not list the source file as dependency, so that * kbuild is not confused if a .c file is rewritten * into .S or vice versa. Storing it in source_* is * needed for modpost to compute srcversions. */ if (is_first_dep) { /* * If processing the concatenation of multiple * dependency files, only process the first * target name, which will be the original * source name, and ignore any other target * names, which will be intermediate temporary * files. */ if (!saw_any_target) { saw_any_target = 1; printf("source_%s := %s\n\n", target, m); printf("deps_%s := \\\n", target); } is_first_dep = 0; } else { printf(" %s \\\n", m); } buf = read_file(m); parse_config_file(buf); free(buf); } if (is_last) break; /* * Start searching for next token immediately after the first * "whitespace" character that follows this token. */ m = p + 1; } if (!saw_any_target) { fprintf(stderr, "fixdep: parse error; no targets found\n"); exit(1); } if (insert_extra_deps) do_extra_deps(); printf("\n%s: $(deps_%s)\n\n", target, target); printf("$(deps_%s):\n", target); } int main(int argc, char *argv[]) { const char *depfile, *target, *cmdline; int insert_extra_deps = 0; void *buf; if (argc == 5 && !strcmp(argv[1], "-e")) { insert_extra_deps = 1; argv++; } else if (argc != 4) usage(); depfile = argv[1]; target = argv[2]; cmdline = argv[3]; printf("cmd_%s := %s\n\n", target, cmdline); buf = read_file(depfile); parse_dep_file(buf, target, insert_extra_deps); free(buf); return 0; }
the_stack_data/12637394.c
/* f2c.h -- Standard Fortran to C header file */ /** barf [ba:rf] 2. "He suggested using FORTRAN, and everybody barfed." - From The Shogakukan DICTIONARY OF NEW ENGLISH (Second edition) */ #ifndef F2C_INCLUDE #define F2C_INCLUDE #include <math.h> #include <stdlib.h> #include <string.h> #include <stdio.h> #include <complex.h> #ifdef complex #undef complex #endif #ifdef I #undef I #endif #if defined(_WIN64) typedef long long BLASLONG; typedef unsigned long long BLASULONG; #else typedef long BLASLONG; typedef unsigned long BLASULONG; #endif #ifdef LAPACK_ILP64 typedef BLASLONG blasint; #if defined(_WIN64) #define blasabs(x) llabs(x) #else #define blasabs(x) labs(x) #endif #else typedef int blasint; #define blasabs(x) abs(x) #endif typedef blasint integer; typedef unsigned int uinteger; typedef char *address; typedef short int shortint; typedef float real; typedef double doublereal; typedef struct { real r, i; } complex; typedef struct { doublereal r, i; } doublecomplex; static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;} static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;} static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;} static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;} #define pCf(z) (*_pCf(z)) #define pCd(z) (*_pCd(z)) typedef int logical; typedef short int shortlogical; typedef char logical1; typedef char integer1; #define TRUE_ (1) #define FALSE_ (0) /* Extern is for use with -E */ #ifndef Extern #define Extern extern #endif /* I/O stuff */ typedef int flag; typedef int ftnlen; typedef int ftnint; /*external read, write*/ typedef struct { flag cierr; ftnint ciunit; flag ciend; char *cifmt; ftnint cirec; } cilist; /*internal read, write*/ typedef struct { flag icierr; char *iciunit; flag iciend; char *icifmt; ftnint icirlen; ftnint icirnum; } icilist; /*open*/ typedef struct { flag oerr; ftnint ounit; char *ofnm; ftnlen ofnmlen; char *osta; char *oacc; char *ofm; ftnint orl; char *oblnk; } olist; /*close*/ typedef struct { flag cerr; ftnint cunit; char *csta; } cllist; /*rewind, backspace, endfile*/ typedef struct { flag aerr; ftnint aunit; } alist; /* inquire */ typedef struct { flag inerr; ftnint inunit; char *infile; ftnlen infilen; ftnint *inex; /*parameters in standard's order*/ ftnint *inopen; ftnint *innum; ftnint *innamed; char *inname; ftnlen innamlen; char *inacc; ftnlen inacclen; char *inseq; ftnlen inseqlen; char *indir; ftnlen indirlen; char *infmt; ftnlen infmtlen; char *inform; ftnint informlen; char *inunf; ftnlen inunflen; ftnint *inrecl; ftnint *innrec; char *inblank; ftnlen inblanklen; } inlist; #define VOID void union Multitype { /* for multiple entry points */ integer1 g; shortint h; integer i; /* longint j; */ real r; doublereal d; complex c; doublecomplex z; }; typedef union Multitype Multitype; struct Vardesc { /* for Namelist */ char *name; char *addr; ftnlen *dims; int type; }; typedef struct Vardesc Vardesc; struct Namelist { char *name; Vardesc **vars; int nvars; }; typedef struct Namelist Namelist; #define abs(x) ((x) >= 0 ? (x) : -(x)) #define dabs(x) (fabs(x)) #define f2cmin(a,b) ((a) <= (b) ? (a) : (b)) #define f2cmax(a,b) ((a) >= (b) ? (a) : (b)) #define dmin(a,b) (f2cmin(a,b)) #define dmax(a,b) (f2cmax(a,b)) #define bit_test(a,b) ((a) >> (b) & 1) #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b))) #define bit_set(a,b) ((a) | ((uinteger)1 << (b))) #define abort_() { sig_die("Fortran abort routine called", 1); } #define c_abs(z) (cabsf(Cf(z))) #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); } #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);} #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);} #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));} #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));} #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));} //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));} #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));} #define d_abs(x) (fabs(*(x))) #define d_acos(x) (acos(*(x))) #define d_asin(x) (asin(*(x))) #define d_atan(x) (atan(*(x))) #define d_atn2(x, y) (atan2(*(x),*(y))) #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); } #define r_cnjg(R, Z) { pCf(R) = conj(Cf(Z)); } #define d_cos(x) (cos(*(x))) #define d_cosh(x) (cosh(*(x))) #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 ) #define d_exp(x) (exp(*(x))) #define d_imag(z) (cimag(Cd(z))) #define r_imag(z) (cimag(Cf(z))) #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x))) #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x))) #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) ) #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) ) #define d_log(x) (log(*(x))) #define d_mod(x, y) (fmod(*(x), *(y))) #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x))) #define d_nint(x) u_nint(*(x)) #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a))) #define d_sign(a,b) u_sign(*(a),*(b)) #define r_sign(a,b) u_sign(*(a),*(b)) #define d_sin(x) (sin(*(x))) #define d_sinh(x) (sinh(*(x))) #define d_sqrt(x) (sqrt(*(x))) #define d_tan(x) (tan(*(x))) #define d_tanh(x) (tanh(*(x))) #define i_abs(x) abs(*(x)) #define i_dnnt(x) ((integer)u_nint(*(x))) #define i_len(s, n) (n) #define i_nint(x) ((integer)u_nint(*(x))) #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b))) #define pow_dd(ap, bp) ( pow(*(ap), *(bp))) #define pow_si(B,E) spow_ui(*(B),*(E)) #define pow_ri(B,E) spow_ui(*(B),*(E)) #define pow_di(B,E) dpow_ui(*(B),*(E)) #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));} #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));} #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));} #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; } #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d)))) #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; } #define sig_die(s, kill) { exit(1); } #define s_stop(s, n) {exit(0);} static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n"; #define z_abs(z) (cabs(Cd(z))) #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));} #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));} #define myexit_() break; #define mycycle() continue; #define myceiling(w) {ceil(w)} #define myhuge(w) {HUGE_VAL} //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);} #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)} /* procedure parameter types for -A and -C++ */ #define F2C_proc_par_types 1 #ifdef __cplusplus typedef logical (*L_fp)(...); #else typedef logical (*L_fp)(); #endif static float spow_ui(float x, integer n) { float pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static double dpow_ui(double x, integer n) { double pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static _Complex float cpow_ui(_Complex float x, integer n) { _Complex float pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static _Complex double zpow_ui(_Complex double x, integer n) { _Complex double pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static integer pow_ii(integer x, integer n) { integer pow; unsigned long int u; if (n <= 0) { if (n == 0 || x == 1) pow = 1; else if (x != -1) pow = x == 0 ? 1/x : 0; else n = -n; } if ((n > 0) || !(n == 0 || x == 1 || x != -1)) { u = n; for(pow = 1; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static integer dmaxloc_(double *w, integer s, integer e, integer *n) { double m; integer i, mi; for(m=w[s-1], mi=s, i=s+1; i<=e; i++) if (w[i-1]>m) mi=i ,m=w[i-1]; return mi-s+1; } static integer smaxloc_(float *w, integer s, integer e, integer *n) { float m; integer i, mi; for(m=w[s-1], mi=s, i=s+1; i<=e; i++) if (w[i-1]>m) mi=i ,m=w[i-1]; return mi-s+1; } static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; _Complex float zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conjf(Cf(&x[i])) * Cf(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]); } } pCf(z) = zdotc; } static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; _Complex double zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conj(Cd(&x[i])) * Cd(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]); } } pCd(z) = zdotc; } static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; _Complex float zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cf(&x[i]) * Cf(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]); } } pCf(z) = zdotc; } static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; _Complex double zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cd(&x[i]) * Cd(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]); } } pCd(z) = zdotc; } #endif /* -- translated by f2c (version 20000121). You must link the resulting object file with the libraries: -lf2c -lm (in that order) */ /* Table of constant values */ static integer c_n1 = -1; static integer c__0 = 0; static integer c__1 = 1; /* > \brief \b SSYRFSX */ /* =========== DOCUMENTATION =========== */ /* Online html documentation available at */ /* http://www.netlib.org/lapack/explore-html/ */ /* > \htmlonly */ /* > Download SSYRFSX + dependencies */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ssyrfsx .f"> */ /* > [TGZ]</a> */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ssyrfsx .f"> */ /* > [ZIP]</a> */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ssyrfsx .f"> */ /* > [TXT]</a> */ /* > \endhtmlonly */ /* Definition: */ /* =========== */ /* SUBROUTINE SSYRFSX( UPLO, EQUED, N, NRHS, A, LDA, AF, LDAF, IPIV, */ /* S, B, LDB, X, LDX, RCOND, BERR, N_ERR_BNDS, */ /* ERR_BNDS_NORM, ERR_BNDS_COMP, NPARAMS, PARAMS, */ /* WORK, IWORK, INFO ) */ /* CHARACTER UPLO, EQUED */ /* INTEGER INFO, LDA, LDAF, LDB, LDX, N, NRHS, NPARAMS, */ /* $ N_ERR_BNDS */ /* REAL RCOND */ /* INTEGER IPIV( * ), IWORK( * ) */ /* REAL A( LDA, * ), AF( LDAF, * ), B( LDB, * ), */ /* $ X( LDX, * ), WORK( * ) */ /* REAL S( * ), PARAMS( * ), BERR( * ), */ /* $ ERR_BNDS_NORM( NRHS, * ), */ /* $ ERR_BNDS_COMP( NRHS, * ) */ /* > \par Purpose: */ /* ============= */ /* > */ /* > \verbatim */ /* > */ /* > SSYRFSX improves the computed solution to a system of linear */ /* > equations when the coefficient matrix is symmetric indefinite, and */ /* > provides error bounds and backward error estimates for the */ /* > solution. In addition to normwise error bound, the code provides */ /* > maximum componentwise error bound if possible. See comments for */ /* > ERR_BNDS_NORM and ERR_BNDS_COMP for details of the error bounds. */ /* > */ /* > The original system of linear equations may have been equilibrated */ /* > before calling this routine, as described by arguments EQUED and S */ /* > below. In this case, the solution and error bounds returned are */ /* > for the original unequilibrated system. */ /* > \endverbatim */ /* Arguments: */ /* ========== */ /* > \verbatim */ /* > Some optional parameters are bundled in the PARAMS array. These */ /* > settings determine how refinement is performed, but often the */ /* > defaults are acceptable. If the defaults are acceptable, users */ /* > can pass NPARAMS = 0 which prevents the source code from accessing */ /* > the PARAMS argument. */ /* > \endverbatim */ /* > */ /* > \param[in] UPLO */ /* > \verbatim */ /* > UPLO is CHARACTER*1 */ /* > = 'U': Upper triangle of A is stored; */ /* > = 'L': Lower triangle of A is stored. */ /* > \endverbatim */ /* > */ /* > \param[in] EQUED */ /* > \verbatim */ /* > EQUED is CHARACTER*1 */ /* > Specifies the form of equilibration that was done to A */ /* > before calling this routine. This is needed to compute */ /* > the solution and error bounds correctly. */ /* > = 'N': No equilibration */ /* > = 'Y': Both row and column equilibration, i.e., A has been */ /* > replaced by diag(S) * A * diag(S). */ /* > The right hand side B has been changed accordingly. */ /* > \endverbatim */ /* > */ /* > \param[in] N */ /* > \verbatim */ /* > N is INTEGER */ /* > The order of the matrix A. N >= 0. */ /* > \endverbatim */ /* > */ /* > \param[in] NRHS */ /* > \verbatim */ /* > NRHS is INTEGER */ /* > The number of right hand sides, i.e., the number of columns */ /* > of the matrices B and X. NRHS >= 0. */ /* > \endverbatim */ /* > */ /* > \param[in] A */ /* > \verbatim */ /* > A is REAL array, dimension (LDA,N) */ /* > The symmetric matrix A. If UPLO = 'U', the leading N-by-N */ /* > upper triangular part of A contains the upper triangular */ /* > part of the matrix A, and the strictly lower triangular */ /* > part of A is not referenced. If UPLO = 'L', the leading */ /* > N-by-N lower triangular part of A contains the lower */ /* > triangular part of the matrix A, and the strictly upper */ /* > triangular part of A is not referenced. */ /* > \endverbatim */ /* > */ /* > \param[in] LDA */ /* > \verbatim */ /* > LDA is INTEGER */ /* > The leading dimension of the array A. LDA >= f2cmax(1,N). */ /* > \endverbatim */ /* > */ /* > \param[in] AF */ /* > \verbatim */ /* > AF is REAL array, dimension (LDAF,N) */ /* > The factored form of the matrix A. AF contains the block */ /* > diagonal matrix D and the multipliers used to obtain the */ /* > factor U or L from the factorization A = U*D*U**T or A = */ /* > L*D*L**T as computed by SSYTRF. */ /* > \endverbatim */ /* > */ /* > \param[in] LDAF */ /* > \verbatim */ /* > LDAF is INTEGER */ /* > The leading dimension of the array AF. LDAF >= f2cmax(1,N). */ /* > \endverbatim */ /* > */ /* > \param[in] IPIV */ /* > \verbatim */ /* > IPIV is INTEGER array, dimension (N) */ /* > Details of the interchanges and the block structure of D */ /* > as determined by SSYTRF. */ /* > \endverbatim */ /* > */ /* > \param[in,out] S */ /* > \verbatim */ /* > S is REAL array, dimension (N) */ /* > The scale factors for A. If EQUED = 'Y', A is multiplied on */ /* > the left and right by diag(S). S is an input argument if FACT = */ /* > 'F'; otherwise, S is an output argument. If FACT = 'F' and EQUED */ /* > = 'Y', each element of S must be positive. If S is output, each */ /* > element of S is a power of the radix. If S is input, each element */ /* > of S should be a power of the radix to ensure a reliable solution */ /* > and error estimates. Scaling by powers of the radix does not cause */ /* > rounding errors unless the result underflows or overflows. */ /* > Rounding errors during scaling lead to refining with a matrix that */ /* > is not equivalent to the input matrix, producing error estimates */ /* > that may not be reliable. */ /* > \endverbatim */ /* > */ /* > \param[in] B */ /* > \verbatim */ /* > B is REAL array, dimension (LDB,NRHS) */ /* > The right hand side matrix B. */ /* > \endverbatim */ /* > */ /* > \param[in] LDB */ /* > \verbatim */ /* > LDB is INTEGER */ /* > The leading dimension of the array B. LDB >= f2cmax(1,N). */ /* > \endverbatim */ /* > */ /* > \param[in,out] X */ /* > \verbatim */ /* > X is REAL array, dimension (LDX,NRHS) */ /* > On entry, the solution matrix X, as computed by SGETRS. */ /* > On exit, the improved solution matrix X. */ /* > \endverbatim */ /* > */ /* > \param[in] LDX */ /* > \verbatim */ /* > LDX is INTEGER */ /* > The leading dimension of the array X. LDX >= f2cmax(1,N). */ /* > \endverbatim */ /* > */ /* > \param[out] RCOND */ /* > \verbatim */ /* > RCOND is REAL */ /* > Reciprocal scaled condition number. This is an estimate of the */ /* > reciprocal Skeel condition number of the matrix A after */ /* > equilibration (if done). If this is less than the machine */ /* > precision (in particular, if it is zero), the matrix is singular */ /* > to working precision. Note that the error may still be small even */ /* > if this number is very small and the matrix appears ill- */ /* > conditioned. */ /* > \endverbatim */ /* > */ /* > \param[out] BERR */ /* > \verbatim */ /* > BERR is REAL array, dimension (NRHS) */ /* > Componentwise relative backward error. This is the */ /* > componentwise relative backward error of each solution vector X(j) */ /* > (i.e., the smallest relative change in any element of A or B that */ /* > makes X(j) an exact solution). */ /* > \endverbatim */ /* > */ /* > \param[in] N_ERR_BNDS */ /* > \verbatim */ /* > N_ERR_BNDS is INTEGER */ /* > Number of error bounds to return for each right hand side */ /* > and each type (normwise or componentwise). See ERR_BNDS_NORM and */ /* > ERR_BNDS_COMP below. */ /* > \endverbatim */ /* > */ /* > \param[out] ERR_BNDS_NORM */ /* > \verbatim */ /* > ERR_BNDS_NORM is REAL array, dimension (NRHS, N_ERR_BNDS) */ /* > For each right-hand side, this array contains information about */ /* > various error bounds and condition numbers corresponding to the */ /* > normwise relative error, which is defined as follows: */ /* > */ /* > Normwise relative error in the ith solution vector: */ /* > max_j (abs(XTRUE(j,i) - X(j,i))) */ /* > ------------------------------ */ /* > max_j abs(X(j,i)) */ /* > */ /* > The array is indexed by the type of error information as described */ /* > below. There currently are up to three pieces of information */ /* > returned. */ /* > */ /* > The first index in ERR_BNDS_NORM(i,:) corresponds to the ith */ /* > right-hand side. */ /* > */ /* > The second index in ERR_BNDS_NORM(:,err) contains the following */ /* > three fields: */ /* > err = 1 "Trust/don't trust" boolean. Trust the answer if the */ /* > reciprocal condition number is less than the threshold */ /* > sqrt(n) * slamch('Epsilon'). */ /* > */ /* > err = 2 "Guaranteed" error bound: The estimated forward error, */ /* > almost certainly within a factor of 10 of the true error */ /* > so long as the next entry is greater than the threshold */ /* > sqrt(n) * slamch('Epsilon'). This error bound should only */ /* > be trusted if the previous boolean is true. */ /* > */ /* > err = 3 Reciprocal condition number: Estimated normwise */ /* > reciprocal condition number. Compared with the threshold */ /* > sqrt(n) * slamch('Epsilon') to determine if the error */ /* > estimate is "guaranteed". These reciprocal condition */ /* > numbers are 1 / (norm(Z^{-1},inf) * norm(Z,inf)) for some */ /* > appropriately scaled matrix Z. */ /* > Let Z = S*A, where S scales each row by a power of the */ /* > radix so all absolute row sums of Z are approximately 1. */ /* > */ /* > See Lapack Working Note 165 for further details and extra */ /* > cautions. */ /* > \endverbatim */ /* > */ /* > \param[out] ERR_BNDS_COMP */ /* > \verbatim */ /* > ERR_BNDS_COMP is REAL array, dimension (NRHS, N_ERR_BNDS) */ /* > For each right-hand side, this array contains information about */ /* > various error bounds and condition numbers corresponding to the */ /* > componentwise relative error, which is defined as follows: */ /* > */ /* > Componentwise relative error in the ith solution vector: */ /* > abs(XTRUE(j,i) - X(j,i)) */ /* > max_j ---------------------- */ /* > abs(X(j,i)) */ /* > */ /* > The array is indexed by the right-hand side i (on which the */ /* > componentwise relative error depends), and the type of error */ /* > information as described below. There currently are up to three */ /* > pieces of information returned for each right-hand side. If */ /* > componentwise accuracy is not requested (PARAMS(3) = 0.0), then */ /* > ERR_BNDS_COMP is not accessed. If N_ERR_BNDS < 3, then at most */ /* > the first (:,N_ERR_BNDS) entries are returned. */ /* > */ /* > The first index in ERR_BNDS_COMP(i,:) corresponds to the ith */ /* > right-hand side. */ /* > */ /* > The second index in ERR_BNDS_COMP(:,err) contains the following */ /* > three fields: */ /* > err = 1 "Trust/don't trust" boolean. Trust the answer if the */ /* > reciprocal condition number is less than the threshold */ /* > sqrt(n) * slamch('Epsilon'). */ /* > */ /* > err = 2 "Guaranteed" error bound: The estimated forward error, */ /* > almost certainly within a factor of 10 of the true error */ /* > so long as the next entry is greater than the threshold */ /* > sqrt(n) * slamch('Epsilon'). This error bound should only */ /* > be trusted if the previous boolean is true. */ /* > */ /* > err = 3 Reciprocal condition number: Estimated componentwise */ /* > reciprocal condition number. Compared with the threshold */ /* > sqrt(n) * slamch('Epsilon') to determine if the error */ /* > estimate is "guaranteed". These reciprocal condition */ /* > numbers are 1 / (norm(Z^{-1},inf) * norm(Z,inf)) for some */ /* > appropriately scaled matrix Z. */ /* > Let Z = S*(A*diag(x)), where x is the solution for the */ /* > current right-hand side and S scales each row of */ /* > A*diag(x) by a power of the radix so all absolute row */ /* > sums of Z are approximately 1. */ /* > */ /* > See Lapack Working Note 165 for further details and extra */ /* > cautions. */ /* > \endverbatim */ /* > */ /* > \param[in] NPARAMS */ /* > \verbatim */ /* > NPARAMS is INTEGER */ /* > Specifies the number of parameters set in PARAMS. If <= 0, the */ /* > PARAMS array is never referenced and default values are used. */ /* > \endverbatim */ /* > */ /* > \param[in,out] PARAMS */ /* > \verbatim */ /* > PARAMS is REAL array, dimension NPARAMS */ /* > Specifies algorithm parameters. If an entry is < 0.0, then */ /* > that entry will be filled with default value used for that */ /* > parameter. Only positions up to NPARAMS are accessed; defaults */ /* > are used for higher-numbered parameters. */ /* > */ /* > PARAMS(LA_LINRX_ITREF_I = 1) : Whether to perform iterative */ /* > refinement or not. */ /* > Default: 1.0 */ /* > = 0.0: No refinement is performed, and no error bounds are */ /* > computed. */ /* > = 1.0: Use the double-precision refinement algorithm, */ /* > possibly with doubled-single computations if the */ /* > compilation environment does not support DOUBLE */ /* > PRECISION. */ /* > (other values are reserved for future use) */ /* > */ /* > PARAMS(LA_LINRX_ITHRESH_I = 2) : Maximum number of residual */ /* > computations allowed for refinement. */ /* > Default: 10 */ /* > Aggressive: Set to 100 to permit convergence using approximate */ /* > factorizations or factorizations other than LU. If */ /* > the factorization uses a technique other than */ /* > Gaussian elimination, the guarantees in */ /* > err_bnds_norm and err_bnds_comp may no longer be */ /* > trustworthy. */ /* > */ /* > PARAMS(LA_LINRX_CWISE_I = 3) : Flag determining if the code */ /* > will attempt to find a solution with small componentwise */ /* > relative error in the double-precision algorithm. Positive */ /* > is true, 0.0 is false. */ /* > Default: 1.0 (attempt componentwise convergence) */ /* > \endverbatim */ /* > */ /* > \param[out] WORK */ /* > \verbatim */ /* > WORK is REAL array, dimension (4*N) */ /* > \endverbatim */ /* > */ /* > \param[out] IWORK */ /* > \verbatim */ /* > IWORK is INTEGER array, dimension (N) */ /* > \endverbatim */ /* > */ /* > \param[out] INFO */ /* > \verbatim */ /* > INFO is INTEGER */ /* > = 0: Successful exit. The solution to every right-hand side is */ /* > guaranteed. */ /* > < 0: If INFO = -i, the i-th argument had an illegal value */ /* > > 0 and <= N: U(INFO,INFO) is exactly zero. The factorization */ /* > has been completed, but the factor U is exactly singular, so */ /* > the solution and error bounds could not be computed. RCOND = 0 */ /* > is returned. */ /* > = N+J: The solution corresponding to the Jth right-hand side is */ /* > not guaranteed. The solutions corresponding to other right- */ /* > hand sides K with K > J may not be guaranteed as well, but */ /* > only the first such right-hand side is reported. If a small */ /* > componentwise error is not requested (PARAMS(3) = 0.0) then */ /* > the Jth right-hand side is the first with a normwise error */ /* > bound that is not guaranteed (the smallest J such */ /* > that ERR_BNDS_NORM(J,1) = 0.0). By default (PARAMS(3) = 1.0) */ /* > the Jth right-hand side is the first with either a normwise or */ /* > componentwise error bound that is not guaranteed (the smallest */ /* > J such that either ERR_BNDS_NORM(J,1) = 0.0 or */ /* > ERR_BNDS_COMP(J,1) = 0.0). See the definition of */ /* > ERR_BNDS_NORM(:,1) and ERR_BNDS_COMP(:,1). To get information */ /* > about all of the right-hand sides check ERR_BNDS_NORM or */ /* > ERR_BNDS_COMP. */ /* > \endverbatim */ /* Authors: */ /* ======== */ /* > \author Univ. of Tennessee */ /* > \author Univ. of California Berkeley */ /* > \author Univ. of Colorado Denver */ /* > \author NAG Ltd. */ /* > \date April 2012 */ /* > \ingroup realSYcomputational */ /* ===================================================================== */ /* Subroutine */ int ssyrfsx_(char *uplo, char *equed, integer *n, integer * nrhs, real *a, integer *lda, real *af, integer *ldaf, integer *ipiv, real *s, real *b, integer *ldb, real *x, integer *ldx, real *rcond, real *berr, integer *n_err_bnds__, real *err_bnds_norm__, real * err_bnds_comp__, integer *nparams, real *params, real *work, integer * iwork, integer *info) { /* System generated locals */ integer a_dim1, a_offset, af_dim1, af_offset, b_dim1, b_offset, x_dim1, x_offset, err_bnds_norm_dim1, err_bnds_norm_offset, err_bnds_comp_dim1, err_bnds_comp_offset, i__1; real r__1, r__2; /* Local variables */ real illrcond_thresh__, unstable_thresh__, err_lbnd__; extern /* Subroutine */ int sla_syrfsx_extended_(integer *, char *, integer *, integer *, real *, integer *, real *, integer *, integer *, logical *, real *, real *, integer *, real *, integer * , real *, integer *, real *, real *, real *, real *, real *, real *, real *, integer *, real *, real *, logical *, integer *); char norm[1]; integer ref_type__; logical ignore_cwise__; integer j; extern logical lsame_(char *, char *); real anorm; logical rcequ; real rcond_tmp__; integer prec_type__; extern real slamch_(char *); extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen); extern real slansy_(char *, char *, integer *, real *, integer *, real *); extern /* Subroutine */ int ssycon_(char *, integer *, real *, integer *, integer *, real *, real *, real *, integer *, integer *); extern integer ilaprec_(char *); integer ithresh, n_norms__; real rthresh; extern real sla_syrcond_(char *, integer *, real *, integer *, real *, integer *, integer *, integer *, real *, integer *, real *, integer *); real cwise_wrong__; /* -- LAPACK computational routine (version 3.7.0) -- */ /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */ /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */ /* April 2012 */ /* ================================================================== */ /* Check the input parameters. */ /* Parameter adjustments */ err_bnds_comp_dim1 = *nrhs; err_bnds_comp_offset = 1 + err_bnds_comp_dim1 * 1; err_bnds_comp__ -= err_bnds_comp_offset; err_bnds_norm_dim1 = *nrhs; err_bnds_norm_offset = 1 + err_bnds_norm_dim1 * 1; err_bnds_norm__ -= err_bnds_norm_offset; a_dim1 = *lda; a_offset = 1 + a_dim1 * 1; a -= a_offset; af_dim1 = *ldaf; af_offset = 1 + af_dim1 * 1; af -= af_offset; --ipiv; --s; b_dim1 = *ldb; b_offset = 1 + b_dim1 * 1; b -= b_offset; x_dim1 = *ldx; x_offset = 1 + x_dim1 * 1; x -= x_offset; --berr; --params; --work; --iwork; /* Function Body */ *info = 0; ref_type__ = 1; if (*nparams >= 1) { if (params[1] < 0.f) { params[1] = 1.f; } else { ref_type__ = params[1]; } } /* Set default parameters. */ illrcond_thresh__ = (real) (*n) * slamch_("Epsilon"); ithresh = 10; rthresh = .5f; unstable_thresh__ = .25f; ignore_cwise__ = FALSE_; if (*nparams >= 2) { if (params[2] < 0.f) { params[2] = (real) ithresh; } else { ithresh = (integer) params[2]; } } if (*nparams >= 3) { if (params[3] < 0.f) { if (ignore_cwise__) { params[3] = 0.f; } else { params[3] = 1.f; } } else { ignore_cwise__ = params[3] == 0.f; } } if (ref_type__ == 0 || *n_err_bnds__ == 0) { n_norms__ = 0; } else if (ignore_cwise__) { n_norms__ = 1; } else { n_norms__ = 2; } rcequ = lsame_(equed, "Y"); /* Test input parameters. */ if (! lsame_(uplo, "U") && ! lsame_(uplo, "L")) { *info = -1; } else if (! rcequ && ! lsame_(equed, "N")) { *info = -2; } else if (*n < 0) { *info = -3; } else if (*nrhs < 0) { *info = -4; } else if (*lda < f2cmax(1,*n)) { *info = -6; } else if (*ldaf < f2cmax(1,*n)) { *info = -8; } else if (*ldb < f2cmax(1,*n)) { *info = -12; } else if (*ldx < f2cmax(1,*n)) { *info = -14; } if (*info != 0) { i__1 = -(*info); xerbla_("SSYRFSX", &i__1, (ftnlen)7); return 0; } /* Quick return if possible. */ if (*n == 0 || *nrhs == 0) { *rcond = 1.f; i__1 = *nrhs; for (j = 1; j <= i__1; ++j) { berr[j] = 0.f; if (*n_err_bnds__ >= 1) { err_bnds_norm__[j + err_bnds_norm_dim1] = 1.f; err_bnds_comp__[j + err_bnds_comp_dim1] = 1.f; } if (*n_err_bnds__ >= 2) { err_bnds_norm__[j + (err_bnds_norm_dim1 << 1)] = 0.f; err_bnds_comp__[j + (err_bnds_comp_dim1 << 1)] = 0.f; } if (*n_err_bnds__ >= 3) { err_bnds_norm__[j + err_bnds_norm_dim1 * 3] = 1.f; err_bnds_comp__[j + err_bnds_comp_dim1 * 3] = 1.f; } } return 0; } /* Default to failure. */ *rcond = 0.f; i__1 = *nrhs; for (j = 1; j <= i__1; ++j) { berr[j] = 1.f; if (*n_err_bnds__ >= 1) { err_bnds_norm__[j + err_bnds_norm_dim1] = 1.f; err_bnds_comp__[j + err_bnds_comp_dim1] = 1.f; } if (*n_err_bnds__ >= 2) { err_bnds_norm__[j + (err_bnds_norm_dim1 << 1)] = 1.f; err_bnds_comp__[j + (err_bnds_comp_dim1 << 1)] = 1.f; } if (*n_err_bnds__ >= 3) { err_bnds_norm__[j + err_bnds_norm_dim1 * 3] = 0.f; err_bnds_comp__[j + err_bnds_comp_dim1 * 3] = 0.f; } } /* Compute the norm of A and the reciprocal of the condition */ /* number of A. */ *(unsigned char *)norm = 'I'; anorm = slansy_(norm, uplo, n, &a[a_offset], lda, &work[1]); ssycon_(uplo, n, &af[af_offset], ldaf, &ipiv[1], &anorm, rcond, &work[1], &iwork[1], info); /* Perform refinement on each right-hand side */ if (ref_type__ != 0) { prec_type__ = ilaprec_("D"); sla_syrfsx_extended_(&prec_type__, uplo, n, nrhs, &a[a_offset], lda, &af[af_offset], ldaf, &ipiv[1], &rcequ, &s[1], &b[b_offset], ldb, &x[x_offset], ldx, &berr[1], &n_norms__, & err_bnds_norm__[err_bnds_norm_offset], &err_bnds_comp__[ err_bnds_comp_offset], &work[*n + 1], &work[1], &work[(*n << 1) + 1], &work[1], rcond, &ithresh, &rthresh, & unstable_thresh__, &ignore_cwise__, info); } /* Computing MAX */ r__1 = 10.f, r__2 = sqrt((real) (*n)); err_lbnd__ = f2cmax(r__1,r__2) * slamch_("Epsilon"); if (*n_err_bnds__ >= 1 && n_norms__ >= 1) { /* Compute scaled normwise condition number cond(A*C). */ if (rcequ) { rcond_tmp__ = sla_syrcond_(uplo, n, &a[a_offset], lda, &af[ af_offset], ldaf, &ipiv[1], &c_n1, &s[1], info, &work[1], &iwork[1]); } else { rcond_tmp__ = sla_syrcond_(uplo, n, &a[a_offset], lda, &af[ af_offset], ldaf, &ipiv[1], &c__0, &s[1], info, &work[1], &iwork[1]); } i__1 = *nrhs; for (j = 1; j <= i__1; ++j) { /* Cap the error at 1.0. */ if (*n_err_bnds__ >= 2 && err_bnds_norm__[j + (err_bnds_norm_dim1 << 1)] > 1.f) { err_bnds_norm__[j + (err_bnds_norm_dim1 << 1)] = 1.f; } /* Threshold the error (see LAWN). */ if (rcond_tmp__ < illrcond_thresh__) { err_bnds_norm__[j + (err_bnds_norm_dim1 << 1)] = 1.f; err_bnds_norm__[j + err_bnds_norm_dim1] = 0.f; if (*info <= *n) { *info = *n + j; } } else if (err_bnds_norm__[j + (err_bnds_norm_dim1 << 1)] < err_lbnd__) { err_bnds_norm__[j + (err_bnds_norm_dim1 << 1)] = err_lbnd__; err_bnds_norm__[j + err_bnds_norm_dim1] = 1.f; } /* Save the condition number. */ if (*n_err_bnds__ >= 3) { err_bnds_norm__[j + err_bnds_norm_dim1 * 3] = rcond_tmp__; } } } if (*n_err_bnds__ >= 1 && n_norms__ >= 2) { /* Compute componentwise condition number cond(A*diag(Y(:,J))) for */ /* each right-hand side using the current solution as an estimate of */ /* the true solution. If the componentwise error estimate is too */ /* large, then the solution is a lousy estimate of truth and the */ /* estimated RCOND may be too optimistic. To avoid misleading users, */ /* the inverse condition number is set to 0.0 when the estimated */ /* cwise error is at least CWISE_WRONG. */ cwise_wrong__ = sqrt(slamch_("Epsilon")); i__1 = *nrhs; for (j = 1; j <= i__1; ++j) { if (err_bnds_comp__[j + (err_bnds_comp_dim1 << 1)] < cwise_wrong__) { rcond_tmp__ = sla_syrcond_(uplo, n, &a[a_offset], lda, &af[ af_offset], ldaf, &ipiv[1], &c__1, &x[j * x_dim1 + 1], info, &work[1], &iwork[1]); } else { rcond_tmp__ = 0.f; } /* Cap the error at 1.0. */ if (*n_err_bnds__ >= 2 && err_bnds_comp__[j + (err_bnds_comp_dim1 << 1)] > 1.f) { err_bnds_comp__[j + (err_bnds_comp_dim1 << 1)] = 1.f; } /* Threshold the error (see LAWN). */ if (rcond_tmp__ < illrcond_thresh__) { err_bnds_comp__[j + (err_bnds_comp_dim1 << 1)] = 1.f; err_bnds_comp__[j + err_bnds_comp_dim1] = 0.f; if (! ignore_cwise__ && *info < *n + j) { *info = *n + j; } } else if (err_bnds_comp__[j + (err_bnds_comp_dim1 << 1)] < err_lbnd__) { err_bnds_comp__[j + (err_bnds_comp_dim1 << 1)] = err_lbnd__; err_bnds_comp__[j + err_bnds_comp_dim1] = 1.f; } /* Save the condition number. */ if (*n_err_bnds__ >= 3) { err_bnds_comp__[j + err_bnds_comp_dim1 * 3] = rcond_tmp__; } } } return 0; /* End of SSYRFSX */ } /* ssyrfsx_ */
the_stack_data/176704352.c
/* uncompr.c -- decompress a memory buffer * Copyright (C) 1995-2003 Jean-loup Gailly. * For conditions of distribution and use, see copyright notice in zlib.h */ /* @(#) $Id: uncompr.c,v 1.6 2004/04/25 08:48:21 VS Exp $ */ #define ZLIB_INTERNAL #include "zlib.h" /* =========================================================================== Decompresses the source buffer into the destination buffer. sourceLen is the byte length of the source buffer. Upon entry, destLen is the total size of the destination buffer, which must be large enough to hold the entire uncompressed data. (The size of the uncompressed data must have been saved previously by the compressor and transmitted to the decompressor by some mechanism outside the scope of this compression library.) Upon exit, destLen is the actual size of the compressed buffer. This function can be used to decompress a whole file at once if the input file is mmap'ed. uncompress returns Z_OK if success, Z_MEM_ERROR if there was not enough memory, Z_BUF_ERROR if there was not enough room in the output buffer, or Z_DATA_ERROR if the input data was corrupted. */ int ZEXPORT uncompress (dest, destLen, source, sourceLen) Bytef *dest; uLongf *destLen; const Bytef *source; uLong sourceLen; { z_stream stream; int err; stream.next_in = (Bytef*)source; stream.avail_in = (uInt)sourceLen; /* Check for source > 64K on 16-bit machine: */ if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; stream.next_out = dest; stream.avail_out = (uInt)*destLen; if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; stream.zalloc = (alloc_func)0; stream.zfree = (free_func)0; err = inflateInit(&stream); if (err != Z_OK) return err; err = inflate(&stream, Z_FINISH); if (err != Z_STREAM_END) { inflateEnd(&stream); if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0)) return Z_DATA_ERROR; return err; } *destLen = stream.total_out; err = inflateEnd(&stream); return err; }
the_stack_data/200142808.c
/* * Copyright (c) 2020 Bouffalolab. * * This file is part of * *** Bouffalolab Software Dev Kit *** * (see www.bouffalolab.com). * * 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. * 3. Neither the name of Bouffalo Lab nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * 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 HOLDER 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. */ char *event_dump_string[] = { "error :eventgorup should input EventGroup_t handle pointer\r\n", "start bugkiller_eventgroup_dump\r\n", "pxList is null\r\n", "pxListItem is null\r\n", "EventGroup TCB pointer value is %p\r\n", "EventGroup:uxEventBits = 0x%lx\r\n", "the value of pxListItem->xItemValue:%p is 0x%lx\r\n", "EventGroup set eventWAIT_FOR_ALL_BITS **FALSE**\r\n", "EventGroup set eventWAIT_FOR_ALL_BITS TURE\r\n", "EventGroup set eventCLEAR_EVENTS_ON_EXIT_BIT **FALSE**\r\n", "EventGroup set eventCLEAR_EVENTS_ON_EXIT_BIT TRUE\r\n", "eventUNBLOCKED_DUE_TO_BIT_SET bit is **FALSE**\r\n", "eventUNBLOCKED_DUE_TO_BIT_SET is TRUE\r\n", "%lu Tasks waiting this event bits\r\n", "task name :%s\r\n", }; char *task_dump_string[] = { "Task State Priority Stack # Base\r\n********************************************************\r\n", "%s", "%s", }; char *heap_dump_string[] = { "All Block HeapStruct Address\r\n*******************************************************\r\n", "Head Address Point To Next Address BlockSize\r\n*******************************************************\r\n", "%p %p 0x%x\r\n", "%p %p 0x%x\r\n", "\r\n", "Free Block HeapStruct Address\r\n*******************************************************\r\n", "Head Address Point To Next Address BlockSize\r\n*******************************************************\r\n", "%p %p 0x%x\r\n", "%p %p 0x%x\r\n", "Current left size is %d bytes, mytest left bytes is %ld\r\n", }; char *sem_dump_string[] = { "pcHead: %p, pcWriteTo: %p, uxMessageswaiting: %lu, uxLength: %lu, uxItemSize: %lu, cRxLock: %d, cTxLock: %d ", "type: SET\r\n", "type: MUTEX\r\n", "type: COUNTING_SEMAPHORE\r\n", "type: BINARY_SEMAPHORE\r\n", "type: RECURSIVE_MUTEX\r\n", "%lu Tasks waiting to receive this semaphore\r\n", "task name :%s\r\n", "%lu Tasks waiting to send this semaphore\r\n", "task name :%s\r\n", }; char *softtimer_dump_string[] = { " Name PeriodInTicks ID Callback Reload Static IsActive\r\n", " %s\t%lu\t%p\t%p\t%c\t%c\t%c\r\n", " Name PeriodInTicks ID Callback Reload Static IsActive\r\n", " %s\t%lu\t%p\t%p\t%c\t%c\t%c\r\n", }; char *streambuffer_dump_string[] = { "address:%p, total_length:%u, used:%u, left:%u, xTail:%u, xHead:%u, triggerlevelbytes:%u, ismessagebuffer:%c, isstatic:%c, isfull:%c, isempty:%c\r\n", "messagebuffer next message length is %u\r\n", "no task waiting for data\r\n", "task << %s >> is waiting for data\r\n", "no task waiting to send data\r\n", "task << %s >> is waiting to send data\r\n", };
the_stack_data/104828169.c
/* * The MIT License (MIT) * * Copyright (c) 2019 Ha Thach (tinyusb.org) * * Permission is hereby granted, 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. * */ #ifdef __RTTHREAD__ #include <board.h> #include <rtdevice.h> #include <tusb.h> #include <fal.h> // whether host does safe-eject static bool ejected = false; static rt_device_t flash_device; // Invoked when received SCSI_CMD_INQUIRY // Application fill vendor id, product id and revision with string up to 8, 16, 4 characters respectively void tud_msc_inquiry_cb(uint8_t lun, uint8_t vendor_id[8], uint8_t product_id[16], uint8_t product_rev[4]) { (void) lun; const char vid[] = "TinyUSB"; const char pid[] = "Mass Storage"; const char rev[] = "1.0"; memcpy(vendor_id, vid, strlen(vid)); memcpy(product_id, pid, strlen(pid)); memcpy(product_rev, rev, strlen(rev)); } // Invoked when received Test Unit Ready command. // return true allowing host to read/write this LUN e.g SD card inserted bool tud_msc_test_unit_ready_cb(uint8_t lun) { (void) lun; // RAM disk is ready until ejected if (ejected) { tud_msc_set_sense(lun, SCSI_SENSE_NOT_READY, 0x3a, 0x00); return false; } return true; } // Invoked when received SCSI_CMD_READ_CAPACITY_10 and SCSI_CMD_READ_FORMAT_CAPACITY to determine the disk size // Application update block count and block size void tud_msc_capacity_cb(uint8_t lun, uint32_t *block_count, uint16_t *block_size) { (void) lun; struct rt_device_blk_geometry blk_geom; if (!flash_device) { flash_device = rt_device_find(PKG_TINYUSB_DEVICE_MSC_NAME); } rt_device_control(flash_device, RT_DEVICE_CTRL_BLK_GETGEOME, &blk_geom); *block_count = blk_geom.sector_count; *block_size = blk_geom.bytes_per_sector; } // Invoked when received Start Stop Unit command // - Start = 0 : stopped power mode, if load_eject = 1 : unload disk storage // - Start = 1 : active mode, if load_eject = 1 : load disk storage bool tud_msc_start_stop_cb(uint8_t lun, uint8_t power_condition, bool start, bool load_eject) { (void) lun; (void) power_condition; if (load_eject) { if (start) { // load disk storage flash_device = rt_device_find(PKG_TINYUSB_DEVICE_MSC_NAME); } else { // unload disk storage ejected = true; } } return true; } // Callback invoked when received READ10 command. // Copy disk's data to buffer (up to bufsize) and return number of copied bytes. int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void *buffer, uint32_t bufsize) { (void) lun; (void) offset; (void) bufsize; return (int32_t) rt_device_read(flash_device, (rt_off_t) lba, buffer, 1) * 4096; } // Callback invoked when received WRITE10 command. // Process data in buffer to disk's storage and return number of written bytes int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, uint8_t *buffer, uint32_t bufsize) { (void) lun; (void) offset; (void) bufsize; return (int32_t) rt_device_write(flash_device, (rt_off_t) lba, buffer, 1) * 4096; } // Callback invoked when received an SCSI command not in built-in list below // - READ_CAPACITY10, READ_FORMAT_CAPACITY, INQUIRY, MODE_SENSE6, REQUEST_SENSE // - READ10 and WRITE10 has their own callbacks int32_t tud_msc_scsi_cb(uint8_t lun, uint8_t const scsi_cmd[16], void *buffer, uint16_t bufsize) { // read10 & write10 has their own callback and MUST not be handled here void const *response = NULL; uint16_t resplen = 0; // most scsi handled is input bool in_xfer = true; switch (scsi_cmd[0]) { case SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL: // Host is about to read/write etc ... better not to disconnect disk resplen = 0; break; default: // Set Sense = Invalid Command Operation tud_msc_set_sense(lun, SCSI_SENSE_ILLEGAL_REQUEST, 0x20, 0x00); // negative means error -> tinyusb could stall and/or response with failed status resplen = -1; break; } // return resplen must not larger than bufsize if (resplen > bufsize) resplen = bufsize; if (response && (resplen > 0)) { if (in_xfer) { memcpy(buffer, response, resplen); } else { // SCSI output } } return resplen; } #endif
the_stack_data/142059.c
/* Generated by CIL v. 1.7.3 */ /* print_CIL_Input is true */ #line 4 "/usr/local/ddv/models/con2/include/asm/posix_types.h" typedef unsigned long __kernel_ino_t; #line 5 "/usr/local/ddv/models/con2/include/asm/posix_types.h" typedef unsigned short __kernel_mode_t; #line 12 "/usr/local/ddv/models/con2/include/asm/posix_types.h" typedef unsigned int __kernel_size_t; #line 13 "/usr/local/ddv/models/con2/include/asm/posix_types.h" typedef int __kernel_ssize_t; #line 4 "/usr/local/ddv/models/con2/include/asm/types.h" typedef unsigned short umode_t; #line 13 "/usr/local/ddv/models/con2/include/asm/types.h" typedef unsigned int __u32; #line 9 "/usr/local/ddv/models/con2/include/linux/types.h" typedef __u32 __kernel_dev_t; #line 11 "/usr/local/ddv/models/con2/include/linux/types.h" typedef __kernel_dev_t dev_t; #line 12 "/usr/local/ddv/models/con2/include/linux/types.h" typedef __kernel_ino_t ino_t; #line 13 "/usr/local/ddv/models/con2/include/linux/types.h" typedef __kernel_mode_t mode_t; #line 30 "/usr/local/ddv/models/con2/include/linux/types.h" typedef long long loff_t; #line 38 "/usr/local/ddv/models/con2/include/linux/types.h" typedef __kernel_size_t size_t; #line 43 "/usr/local/ddv/models/con2/include/linux/types.h" typedef __kernel_ssize_t ssize_t; #line 44 "/usr/local/ddv/models/con2/include/ddverify/satabs.h" struct __pthread_t_struct { int id ; }; #line 49 "/usr/local/ddv/models/con2/include/ddverify/satabs.h" struct __pthread_attr_t_struct { int dummy ; }; #line 54 "/usr/local/ddv/models/con2/include/ddverify/satabs.h" typedef struct __pthread_t_struct pthread_t; #line 55 "/usr/local/ddv/models/con2/include/ddverify/satabs.h" typedef struct __pthread_attr_t_struct pthread_attr_t; #line 6 "/usr/local/ddv/models/con2/include/asm/atomic.h" typedef int atomic_t; #line 67 "/usr/local/ddv/models/con2/include/linux/gfp.h" struct page; #line 4 "/usr/local/ddv/models/con2/include/linux/dcache.h" struct inode; #line 4 "/usr/local/ddv/models/con2/include/linux/dcache.h" struct dentry { struct inode *d_inode ; }; #line 83 "/usr/local/ddv/models/con2/include/linux/fs.h" struct iovec; #line 84 struct poll_table_struct; #line 85 struct vm_area_struct; #line 90 "/usr/local/ddv/models/con2/include/linux/fs.h" struct address_space { struct inode *host ; }; #line 94 struct file_operations; #line 94 "/usr/local/ddv/models/con2/include/linux/fs.h" struct file { struct dentry *f_dentry ; struct file_operations *f_op ; atomic_t f_count ; unsigned int f_flags ; mode_t f_mode ; loff_t f_pos ; void *private_data ; struct address_space *f_mapping ; }; #line 105 struct gendisk; #line 105 "/usr/local/ddv/models/con2/include/linux/fs.h" struct block_device { struct inode *bd_inode ; struct gendisk *bd_disk ; struct block_device *bd_contains ; unsigned int bd_block_size ; }; #line 113 struct cdev; #line 113 "/usr/local/ddv/models/con2/include/linux/fs.h" struct inode { umode_t i_mode ; struct block_device *i_bdev ; dev_t i_rdev ; loff_t i_size ; struct cdev *i_cdev ; }; #line 122 "/usr/local/ddv/models/con2/include/linux/fs.h" struct __anonstruct_read_descriptor_t_4 { size_t written ; size_t count ; }; #line 122 "/usr/local/ddv/models/con2/include/linux/fs.h" typedef struct __anonstruct_read_descriptor_t_4 read_descriptor_t; #line 130 "/usr/local/ddv/models/con2/include/linux/fs.h" struct file_lock { int something ; }; #line 134 struct module; #line 134 "/usr/local/ddv/models/con2/include/linux/fs.h" struct file_operations { struct module *owner ; loff_t (*llseek)(struct file * , loff_t , int ) ; ssize_t (*read)(struct file * , char * , size_t , loff_t * ) ; ssize_t (*write)(struct file * , char const * , size_t , loff_t * ) ; int (*readdir)(struct file * , void * , int (*)(void * , char const * , int , loff_t , ino_t , unsigned int ) ) ; unsigned int (*poll)(struct file * , struct poll_table_struct * ) ; int (*ioctl)(struct inode * , struct file * , unsigned int , unsigned long ) ; long (*unlocked_ioctl)(struct file * , unsigned int , unsigned long ) ; long (*compat_ioctl)(struct file * , unsigned int , unsigned long ) ; int (*mmap)(struct file * , struct vm_area_struct * ) ; int (*open)(struct inode * , struct file * ) ; int (*flush)(struct file * ) ; int (*release)(struct inode * , struct file * ) ; int (*fsync)(struct file * , struct dentry * , int datasync ) ; int (*fasync)(int , struct file * , int ) ; int (*lock)(struct file * , int , struct file_lock * ) ; ssize_t (*readv)(struct file * , struct iovec const * , unsigned long , loff_t * ) ; ssize_t (*writev)(struct file * , struct iovec const * , unsigned long , loff_t * ) ; ssize_t (*sendfile)(struct file * , loff_t * , size_t , int (*)(read_descriptor_t * , struct page * , unsigned long , unsigned long ) , void * ) ; ssize_t (*sendpage)(struct file * , struct page * , int , size_t , loff_t * , int ) ; unsigned long (*get_unmapped_area)(struct file * , unsigned long , unsigned long , unsigned long , unsigned long ) ; int (*check_flags)(int ) ; int (*dir_notify)(struct file *filp , unsigned long arg ) ; int (*flock)(struct file * , int , struct file_lock * ) ; int (*open_exec)(struct inode * ) ; }; #line 4 "/usr/local/ddv/models/con2/include/linux/cdev.h" struct cdev { struct module *owner ; struct file_operations *ops ; dev_t dev ; unsigned int count ; }; #line 13 "/usr/local/ddv/models/con2/include/ddverify/cdev.h" struct ddv_cdev { struct cdev *cdevp ; struct file filp ; struct inode inode ; int open ; }; #line 30 "/usr/local/ddv/models/con2/include/asm/types.h" typedef unsigned long long u64; #line 91 "/usr/local/ddv/models/con2/include/linux/types.h" typedef unsigned long sector_t; #line 15 "/usr/local/ddv/models/con2/include/ddverify/pthread.h" struct __pthread_t_struct___0 { int id ; }; #line 25 "/usr/local/ddv/models/con2/include/ddverify/pthread.h" struct __pthread_mutex_t_struct { _Bool locked ; }; #line 30 "/usr/local/ddv/models/con2/include/ddverify/pthread.h" struct __pthread_mutexattr_t_struct { int dummy ; }; #line 50 "/usr/local/ddv/models/con2/include/ddverify/pthread.h" typedef struct __pthread_t_struct___0 pthread_t___0; #line 52 "/usr/local/ddv/models/con2/include/ddverify/pthread.h" typedef struct __pthread_mutex_t_struct pthread_mutex_t; #line 53 "/usr/local/ddv/models/con2/include/ddverify/pthread.h" typedef struct __pthread_mutexattr_t_struct pthread_mutexattr_t; #line 9 "/usr/local/ddv/models/con2/include/linux/list.h" struct list_head { struct list_head *next ; struct list_head *prev ; }; #line 4 "/usr/local/ddv/models/con2/include/linux/spinlock_types.h" struct __anonstruct_spinlock_t_9 { int init ; int locked ; }; #line 4 "/usr/local/ddv/models/con2/include/linux/spinlock_types.h" typedef struct __anonstruct_spinlock_t_9 spinlock_t; #line 4 "/usr/local/ddv/models/con2/include/linux/timer.h" struct timer_list { unsigned long expires ; void (*function)(unsigned long ) ; unsigned long data ; short __ddv_active ; short __ddv_init ; }; #line 82 "/usr/local/ddv/models/con2/include/linux/fs.h" struct hd_geometry; #line 168 "/usr/local/ddv/models/con2/include/linux/fs.h" struct block_device_operations { int (*open)(struct inode * , struct file * ) ; int (*release)(struct inode * , struct file * ) ; int (*ioctl)(struct inode * , struct file * , unsigned int , unsigned long ) ; long (*unlocked_ioctl)(struct file * , unsigned int , unsigned long ) ; long (*compat_ioctl)(struct file * , unsigned int , unsigned long ) ; int (*direct_access)(struct block_device * , sector_t , unsigned long * ) ; int (*media_changed)(struct gendisk * ) ; int (*revalidate_disk)(struct gendisk * ) ; int (*getgeo)(struct block_device * , struct hd_geometry * ) ; struct module *owner ; }; #line 18 "/usr/local/ddv/models/con2/include/linux/ioport.h" struct resource { char const *name ; unsigned long start ; unsigned long end ; unsigned long flags ; }; #line 24 "/usr/local/ddv/models/con2/include/linux/module.h" struct module { int something ; }; #line 8 "/usr/local/ddv/models/con2/include/linux/pm.h" struct pm_message { int event ; }; #line 8 "/usr/local/ddv/models/con2/include/linux/pm.h" typedef struct pm_message pm_message_t; #line 25 "/usr/local/ddv/models/con2/include/linux/device.h" struct device { void *driver_data ; void (*release)(struct device *dev ) ; }; #line 17 "/usr/local/ddv/models/con2/include/linux/genhd.h" struct request_queue; #line 17 "/usr/local/ddv/models/con2/include/linux/genhd.h" struct gendisk { int major ; int first_minor ; int minors ; char disk_name[32] ; struct block_device_operations *fops ; struct request_queue *queue ; void *private_data ; int flags ; struct device *driverfs_dev ; char devfs_name[64] ; }; #line 12 "/usr/local/ddv/models/con2/include/linux/workqueue.h" struct work_struct { unsigned long pending ; void (*func)(void * ) ; void *data ; int init ; }; #line 9 "/usr/local/ddv/models/con2/include/linux/mm_types.h" struct page { int something ; }; #line 4 "/usr/local/ddv/models/con2/include/asm/ptrace.h" struct pt_regs { int something ; }; #line 28 "/usr/local/ddv/models/con2/include/linux/interrupt.h" typedef int irqreturn_t; #line 34 "/usr/local/ddv/models/con2/include/linux/interrupt.h" struct tasklet_struct { atomic_t count ; void (*func)(unsigned long ) ; unsigned long data ; int init ; }; #line 11 "/usr/local/ddv/models/con2/include/linux/backing-dev.h" struct backing_dev_info { unsigned long ra_pages ; unsigned long state ; unsigned int capabilities ; }; #line 6 "/usr/local/ddv/models/con2/include/linux/bio.h" struct bio_vec { struct page *bv_page ; unsigned int bv_len ; unsigned int bv_offset ; }; #line 13 struct bio; #line 14 "/usr/local/ddv/models/con2/include/linux/bio.h" typedef int bio_end_io_t(struct bio * , unsigned int , int ); #line 17 "/usr/local/ddv/models/con2/include/linux/bio.h" struct bio { sector_t bi_sector ; struct bio *bi_next ; struct block_device *bi_bdev ; unsigned long bi_flags ; unsigned long bi_rw ; unsigned short bi_vcnt ; unsigned short bi_idx ; unsigned short bi_phys_segments ; unsigned int bi_size ; struct bio_vec *bi_io_vec ; bio_end_io_t *bi_end_io ; void *bi_private ; }; #line 4 "/usr/local/ddv/models/con2/include/linux/elevator.h" struct request; #line 23 "/usr/local/ddv/models/con2/include/linux/blkdev.h" typedef struct request_queue request_queue_t; #line 25 "/usr/local/ddv/models/con2/include/linux/blkdev.h" typedef void request_fn_proc(request_queue_t *q ); #line 26 "/usr/local/ddv/models/con2/include/linux/blkdev.h" typedef int make_request_fn(request_queue_t *q , struct bio *bio ); #line 27 "/usr/local/ddv/models/con2/include/linux/blkdev.h" typedef void unplug_fn(request_queue_t * ); #line 32 enum rq_cmd_type_bits { REQ_TYPE_FS = 1, REQ_TYPE_BLOCK_PC = 2, REQ_TYPE_SENSE = 3, REQ_TYPE_PM_SUSPEND = 4, REQ_TYPE_PM_RESUME = 5, REQ_TYPE_PM_SHUTDOWN = 6, REQ_TYPE_FLUSH = 7, REQ_TYPE_SPECIAL = 8, REQ_TYPE_LINUX_BLOCK = 9, REQ_TYPE_ATA_CMD = 10, REQ_TYPE_ATA_TASK = 11, REQ_TYPE_ATA_TASKFILE = 12, REQ_TYPE_ATA_PC = 13 } ; #line 54 "/usr/local/ddv/models/con2/include/linux/blkdev.h" struct request_queue { request_fn_proc *request_fn ; make_request_fn *make_request_fn ; unplug_fn *unplug_fn ; struct backing_dev_info backing_dev_info ; void *queuedata ; unsigned long queue_flags ; spinlock_t *queue_lock ; unsigned short hardsect_size ; int __ddv_genhd_no ; int __ddv_queue_alive ; }; #line 90 "/usr/local/ddv/models/con2/include/linux/blkdev.h" struct request { struct list_head queuelist ; struct list_head donelist ; request_queue_t *q ; unsigned long flags ; unsigned int cmd_flags ; enum rq_cmd_type_bits cmd_type ; struct bio *bio ; void *completion_data ; struct gendisk *rq_disk ; sector_t sector ; unsigned long nr_sectors ; unsigned int current_nr_sectors ; char *buffer ; int errors ; unsigned short nr_phys_segments ; unsigned char cmd[16] ; }; #line 15 "/usr/local/ddv/models/con2/include/ddverify/genhd.h" struct ddv_genhd { struct gendisk *gd ; struct inode inode ; struct file file ; struct request current_request ; int requests_open ; }; #line 6 "/usr/local/ddv/models/con2/include/linux/mod_devicetable.h" typedef unsigned long kernel_ulong_t; #line 10 "/usr/local/ddv/models/con2/include/linux/mod_devicetable.h" struct pci_device_id { __u32 vendor ; __u32 device ; __u32 subvendor ; __u32 subdevice ; __u32 class ; __u32 class_mask ; kernel_ulong_t driver_data ; }; #line 40 "/usr/local/ddv/models/con2/include/linux/pci.h" typedef int pci_power_t; #line 43 struct pci_bus; #line 43 "/usr/local/ddv/models/con2/include/linux/pci.h" struct pci_dev { struct pci_bus *bus ; unsigned int devfn ; unsigned short vendor ; unsigned short device ; u64 dma_mask ; struct device dev ; unsigned int irq ; struct resource resource[12] ; }; #line 62 "/usr/local/ddv/models/con2/include/linux/pci.h" struct pci_bus { unsigned char number ; }; #line 67 "/usr/local/ddv/models/con2/include/linux/pci.h" struct pci_driver { char *name ; struct pci_device_id const *id_table ; int (*probe)(struct pci_dev *dev , struct pci_device_id const *id ) ; void (*remove)(struct pci_dev *dev ) ; int (*suspend)(struct pci_dev *dev , pm_message_t state ) ; int (*resume)(struct pci_dev *dev ) ; int (*enable_wake)(struct pci_dev *dev , pci_power_t state , int enable ) ; void (*shutdown)(struct pci_dev *dev ) ; }; #line 6 "/usr/local/ddv/models/con2/include/ddverify/pci.h" struct ddv_pci_driver { struct pci_driver *pci_driver ; struct pci_dev pci_dev ; unsigned int no_pci_device_id ; int dev_initialized ; }; #line 9 "/usr/local/ddv/models/con2/include/ddverify/interrupt.h" struct registered_irq { irqreturn_t (*handler)(int , void * , struct pt_regs * ) ; void *dev_id ; }; #line 10 "/usr/local/ddv/models/con2/include/ddverify/tasklet.h" struct ddv_tasklet { struct tasklet_struct *tasklet ; unsigned short is_running ; }; #line 10 "/usr/local/ddv/models/con2/include/ddverify/timer.h" struct ddv_timer { struct timer_list *timer ; }; #line 88 "/usr/local/ddv/models/con2/include/linux/types.h" typedef unsigned int gfp_t; #line 8 "/usr/local/ddv/models/con2/include/asm/posix_types.h" typedef int __kernel_pid_t; #line 7 "/usr/local/ddv/models/con2/include/asm/types.h" typedef unsigned char __u8; #line 16 "/usr/local/ddv/models/con2/include/linux/types.h" typedef __kernel_pid_t pid_t; #line 7 "/usr/local/ddv/models/con2/include/asm/current.h" struct task_struct; #line 11 "/usr/local/ddv/models/con2/include/linux/wait.h" struct __wait_queue { int something ; }; #line 14 "/usr/local/ddv/models/con2/include/linux/wait.h" typedef struct __wait_queue wait_queue_t; #line 16 "/usr/local/ddv/models/con2/include/linux/wait.h" struct __wait_queue_head { int number_process_waiting ; int wakeup ; int init ; }; #line 22 "/usr/local/ddv/models/con2/include/linux/wait.h" typedef struct __wait_queue_head wait_queue_head_t; #line 10 "/usr/local/ddv/models/con2/include/asm/signal.h" struct __anonstruct_sigset_t_3 { unsigned long sig[2] ; }; #line 10 "/usr/local/ddv/models/con2/include/asm/signal.h" typedef struct __anonstruct_sigset_t_3 sigset_t; #line 24 "/usr/local/ddv/models/con2/include/linux/sched.h" struct sighand_struct { spinlock_t siglock ; }; #line 28 "/usr/local/ddv/models/con2/include/linux/sched.h" struct task_struct { long state ; pid_t pid ; char comm[16] ; sigset_t blocked ; sigset_t real_blocked ; struct sighand_struct *sighand ; }; #line 4 "/usr/local/ddv/models/con2/include/asm/semaphore.h" struct semaphore { int init ; int locked ; }; #line 4 "/usr/local/ddv/models/con2/include/linux/hdreg.h" struct hd_geometry { unsigned char heads ; unsigned char sectors ; unsigned short cylinders ; unsigned long start ; }; #line 153 "/usr/local/ddv/models/con2/include/linux/cdrom.h" struct cdrom_msf0 { __u8 minute ; __u8 second ; __u8 frame ; }; #line 161 "/usr/local/ddv/models/con2/include/linux/cdrom.h" union cdrom_addr { struct cdrom_msf0 msf ; int lba ; }; #line 179 "/usr/local/ddv/models/con2/include/linux/cdrom.h" struct cdrom_ti { __u8 cdti_trk0 ; __u8 cdti_ind0 ; __u8 cdti_trk1 ; __u8 cdti_ind1 ; }; #line 188 "/usr/local/ddv/models/con2/include/linux/cdrom.h" struct cdrom_tochdr { __u8 cdth_trk0 ; __u8 cdth_trk1 ; }; #line 195 "/usr/local/ddv/models/con2/include/linux/cdrom.h" struct cdrom_volctrl { __u8 channel0 ; __u8 channel1 ; __u8 channel2 ; __u8 channel3 ; }; #line 204 "/usr/local/ddv/models/con2/include/linux/cdrom.h" struct cdrom_subchnl { __u8 cdsc_format ; __u8 cdsc_audiostatus ; __u8 cdsc_adr : 4 ; __u8 cdsc_ctrl : 4 ; __u8 cdsc_trk ; __u8 cdsc_ind ; union cdrom_addr cdsc_absaddr ; union cdrom_addr cdsc_reladdr ; }; #line 218 "/usr/local/ddv/models/con2/include/linux/cdrom.h" struct cdrom_tocentry { __u8 cdte_track ; __u8 cdte_adr : 4 ; __u8 cdte_ctrl : 4 ; __u8 cdte_format ; union cdrom_addr cdte_addr ; __u8 cdte_datamode ; }; #line 237 "/usr/local/ddv/models/con2/include/linux/cdrom.h" struct cdrom_read_audio { union cdrom_addr addr ; __u8 addr_format ; int nframes ; __u8 *buf ; }; #line 246 "/usr/local/ddv/models/con2/include/linux/cdrom.h" struct cdrom_multisession { union cdrom_addr addr ; __u8 xa_flag ; __u8 addr_format ; }; #line 260 "/usr/local/ddv/models/con2/include/linux/cdrom.h" struct cdrom_mcn { __u8 medium_catalog_number[14] ; }; #line 280 struct request_sense; #line 694 "/usr/local/ddv/models/con2/include/linux/cdrom.h" struct request_sense { __u8 error_code : 7 ; __u8 valid : 1 ; __u8 segment_number ; __u8 sense_key : 4 ; __u8 reserved2 : 1 ; __u8 ili : 1 ; __u8 reserved1 : 2 ; __u8 information[4] ; __u8 add_sense_len ; __u8 command_info[4] ; __u8 asc ; __u8 ascq ; __u8 fruc ; __u8 sks[3] ; __u8 asb[46] ; }; #line 912 "/usr/local/ddv/models/con2/include/linux/cdrom.h" struct packet_command { unsigned char cmd[12] ; unsigned char *buffer ; unsigned int buflen ; int stat ; struct request_sense *sense ; unsigned char data_direction ; int quiet ; int timeout ; void *reserved[1] ; }; #line 933 struct cdrom_device_ops; #line 933 "/usr/local/ddv/models/con2/include/linux/cdrom.h" struct cdrom_device_info { struct cdrom_device_ops *ops ; struct cdrom_device_info *next ; struct gendisk *disk ; void *handle ; int mask ; int speed ; int capacity ; int options : 30 ; unsigned int mc_flags : 2 ; int use_count ; char name[20] ; __u8 sanyo_slot : 2 ; __u8 reserved : 6 ; int cdda_method ; __u8 last_sense ; __u8 media_written ; unsigned short mmc3_profile ; int for_data ; int (*exit)(struct cdrom_device_info * ) ; int mrw_mode_page ; }; #line 959 "/usr/local/ddv/models/con2/include/linux/cdrom.h" struct cdrom_device_ops { int (*open)(struct cdrom_device_info * , int ) ; void (*release)(struct cdrom_device_info * ) ; int (*drive_status)(struct cdrom_device_info * , int ) ; int (*media_changed)(struct cdrom_device_info * , int ) ; int (*tray_move)(struct cdrom_device_info * , int ) ; int (*lock_door)(struct cdrom_device_info * , int ) ; int (*select_speed)(struct cdrom_device_info * , int ) ; int (*select_disc)(struct cdrom_device_info * , int ) ; int (*get_last_session)(struct cdrom_device_info * , struct cdrom_multisession * ) ; int (*get_mcn)(struct cdrom_device_info * , struct cdrom_mcn * ) ; int (*reset)(struct cdrom_device_info * ) ; int (*audio_ioctl)(struct cdrom_device_info * , unsigned int , void * ) ; int (*dev_ioctl)(struct cdrom_device_info * , unsigned int , unsigned long ) ; int const capability ; int n_minors ; int (*generic_packet)(struct cdrom_device_info * , struct packet_command * ) ; }; #line 170 "cdu31a.h" struct s_sony_drive_config { unsigned char exec_status[2] ; char vendor_id[8] ; char product_id[16] ; char product_rev_level[8] ; unsigned char hw_config[2] ; }; #line 180 "cdu31a.h" struct s_sony_subcode { unsigned char exec_status[2] ; unsigned char address : 4 ; unsigned char control : 4 ; unsigned char track_num ; unsigned char index_num ; unsigned char rel_msf[3] ; unsigned char reserved1 ; unsigned char abs_msf[3] ; }; #line 227 "cdu31a.h" struct __anonstruct_tracks_14 { unsigned char address : 4 ; unsigned char control : 4 ; unsigned char track ; unsigned char track_start_msf[3] ; }; #line 227 "cdu31a.h" struct s_sony_session_toc { unsigned char exec_status[2] ; unsigned char session_number ; unsigned char address0 : 4 ; unsigned char control0 : 4 ; unsigned char point0 ; unsigned char first_track_num ; unsigned char disk_type ; unsigned char dummy0 ; unsigned char address1 : 4 ; unsigned char control1 : 4 ; unsigned char point1 ; unsigned char last_track_num ; unsigned char dummy1 ; unsigned char dummy2 ; unsigned char address2 : 4 ; unsigned char control2 : 4 ; unsigned char point2 ; unsigned char lead_out_start_msf[3] ; unsigned char addressb0 : 4 ; unsigned char controlb0 : 4 ; unsigned char pointb0 ; unsigned char next_poss_prog_area_msf[3] ; unsigned char num_mode_5_pointers ; unsigned char max_start_outer_leadout_msf[3] ; unsigned char addressb1 : 4 ; unsigned char controlb1 : 4 ; unsigned char pointb1 ; unsigned char dummyb0_1[4] ; unsigned char num_skip_interval_pointers ; unsigned char num_skip_track_assignments ; unsigned char dummyb0_2 ; unsigned char addressb2 : 4 ; unsigned char controlb2 : 4 ; unsigned char pointb2 ; unsigned char tracksb2[7] ; unsigned char addressb3 : 4 ; unsigned char controlb3 : 4 ; unsigned char pointb3 ; unsigned char tracksb3[7] ; unsigned char addressb4 : 4 ; unsigned char controlb4 : 4 ; unsigned char pointb4 ; unsigned char tracksb4[7] ; unsigned char addressc0 : 4 ; unsigned char controlc0 : 4 ; unsigned char pointc0 ; unsigned char dummyc0[7] ; struct __anonstruct_tracks_14 tracks[100] ; unsigned int start_track_lba ; unsigned int lead_out_start_lba ; unsigned int mint ; unsigned int maxt ; }; #line 290 "cdu31a.h" struct __anonstruct_tracks_15 { unsigned char address : 4 ; unsigned char control : 4 ; unsigned char track ; unsigned char track_start_msf[3] ; }; #line 290 "cdu31a.h" struct s_all_sessions_toc { unsigned char sessions ; unsigned int track_entries ; unsigned char first_track_num ; unsigned char last_track_num ; unsigned char disk_type ; unsigned char lead_out_start_msf[3] ; struct __anonstruct_tracks_15 tracks[100] ; unsigned int start_track_lba ; unsigned int lead_out_start_lba ; }; #line 190 "cdu31a.c" struct __anonstruct_cdu31a_addresses_16 { unsigned short base ; short int_num ; }; #line 34 "/usr/local/ddv/models/con2/include/linux/miscdevice.h" struct miscdevice { int minor ; char const *name ; struct file_operations *fops ; }; #line 7 "/usr/local/ddv/models/con2/include/linux/proc_fs.h" struct proc_dir_entry { int something ; }; #line 20 "/usr/local/ddv/models/con2/include/linux/mutex.h" struct mutex { int locked ; int init ; }; #line 7 "/usr/local/ddv/models/con2/include/asm/posix_types.h" typedef long __kernel_off_t; #line 15 "/usr/local/ddv/models/con2/include/linux/types.h" typedef __kernel_off_t off_t; #line 6 "/usr/local/ddv/models/con2/include/asm/termbits.h" typedef unsigned char cc_t; #line 8 "/usr/local/ddv/models/con2/include/asm/termbits.h" typedef unsigned int tcflag_t; #line 11 "/usr/local/ddv/models/con2/include/asm/termbits.h" struct termios { tcflag_t c_iflag ; tcflag_t c_oflag ; tcflag_t c_cflag ; tcflag_t c_lflag ; cc_t c_line ; cc_t c_cc[19] ; }; #line 9 "/usr/local/ddv/models/con2/include/linux/tty_driver.h" struct tty_struct; #line 12 "/usr/local/ddv/models/con2/include/linux/tty_driver.h" struct tty_operations { int (*open)(struct tty_struct *tty , struct file *filp ) ; void (*close)(struct tty_struct *tty , struct file *filp ) ; int (*write)(struct tty_struct *tty , unsigned char const *buf , int count ) ; void (*put_char)(struct tty_struct *tty , unsigned char ch ) ; void (*flush_chars)(struct tty_struct *tty ) ; int (*write_room)(struct tty_struct *tty ) ; int (*chars_in_buffer)(struct tty_struct *tty ) ; int (*ioctl)(struct tty_struct *tty , struct file *file , unsigned int cmd , unsigned long arg ) ; void (*set_termios)(struct tty_struct *tty , struct termios *old ) ; void (*throttle)(struct tty_struct *tty ) ; void (*unthrottle)(struct tty_struct *tty ) ; void (*stop)(struct tty_struct *tty ) ; void (*start)(struct tty_struct *tty ) ; void (*hangup)(struct tty_struct *tty ) ; void (*break_ctl)(struct tty_struct *tty , int state ) ; void (*flush_buffer)(struct tty_struct *tty ) ; void (*set_ldisc)(struct tty_struct *tty ) ; void (*wait_until_sent)(struct tty_struct *tty , int timeout ) ; void (*send_xchar)(struct tty_struct *tty , char ch ) ; int (*read_proc)(char *page , char **start , off_t off , int count , int *eof , void *data ) ; int (*write_proc)(struct file *file , char const *buffer , unsigned long count , void *data ) ; int (*tiocmget)(struct tty_struct *tty , struct file *file ) ; int (*tiocmset)(struct tty_struct *tty , struct file *file , unsigned int set , unsigned int clear ) ; }; #line 43 "/usr/local/ddv/models/con2/include/linux/tty_driver.h" struct tty_driver { int magic ; struct cdev cdev ; struct module *owner ; char const *driver_name ; char const *name ; int name_base ; int major ; int minor_start ; int minor_num ; int num ; short type ; short subtype ; struct termios init_termios ; int flags ; int refcount ; struct proc_dir_entry *proc_entry ; int (*open)(struct tty_struct *tty , struct file *filp ) ; void (*close)(struct tty_struct *tty , struct file *filp ) ; int (*write)(struct tty_struct *tty , unsigned char const *buf , int count ) ; void (*put_char)(struct tty_struct *tty , unsigned char ch ) ; void (*flush_chars)(struct tty_struct *tty ) ; int (*write_room)(struct tty_struct *tty ) ; int (*chars_in_buffer)(struct tty_struct *tty ) ; int (*ioctl)(struct tty_struct *tty , struct file *file , unsigned int cmd , unsigned long arg ) ; void (*set_termios)(struct tty_struct *tty , struct termios *old ) ; void (*throttle)(struct tty_struct *tty ) ; void (*unthrottle)(struct tty_struct *tty ) ; void (*stop)(struct tty_struct *tty ) ; void (*start)(struct tty_struct *tty ) ; void (*hangup)(struct tty_struct *tty ) ; void (*break_ctl)(struct tty_struct *tty , int state ) ; void (*flush_buffer)(struct tty_struct *tty ) ; void (*set_ldisc)(struct tty_struct *tty ) ; void (*wait_until_sent)(struct tty_struct *tty , int timeout ) ; void (*send_xchar)(struct tty_struct *tty , char ch ) ; int (*read_proc)(char *page , char **start , off_t off , int count , int *eof , void *data ) ; int (*write_proc)(struct file *file , char const *buffer , unsigned long count , void *data ) ; int (*tiocmget)(struct tty_struct *tty , struct file *file ) ; int (*tiocmset)(struct tty_struct *tty , struct file *file , unsigned int set , unsigned int clear ) ; }; #line 113 "/usr/local/ddv/models/con2/include/linux/tty.h" struct tty_struct { int magic ; struct tty_driver *driver ; int index ; struct termios *termios ; struct termios *termios_locked ; char name[64] ; unsigned long flags ; int count ; unsigned char stopped : 1 ; unsigned char hw_stopped : 1 ; unsigned char flow_stopped : 1 ; unsigned char packet : 1 ; unsigned int receive_room ; wait_queue_head_t write_wait ; wait_queue_head_t read_wait ; void *disc_data ; void *driver_data ; unsigned char closing : 1 ; }; #line 7 "/usr/local/ddv/models/con2/include/ddverify/tty.h" struct ddv_tty_driver { struct tty_driver driver ; unsigned short allocated ; unsigned short registered ; }; #line 1 "cdev.o" #pragma merger("0","/tmp/cil-_7nNmTmA.i","") #line 11 "/usr/local/ddv/models/con2/include/ddverify/ddverify.h" int current_execution_context ; #line 42 "/usr/local/ddv/models/con2/include/ddverify/ddverify.h" int (*_ddv_module_init)(void) ; #line 43 "/usr/local/ddv/models/con2/include/ddverify/ddverify.h" void (*_ddv_module_exit)(void) ; #line 15 "/usr/local/ddv/models/con2/include/ddverify/satabs.h" extern unsigned short nondet_ushort() ; #line 16 extern int nondet_int() ; #line 17 extern unsigned int nondet_uint() ; #line 19 extern unsigned long nondet_ulong() ; #line 20 extern char nondet_char() ; #line 23 extern loff_t nondet_loff_t() ; #line 24 extern size_t nondet_size_t() ; #line 57 extern pthread_t nondet_pthread_t() ; #line 59 "/usr/local/ddv/models/con2/include/ddverify/satabs.h" __inline extern int pthread_create(pthread_t *__threadp , pthread_attr_t const *__attr , void *(*__start_routine)(void * ) , void *__arg ) { { #line 65 *__threadp = nondet_pthread_t(); #line 66 (*__start_routine)(__arg); #line 67 return (0); } } #line 7 "/usr/local/ddv/models/con2/include/linux/jiffies.h" unsigned long jiffies ; #line 12 "/usr/local/ddv/models/con2/include/ddverify/fixed_cdev.h" struct cdev fixed_cdev[10] ; #line 13 "/usr/local/ddv/models/con2/include/ddverify/fixed_cdev.h" int fixed_cdev_used = 0; #line 11 "/usr/local/ddv/models/con2/include/ddverify/cdev.h" short number_cdev_registered = (short)0; #line 22 "/usr/local/ddv/models/con2/include/ddverify/cdev.h" struct ddv_cdev cdev_registered[10] ; #line 24 void call_cdev_functions(void) ; #line 21 "/usr/local/ddv/models/con2/src/ddverify/cdev.c" extern int ( /* missing proto */ __CPROVER_assume)() ; #line 5 "/usr/local/ddv/models/con2/src/ddverify/cdev.c" void call_cdev_functions(void) { int cdev_no ; int result ; loff_t loff_t_value ; int int_value ; unsigned int uint_value ; unsigned long ulong_value ; char char_value ; size_t size_t_value ; unsigned short tmp ; int tmp___0 ; unsigned short tmp___1 ; { #line 16 if ((int )number_cdev_registered == 0) { #line 17 return; } #line 20 tmp = nondet_ushort(); #line 20 cdev_no = (int )tmp; #line 21 if (0 <= cdev_no) { #line 21 if (cdev_no < (int )number_cdev_registered) { #line 21 tmp___0 = 1; } else { #line 21 tmp___0 = 0; } } else { #line 21 tmp___0 = 0; } #line 21 __CPROVER_assume(tmp___0); #line 23 tmp___1 = nondet_ushort(); #line 23 switch ((int )tmp___1) { case 0: #line 25 if (((cdev_registered[cdev_no].cdevp)->ops)->llseek) { #line 26 loff_t_value = nondet_loff_t(); #line 27 int_value = nondet_int(); #line 29 (*(((cdev_registered[cdev_no].cdevp)->ops)->llseek))(& cdev_registered[cdev_no].filp, loff_t_value, int_value); } #line 33 break; case 1: #line 35 if (((cdev_registered[cdev_no].cdevp)->ops)->read) { #line 36 char_value = nondet_char(); #line 37 size_t_value = nondet_size_t(); #line 39 (*(((cdev_registered[cdev_no].cdevp)->ops)->read))(& cdev_registered[cdev_no].filp, & char_value, size_t_value, & loff_t_value); } #line 44 break; case 2: #line 47 break; case 3: #line 49 if (((cdev_registered[cdev_no].cdevp)->ops)->write) { #line 50 char_value = nondet_char(); #line 51 size_t_value = nondet_size_t(); #line 53 (*(((cdev_registered[cdev_no].cdevp)->ops)->write))(& cdev_registered[cdev_no].filp, (char const *)(& char_value), size_t_value, & loff_t_value); } #line 58 break; case 4: #line 61 break; case 5: #line 64 break; case 6: #line 67 break; case 7: #line 69 if (((cdev_registered[cdev_no].cdevp)->ops)->ioctl) { #line 70 uint_value = nondet_uint(); #line 71 ulong_value = nondet_ulong(); #line 73 (*(((cdev_registered[cdev_no].cdevp)->ops)->ioctl))(& cdev_registered[cdev_no].inode, & cdev_registered[cdev_no].filp, uint_value, ulong_value); } #line 79 break; case 8: #line 82 break; case 9: #line 85 break; case 10: #line 88 break; case 11: #line 90 if (((cdev_registered[cdev_no].cdevp)->ops)->open) { #line 90 if (! cdev_registered[cdev_no].open) { #line 92 result = (*(((cdev_registered[cdev_no].cdevp)->ops)->open))(& cdev_registered[cdev_no].inode, & cdev_registered[cdev_no].filp); #line 95 if (! result) { #line 96 cdev_registered[cdev_no].open = 1; } } } #line 99 break; case 12: #line 102 break; case 13: #line 104 if (((cdev_registered[cdev_no].cdevp)->ops)->release) { #line 104 if (cdev_registered[cdev_no].open) { #line 106 result = (*(((cdev_registered[cdev_no].cdevp)->ops)->release))(& cdev_registered[cdev_no].inode, & cdev_registered[cdev_no].filp); #line 109 if (! result) { #line 110 cdev_registered[cdev_no].open = 0; } } } #line 113 break; case 14: #line 116 break; case 15: #line 119 break; case 16: #line 122 break; case 17: #line 125 break; case 18: #line 128 break; case 19: #line 131 break; case 20: #line 134 break; case 21: #line 137 break; case 22: #line 140 break; case 23: #line 143 break; case 24: #line 146 break; case 25: #line 149 break; case 26: #line 152 break; default: #line 154 break; } #line 156 return; } } #line 1 "char_dev.o" #pragma merger("0","/tmp/cil-ly8eCo8J.i","") #line 8 "/usr/local/ddv/models/con2/include/linux/slab.h" extern void kfree(void const * ) ; #line 195 "/usr/local/ddv/models/con2/include/linux/fs.h" __inline int alloc_chrdev_region(dev_t *dev , unsigned int baseminor , unsigned int count , char const *name ) ; #line 196 __inline int register_chrdev_region(dev_t from , unsigned int count , char const *name ) ; #line 199 __inline int register_chrdev(unsigned int major , char const *name , struct file_operations *fops ) ; #line 200 __inline int unregister_chrdev(unsigned int major , char const *name ) ; #line 11 "/usr/local/ddv/models/con2/include/linux/cdev.h" __inline void cdev_init(struct cdev *cdev , struct file_operations *fops ) ; #line 13 __inline struct cdev *cdev_alloc(void) ; #line 17 __inline int cdev_add(struct cdev *p , dev_t dev , unsigned int count ) ; #line 19 __inline void cdev_del(struct cdev *p ) ; #line 9 "/usr/local/ddv/models/con2/src/linux/fs/char_dev.c" __inline int alloc_chrdev_region(dev_t *dev , unsigned int baseminor , unsigned int count , char const *name ) { int major ; int return_value ; int tmp ; int tmp___0 ; unsigned int tmp___1 ; { #line 12 tmp = nondet_int(); #line 12 return_value = tmp; #line 13 if (return_value == 0) { #line 13 tmp___0 = 1; } else #line 13 if (return_value == -1) { #line 13 tmp___0 = 1; } else { #line 13 tmp___0 = 0; } #line 13 __CPROVER_assume(tmp___0); #line 15 if (return_value == 0) { #line 16 tmp___1 = nondet_uint(); #line 16 major = (int )tmp___1; #line 17 *dev = (unsigned int )(major << 20) | baseminor; } #line 20 return (return_value); } } #line 23 "/usr/local/ddv/models/con2/src/linux/fs/char_dev.c" __inline int register_chrdev_region(dev_t from , unsigned int count , char const *name ) { int return_value ; int tmp ; int tmp___0 ; { #line 25 tmp = nondet_int(); #line 25 return_value = tmp; #line 26 if (return_value == 0) { #line 26 tmp___0 = 1; } else #line 26 if (return_value == -1) { #line 26 tmp___0 = 1; } else { #line 26 tmp___0 = 0; } #line 26 __CPROVER_assume(tmp___0); #line 28 return (return_value); } } #line 33 "/usr/local/ddv/models/con2/src/linux/fs/char_dev.c" __inline int register_chrdev(unsigned int major , char const *name , struct file_operations *fops ) { struct cdev *cdev ; int err ; int tmp ; { #line 39 tmp = register_chrdev_region((dev_t )0, 256U, name); #line 39 major = (unsigned int )tmp; #line 41 cdev = cdev_alloc(); #line 42 cdev->owner = fops->owner; #line 43 cdev->ops = fops; #line 45 err = cdev_add(cdev, major << 20, 256U); #line 47 if (err) { #line 48 kfree((void const *)cdev); #line 49 return (err); } #line 52 return ((int )major); } } #line 55 "/usr/local/ddv/models/con2/src/linux/fs/char_dev.c" __inline int unregister_chrdev(unsigned int major , char const *name ) { { #line 57 return (0); } } #line 60 "/usr/local/ddv/models/con2/src/linux/fs/char_dev.c" __inline struct cdev *cdev_alloc(void) { int tmp ; { #line 62 if (fixed_cdev_used < 10) { #line 63 tmp = fixed_cdev_used; #line 63 fixed_cdev_used ++; #line 63 return (& fixed_cdev[tmp]); } #line 65 return ((struct cdev *)0); } } #line 67 "/usr/local/ddv/models/con2/src/linux/fs/char_dev.c" __inline void cdev_init(struct cdev *cdev , struct file_operations *fops ) { { #line 69 cdev->ops = fops; #line 70 return; } } #line 72 "/usr/local/ddv/models/con2/src/linux/fs/char_dev.c" __inline int cdev_add(struct cdev *p , dev_t dev , unsigned int count ) { int return_value ; int tmp ; int tmp___0 ; { #line 74 p->dev = dev; #line 75 p->count = count; #line 77 tmp = nondet_int(); #line 77 return_value = tmp; #line 78 if (return_value == 0) { #line 78 tmp___0 = 1; } else #line 78 if (return_value == -1) { #line 78 tmp___0 = 1; } else { #line 78 tmp___0 = 0; } #line 78 __CPROVER_assume(tmp___0); #line 80 if (return_value == 0) { #line 81 if ((int )number_cdev_registered < 10) { #line 83 cdev_registered[number_cdev_registered].cdevp = p; #line 84 cdev_registered[number_cdev_registered].inode.i_rdev = dev; #line 85 cdev_registered[number_cdev_registered].inode.i_cdev = p; #line 86 cdev_registered[number_cdev_registered].open = 0; #line 88 number_cdev_registered = (short )((int )number_cdev_registered + 1); } else { #line 90 return (-1); } } #line 94 return (return_value); } } #line 97 "/usr/local/ddv/models/con2/src/linux/fs/char_dev.c" __inline void cdev_del(struct cdev *p ) { int i ; { #line 101 i = 0; #line 101 while (i < (int )number_cdev_registered) { #line 102 if ((unsigned long )cdev_registered[i].cdevp == (unsigned long )p) { #line 103 cdev_registered[i].cdevp = (struct cdev *)0; #line 105 return; } #line 101 i ++; } #line 108 return; } } #line 1 "ddverify.o" #pragma merger("0","/tmp/cil-bj2uambR.i","") #line 45 "/usr/local/ddv/models/con2/include/ddverify/ddverify.h" int call_ddv(void) ; #line 39 "/usr/local/ddv/models/con2/include/ddverify/satabs.h" extern void __CPROVER_atomic_begin() ; #line 40 extern void __CPROVER_atomic_end() ; #line 186 "/usr/local/ddv/models/con2/include/ddverify/pthread.h" __inline extern int pthread_mutex_init(pthread_mutex_t *__mutex , pthread_mutexattr_t const *__mutex_attr ) { pthread_mutex_t i ; { #line 190 i.locked = (_Bool)0; #line 191 *__mutex = i; #line 192 return (0); } } #line 194 "/usr/local/ddv/models/con2/include/ddverify/pthread.h" __inline extern int pthread_mutex_destroy(pthread_mutex_t *__mutex ) { { #line 196 return (0); } } #line 203 "/usr/local/ddv/models/con2/include/ddverify/pthread.h" __inline extern int pthread_mutex_lock(pthread_mutex_t *__mutex ) { { #line 206 __CPROVER_atomic_begin(); #line 207 __CPROVER_assume(! __mutex->locked); #line 208 __mutex->locked = (_Bool)1; #line 209 __CPROVER_atomic_end(); #line 210 return (0); } } #line 216 extern int ( /* missing proto */ __CPROVER_assert)() ; #line 213 "/usr/local/ddv/models/con2/include/ddverify/pthread.h" __inline extern int pthread_mutex_unlock(pthread_mutex_t *__mutex ) { { #line 216 __CPROVER_assert((int )__mutex->locked, "pthread_mutex_unlock without lock"); #line 217 __mutex->locked = (_Bool)0; #line 218 return (0); } } #line 9 "/usr/local/ddv/models/con2/include/linux/spinlock.h" void spin_lock_init(spinlock_t *lock ) ; #line 12 "/usr/local/ddv/models/con2/include/ddverify/genhd.h" short number_genhd_registered = (short)0; #line 13 "/usr/local/ddv/models/con2/include/ddverify/genhd.h" short number_fixed_genhd_used = (short)0; #line 24 "/usr/local/ddv/models/con2/include/ddverify/genhd.h" struct gendisk fixed_gendisk[10] ; #line 25 "/usr/local/ddv/models/con2/include/ddverify/genhd.h" struct ddv_genhd genhd_registered[10] ; #line 14 "/usr/local/ddv/models/con2/include/ddverify/pci.h" struct ddv_pci_driver registered_pci_driver ; #line 19 extern void call_pci_functions() ; #line 14 "/usr/local/ddv/models/con2/include/ddverify/interrupt.h" struct registered_irq registered_irq[16] ; #line 16 void call_interrupt_handler(void) ; #line 8 "/usr/local/ddv/models/con2/include/ddverify/tasklet.h" short number_tasklet_registered = (short)0; #line 15 "/usr/local/ddv/models/con2/include/ddverify/tasklet.h" struct ddv_tasklet tasklet_registered[10] ; #line 17 void call_tasklet_functions(void) ; #line 8 "/usr/local/ddv/models/con2/include/ddverify/timer.h" short number_timer_registered = (short)0; #line 14 "/usr/local/ddv/models/con2/include/ddverify/timer.h" struct ddv_timer timer_registered[5] ; #line 16 extern void call_timer_functions() ; #line 8 "/usr/local/ddv/models/con2/include/ddverify/workqueue.h" struct work_struct *shared_workqueue[10] ; #line 10 void call_shared_workqueue_functions(void) ; #line 7 "/usr/local/ddv/models/con2/include/linux/smp_lock.h" spinlock_t kernel_lock ; #line 15 "/usr/local/ddv/models/con2/src/ddverify/ddverify.c" void init_kernel(void) { int i ; { #line 19 spin_lock_init(& kernel_lock); #line 21 i = 0; #line 21 while (i < 10) { #line 22 shared_workqueue[i] = (struct work_struct *)((void *)0); #line 21 i ++; } #line 25 i = 0; #line 25 while (i < 10) { #line 26 tasklet_registered[i].tasklet = (struct tasklet_struct *)((void *)0); #line 27 tasklet_registered[i].is_running = (unsigned short)0; #line 25 i ++; } #line 29 return; } } #line 31 "/usr/local/ddv/models/con2/src/ddverify/ddverify.c" static void *ddv_2(void *arg ) { unsigned short random ; { #line 35 while (1) { #line 36 random = nondet_ushort(); #line 38 switch ((int )random) { case 1: #line 40 current_execution_context = 2; #line 41 call_timer_functions(); #line 42 current_execution_context = 1; #line 43 break; case 2: #line 46 current_execution_context = 2; #line 47 call_interrupt_handler(); #line 48 current_execution_context = 1; #line 49 break; case 3: #line 52 current_execution_context = 1; #line 53 call_shared_workqueue_functions(); #line 54 current_execution_context = 1; #line 55 break; case 4: #line 58 current_execution_context = 2; #line 59 call_tasklet_functions(); #line 60 current_execution_context = 1; #line 61 break; case 5: #line 64 current_execution_context = 1; #line 65 call_pci_functions(); #line 66 current_execution_context = 1; #line 67 break; default: #line 70 break; } #line 35 if (! random) { #line 35 break; } } #line 73 return ((void *)0); } } #line 75 "/usr/local/ddv/models/con2/src/ddverify/ddverify.c" void ddv(void) { pthread_t___0 thread ; int tmp ; { #line 81 pthread_create((struct __pthread_t_struct *)(& thread), (struct __pthread_attr_t_struct const *)((void *)0), & ddv_2, (void *)0); #line 83 while (1) { #line 84 current_execution_context = 1; #line 86 call_cdev_functions(); #line 83 tmp = nondet_int(); #line 83 if (! tmp) { #line 83 break; } } #line 93 return; } } #line 95 "/usr/local/ddv/models/con2/src/ddverify/ddverify.c" int call_ddv(void) { int err ; { #line 99 current_execution_context = 1; #line 101 init_kernel(); #line 103 err = (*_ddv_module_init)(); #line 105 if (err) { #line 106 return (-1); } #line 110 ddv(); #line 112 current_execution_context = 1; #line 113 (*_ddv_module_exit)(); #line 115 return (0); } } #line 1 "genhd.o" #pragma merger("0","/tmp/cil-rZZToN9n.i","") #line 9 "/usr/local/ddv/models/con2/include/ddverify/satabs.h" extern void *malloc(size_t size ) ; #line 207 "/usr/local/ddv/models/con2/include/linux/fs.h" int register_blkdev(unsigned int major , char const *name ) ; #line 208 int unregister_blkdev(unsigned int major , char const *name ) ; #line 33 "/usr/local/ddv/models/con2/include/linux/genhd.h" void add_disk(struct gendisk *disk ) ; #line 35 void del_gendisk(struct gendisk *gp ) ; #line 37 struct gendisk *alloc_disk(int minors ) ; #line 6 "/usr/local/ddv/models/con2/src/linux/block/genhd.c" int register_blkdev(unsigned int major , char const *name ) { int result ; int tmp ; { #line 8 tmp = nondet_int(); #line 8 result = tmp; #line 14 return (result); } } #line 17 "/usr/local/ddv/models/con2/src/linux/block/genhd.c" int unregister_blkdev(unsigned int major , char const *name ) { { #line 19 return (0); } } #line 22 "/usr/local/ddv/models/con2/src/linux/block/genhd.c" struct gendisk *alloc_disk(int minors ) { struct gendisk *gd ; { #line 26 if ((int )number_fixed_genhd_used < 10) { #line 27 gd = & fixed_gendisk[number_fixed_genhd_used]; #line 28 gd->minors = minors; #line 30 number_fixed_genhd_used = (short )((int )number_fixed_genhd_used + 1); #line 32 return (gd); } else { #line 34 return ((struct gendisk *)((void *)0)); } } } #line 38 "/usr/local/ddv/models/con2/src/linux/block/genhd.c" void add_disk(struct gendisk *disk ) { void *tmp ; { #line 40 if ((int )number_genhd_registered < 10) { #line 41 genhd_registered[number_genhd_registered].gd = disk; #line 42 tmp = malloc((size_t )sizeof(struct block_device )); #line 42 genhd_registered[number_genhd_registered].inode.i_bdev = (struct block_device *)tmp; #line 43 (genhd_registered[number_genhd_registered].inode.i_bdev)->bd_disk = disk; #line 45 number_genhd_registered = (short )((int )number_genhd_registered + 1); } #line 47 return; } } #line 49 "/usr/local/ddv/models/con2/src/linux/block/genhd.c" void del_gendisk(struct gendisk *gp ) { int i ; { #line 53 i = 0; #line 53 while (i < (int )number_genhd_registered) { #line 54 if ((unsigned long )genhd_registered[i].gd == (unsigned long )gp) { #line 55 genhd_registered[i].gd = (struct gendisk *)((void *)0); } #line 53 i ++; } #line 58 return; } } #line 1 "interrupt.o" #pragma merger("0","/tmp/cil-hWfrjtlm.i","") #line 10 "/usr/local/ddv/models/con2/src/ddverify/interrupt.c" void call_interrupt_handler(void) { unsigned short i ; struct pt_regs regs ; int tmp ; { #line 15 tmp = nondet_int(); #line 15 i = (unsigned short )tmp; #line 16 __CPROVER_assume((int )i < 16); #line 18 if (registered_irq[i].handler) { #line 19 (*(registered_irq[i].handler))((int )i, registered_irq[i].dev_id, & regs); } #line 22 return; } } #line 1 "ioctl.o" #pragma merger("0","/tmp/cil-a1MiuK_K.i","") #line 1 "ll_rw_blk.o" #pragma merger("0","/tmp/cil-mg60nJbW.i","") #line 192 "/usr/local/ddv/models/con2/include/linux/blkdev.h" request_queue_t *blk_alloc_queue(gfp_t gfp_mask ) ; #line 194 request_queue_t *blk_init_queue(request_fn_proc *rfn , spinlock_t *lock ) ; #line 196 void blk_queue_make_request(request_queue_t *q , make_request_fn *mfn ) ; #line 198 void blk_queue_hardsect_size(request_queue_t *q , unsigned short size ) ; #line 200 void blk_cleanup_queue(request_queue_t *q ) ; #line 220 void end_request(struct request *req , int uptodate ) ; #line 6 "/usr/local/ddv/models/con2/include/ddverify/blkdev.h" request_queue_t fixed_request_queue[10] ; #line 8 "/usr/local/ddv/models/con2/include/ddverify/blkdev.h" int number_request_queue_used = 0; #line 7 "/usr/local/ddv/models/con2/src/linux/block/ll_rw_blk.c" request_queue_t *get_fixed_request_queue(void) { int tmp ; { #line 9 if (number_request_queue_used < 10) { #line 10 tmp = number_request_queue_used; #line 10 number_request_queue_used ++; #line 10 return (& fixed_request_queue[tmp]); } else { #line 12 return ((request_queue_t *)((void *)0)); } } } #line 16 "/usr/local/ddv/models/con2/src/linux/block/ll_rw_blk.c" request_queue_t *blk_init_queue(request_fn_proc *rfn , spinlock_t *lock ) { request_queue_t *queue ; int tmp ; { #line 20 tmp = nondet_int(); #line 20 if (tmp) { #line 21 queue = get_fixed_request_queue(); #line 23 queue->queue_lock = lock; #line 24 queue->request_fn = rfn; #line 25 queue->make_request_fn = (make_request_fn *)((void *)0); #line 26 queue->__ddv_queue_alive = 1; #line 28 return (queue); } else { #line 30 return ((request_queue_t *)((void *)0)); } } } #line 34 "/usr/local/ddv/models/con2/src/linux/block/ll_rw_blk.c" request_queue_t *blk_alloc_queue(gfp_t gfp_mask ) { request_queue_t *queue ; int tmp ; { #line 38 tmp = nondet_int(); #line 38 if (tmp) { #line 39 queue = get_fixed_request_queue(); #line 41 queue->request_fn = (request_fn_proc *)((void *)0); #line 42 queue->make_request_fn = (make_request_fn *)((void *)0); #line 43 queue->__ddv_queue_alive = 1; #line 45 return (queue); } else { #line 47 return ((request_queue_t *)((void *)0)); } } } #line 51 "/usr/local/ddv/models/con2/src/linux/block/ll_rw_blk.c" void blk_queue_make_request(request_queue_t *q , make_request_fn *mfn ) { { #line 53 q->make_request_fn = mfn; #line 54 return; } } #line 56 "/usr/local/ddv/models/con2/src/linux/block/ll_rw_blk.c" void end_request(struct request *req , int uptodate ) { int genhd_no ; { #line 58 genhd_no = ((req->rq_disk)->queue)->__ddv_genhd_no; #line 60 genhd_registered[genhd_no].requests_open = 0; #line 61 return; } } #line 64 "/usr/local/ddv/models/con2/src/linux/block/ll_rw_blk.c" void blk_queue_hardsect_size(request_queue_t *q , unsigned short size ) { { #line 66 q->hardsect_size = size; #line 67 return; } } #line 69 "/usr/local/ddv/models/con2/src/linux/block/ll_rw_blk.c" void blk_cleanup_queue(request_queue_t *q ) { { #line 71 q->__ddv_queue_alive = 0; #line 72 return; } } #line 1 "__main.o" #pragma merger("0","/tmp/cil-DvHgsI24.i","") #line 26 "/usr/local/ddv/models/con2/include/linux/timer.h" void init_timer(struct timer_list *timer ) ; #line 28 void add_timer(struct timer_list *timer ) ; #line 29 int del_timer(struct timer_list *timer ) ; #line 12 "/usr/local/ddv/models/con2/include/linux/spinlock.h" void spin_lock_irq(spinlock_t *lock ) ; #line 17 void spin_unlock_irq(spinlock_t *lock ) ; #line 9 "/usr/local/ddv/models/con2/include/asm/current.h" extern struct task_struct *get_current(void) ; #line 66 "/usr/local/ddv/models/con2/include/linux/wait.h" extern void prepare_to_wait(wait_queue_head_t *q , wait_queue_t *wait , int state ) ; #line 68 extern void finish_wait(wait_queue_head_t *q , wait_queue_t *wait ) ; #line 75 void wake_up_interruptible(wait_queue_head_t *q ) ; #line 85 extern int waitqueue_active(wait_queue_head_t *q ) ; #line 4 "/usr/local/ddv/models/con2/include/asm/string.h" extern void *memset(void *s , int c , unsigned int n ) ; #line 11 "/usr/local/ddv/models/con2/include/linux/string.h" extern char *strcat(char * , char const * ) ; #line 31 extern void *memmove(void * , void const * , __kernel_size_t ) ; #line 40 "/usr/local/ddv/models/con2/include/linux/sched.h" extern int signal_pending(struct task_struct *p ) ; #line 43 void schedule(void) ; #line 53 extern void yield(void) ; #line 34 "/usr/local/ddv/models/con2/include/linux/kernel.h" extern int printk(char const *fmt , ...) ; #line 35 extern int sprintf(char *buf , char const *fmt , ...) ; #line 31 "/usr/local/ddv/models/con2/include/asm/semaphore.h" int down_interruptible(struct semaphore *sem ) ; #line 33 int down_trylock(struct semaphore *sem ) ; #line 35 void up(struct semaphore *sem ) ; #line 90 "/usr/local/ddv/models/con2/include/linux/ioport.h" struct resource *request_region(unsigned long start , unsigned long len , char const *name ) ; #line 92 void release_region(unsigned long start , unsigned long len ) ; #line 39 "/usr/local/ddv/models/con2/include/linux/genhd.h" extern void put_disk(struct gendisk *disk ) ; #line 75 "/usr/local/ddv/models/con2/include/linux/interrupt.h" int request_irq(unsigned int irq , irqreturn_t (*handler)(int , void * , struct pt_regs * ) , unsigned long irqflags , char const *devname , void *dev_id ) ; #line 78 void free_irq(unsigned int irq , void *dev_id ) ; #line 989 "/usr/local/ddv/models/con2/include/linux/cdrom.h" extern int cdrom_open(struct cdrom_device_info *cdi , struct inode *ip , struct file *fp ) ; #line 991 extern int cdrom_release(struct cdrom_device_info *cdi , struct file *fp ) ; #line 992 extern int cdrom_ioctl(struct file *file , struct cdrom_device_info *cdi , struct inode *ip , unsigned int cmd , unsigned long arg ) ; #line 994 extern int cdrom_media_changed(struct cdrom_device_info * ) ; #line 996 extern int register_cdrom(struct cdrom_device_info *cdi ) ; #line 997 extern int unregister_cdrom(struct cdrom_device_info *cdi ) ; #line 14 "/usr/local/ddv/models/con2/include/asm/io.h" unsigned char inb(unsigned int port ) ; #line 15 void outb(unsigned char byte , unsigned int port ) ; #line 32 extern unsigned int insb(unsigned int , void *addr , unsigned long count ) ; #line 35 "/usr/local/ddv/models/con2/include/asm/uaccess.h" extern int access_ok(int type , void const *addr , unsigned long size ) ; #line 51 unsigned long copy_to_user(void *to , void const *from , unsigned long n ) ; #line 53 unsigned long copy_from_user(void *to , void *from , unsigned long n ) ; #line 18 "/usr/local/ddv/models/con2/include/linux/delay.h" extern void msleep(unsigned int msecs ) ; #line 4 "/usr/local/ddv/models/con2/include/linux/elevator.h" extern struct request *elv_next_request(struct request_queue *q ) ; #line 211 "/usr/local/ddv/models/con2/include/linux/blkdev.h" extern void blkdev_dequeue_request(struct request *req ) ; #line 214 extern int end_that_request_first(struct request * , int , int ) ; #line 218 extern void end_that_request_last(struct request * , int ) ; #line 190 "cdu31a.c" static struct __anonstruct_cdu31a_addresses_16 cdu31a_addresses[1] = { {(unsigned short)0, (short)0}}; #line 198 static int handle_sony_cd_attention(void) ; #line 199 static int read_subcode(void) ; #line 200 static void sony_get_toc(void) ; #line 201 static int scd_spinup(void) ; #line 203 static int scd_open(struct cdrom_device_info *cdi , int purpose ) ; #line 204 static void do_sony_cd_cmd(unsigned char cmd , unsigned char *params , unsigned int num_params , unsigned char *result_buffer , unsigned int *result_size ) ; #line 209 static void size_to_buf(unsigned int size , unsigned char *buf ) ; #line 212 "cdu31a.c" static unsigned int sony_next_block ; #line 213 "cdu31a.c" static unsigned int sony_blocks_left = 0U; #line 219 "cdu31a.c" static unsigned int cdu31a_port = 0U; #line 226 "cdu31a.c" static unsigned short volatile sony_cd_cmd_reg ; #line 227 "cdu31a.c" static unsigned short volatile sony_cd_param_reg ; #line 228 "cdu31a.c" static unsigned short volatile sony_cd_write_reg ; #line 229 "cdu31a.c" static unsigned short volatile sony_cd_control_reg ; #line 230 "cdu31a.c" static unsigned short volatile sony_cd_status_reg ; #line 231 "cdu31a.c" static unsigned short volatile sony_cd_result_reg ; #line 232 "cdu31a.c" static unsigned short volatile sony_cd_read_reg ; #line 233 "cdu31a.c" static unsigned short volatile sony_cd_fifost_reg ; #line 235 "cdu31a.c" static struct request_queue *cdu31a_queue ; #line 236 "cdu31a.c" static spinlock_t cdu31a_lock = {1, 0}; #line 238 "cdu31a.c" static int sony_spun_up = 0; #line 240 "cdu31a.c" static int sony_speed = 0; #line 242 "cdu31a.c" static int sony_xa_mode = 0; #line 245 "cdu31a.c" static int sony_raw_data_mode = 1; #line 248 "cdu31a.c" static unsigned int sony_usage = 0U; #line 251 "cdu31a.c" static int sony_pas_init = 0; #line 254 "cdu31a.c" static struct s_sony_session_toc single_toc ; #line 258 "cdu31a.c" static struct s_all_sessions_toc sony_toc ; #line 261 "cdu31a.c" static int sony_toc_read = 0; #line 264 "cdu31a.c" static struct s_sony_subcode last_sony_subcode ; #line 267 "cdu31a.c" static struct semaphore sony_sem = {1, 0}; #line 269 "cdu31a.c" static int is_double_speed = 0; #line 271 "cdu31a.c" static int is_auto_eject = 1; #line 277 "cdu31a.c" static int volatile sony_audio_status = (int volatile )21; #line 286 "cdu31a.c" static unsigned char volatile cur_pos_msf[3] = { (unsigned char volatile )0, (unsigned char volatile )0, (unsigned char volatile )0}; #line 287 "cdu31a.c" static unsigned char volatile final_pos_msf[3] = { (unsigned char volatile )0, (unsigned char volatile )0, (unsigned char volatile )0}; #line 290 "cdu31a.c" static int cdu31a_irq = 0; #line 295 "cdu31a.c" static wait_queue_head_t cdu31a_irq_wait = {0, 0, 1}; #line 296 "cdu31a.c" static int irq_flag = 0; #line 298 "cdu31a.c" static int curr_control_reg = 0; #line 303 "cdu31a.c" static char disk_changed ; #line 306 "cdu31a.c" static char audio_buffer[2352] ; #line 311 "cdu31a.c" static struct timer_list cdu31a_abort_timer ; #line 316 "cdu31a.c" static int abort_read_started = 0; #line 322 "cdu31a.c" static int scd_media_changed(struct cdrom_device_info *cdi , int disc_nr ) { int retval ; { #line 326 retval = (int )disk_changed; #line 327 disk_changed = (char)0; #line 329 return (retval); } } #line 336 "cdu31a.c" static int scd_drive_status(struct cdrom_device_info *cdi , int slot_nr ) { int tmp ; int tmp___0 ; int tmp___1 ; { #line 338 if ((int )(4294967295U >> 1) != slot_nr) { #line 340 return (-22); } #line 341 if (sony_spun_up) { #line 342 return (4); } #line 343 tmp = down_interruptible(& sony_sem); #line 343 if (tmp) { #line 344 return (-512); } #line 345 tmp___0 = scd_spinup(); #line 345 if (tmp___0 == 0) { #line 346 sony_spun_up = 1; } #line 347 up(& sony_sem); #line 348 if (sony_spun_up) { #line 348 tmp___1 = 4; } else { #line 348 tmp___1 = 3; } #line 348 return (tmp___1); } } #line 351 "cdu31a.c" __inline static void enable_interrupts(void) { { #line 353 curr_control_reg |= 56; #line 356 outb((unsigned char )curr_control_reg, (unsigned int )sony_cd_control_reg); #line 357 return; } } #line 359 "cdu31a.c" __inline static void disable_interrupts(void) { { #line 361 curr_control_reg &= -57; #line 364 outb((unsigned char )curr_control_reg, (unsigned int )sony_cd_control_reg); #line 365 return; } } #line 371 "cdu31a.c" __inline static void sony_sleep(void) { wait_queue_t w ; int first ; struct task_struct *tmp ; int tmp___0 ; { #line 373 if (cdu31a_irq <= 0) { #line 374 yield(); } else { #line 377 first = 1; #line 379 while (1) { #line 380 prepare_to_wait(& cdu31a_irq_wait, & w, 1); #line 382 if (first) { #line 383 enable_interrupts(); #line 384 first = 0; } #line 387 if (irq_flag != 0) { #line 388 break; } #line 389 tmp = get_current(); #line 389 tmp___0 = signal_pending(tmp); #line 389 if (tmp___0) { #line 393 disable_interrupts(); } else { #line 390 schedule(); #line 391 continue; } #line 394 break; } #line 396 finish_wait(& cdu31a_irq_wait, & w); #line 397 irq_flag = 0; } #line 399 return; } } #line 406 "cdu31a.c" __inline static int is_attention(void) { unsigned char tmp ; { #line 408 tmp = inb((unsigned int )sony_cd_status_reg); #line 408 return (((int )tmp & 1) != 0); } } #line 411 "cdu31a.c" __inline static int is_busy(void) { unsigned char tmp ; { #line 413 tmp = inb((unsigned int )sony_cd_status_reg); #line 413 return (((int )tmp & 128) != 0); } } #line 416 "cdu31a.c" __inline static int is_data_ready(void) { unsigned char tmp ; { #line 418 tmp = inb((unsigned int )sony_cd_status_reg); #line 418 return (((int )tmp & 4) != 0); } } #line 421 "cdu31a.c" __inline static int is_data_requested(void) { unsigned char tmp ; { #line 423 tmp = inb((unsigned int )sony_cd_status_reg); #line 423 return (((int )tmp & 64) != 0); } } #line 426 "cdu31a.c" __inline static int is_result_ready(void) { unsigned char tmp ; { #line 428 tmp = inb((unsigned int )sony_cd_status_reg); #line 428 return (((int )tmp & 2) != 0); } } #line 431 "cdu31a.c" __inline static int is_param_write_rdy(void) { unsigned char tmp ; { #line 433 tmp = inb((unsigned int )sony_cd_fifost_reg); #line 433 return (((int )tmp & 1) != 0); } } #line 436 "cdu31a.c" __inline static int is_result_reg_not_empty(void) { unsigned char tmp ; { #line 438 tmp = inb((unsigned int )sony_cd_fifost_reg); #line 438 return (((int )tmp & 4) != 0); } } #line 441 "cdu31a.c" __inline static void reset_drive(void) { { #line 443 curr_control_reg = 0; #line 444 sony_toc_read = 0; #line 445 outb((unsigned char)128, (unsigned int )sony_cd_control_reg); #line 446 return; } } #line 452 "cdu31a.c" static int scd_reset(struct cdrom_device_info *cdi ) { unsigned long retry_count ; int tmp ; int tmp___0 ; { #line 456 tmp = down_interruptible(& sony_sem); #line 456 if (tmp) { #line 457 return (-512); } #line 458 reset_drive(); #line 460 retry_count = jiffies + 100UL; #line 461 while (1) { #line 461 if ((long )jiffies - (long )retry_count < 0L) { #line 461 tmp___0 = is_attention(); #line 461 if (tmp___0) { #line 461 break; } } else { #line 461 break; } #line 462 sony_sleep(); } #line 465 up(& sony_sem); #line 466 return (0); } } #line 469 "cdu31a.c" __inline static void clear_attention(void) { { #line 471 outb((unsigned char )(curr_control_reg | 1), (unsigned int )sony_cd_control_reg); #line 472 return; } } #line 474 "cdu31a.c" __inline static void clear_result_ready(void) { { #line 476 outb((unsigned char )(curr_control_reg | 2), (unsigned int )sony_cd_control_reg); #line 477 return; } } #line 479 "cdu31a.c" __inline static void clear_data_ready(void) { { #line 481 outb((unsigned char )(curr_control_reg | 4), (unsigned int )sony_cd_control_reg); #line 483 return; } } #line 485 "cdu31a.c" __inline static void clear_param_reg(void) { { #line 487 outb((unsigned char )(curr_control_reg | 64), (unsigned int )sony_cd_control_reg); #line 488 return; } } #line 490 "cdu31a.c" __inline static unsigned char read_status_register(void) { unsigned char tmp ; { #line 492 tmp = inb((unsigned int )sony_cd_status_reg); #line 492 return (tmp); } } #line 495 "cdu31a.c" __inline static unsigned char read_result_register(void) { unsigned char tmp ; { #line 497 tmp = inb((unsigned int )sony_cd_result_reg); #line 497 return (tmp); } } #line 500 "cdu31a.c" __inline static unsigned char read_data_register(void) { unsigned char tmp ; { #line 502 tmp = inb((unsigned int )sony_cd_read_reg); #line 502 return (tmp); } } #line 505 "cdu31a.c" __inline static void write_param(unsigned char param ) { { #line 507 outb(param, (unsigned int )sony_cd_param_reg); #line 508 return; } } #line 510 "cdu31a.c" __inline static void write_cmd(unsigned char cmd ) { { #line 512 outb((unsigned char )(curr_control_reg | 16), (unsigned int )sony_cd_control_reg); #line 514 outb(cmd, (unsigned int )sony_cd_cmd_reg); #line 515 return; } } #line 517 "cdu31a.c" static irqreturn_t cdu31a_interrupt(int irq , void *dev_id , struct pt_regs *regs ) { unsigned char val ; int tmp ; int tmp___0 ; int tmp___1 ; int tmp___2 ; { #line 521 if (abort_read_started) { #line 526 while (1) { #line 526 tmp = is_result_reg_not_empty(); #line 526 if (! tmp) { #line 526 break; } #line 527 val = read_result_register(); } #line 529 clear_data_ready(); #line 530 clear_result_ready(); #line 533 while (1) { #line 533 tmp___0 = is_data_requested(); #line 533 if (! tmp___0) { #line 533 break; } #line 534 val = read_data_register(); } #line 536 abort_read_started = 0; #line 539 tmp___1 = waitqueue_active(& cdu31a_irq_wait); #line 539 if (tmp___1) { #line 540 disable_interrupts(); #line 541 irq_flag = 1; #line 542 wake_up_interruptible(& cdu31a_irq_wait); } } else { #line 544 tmp___2 = waitqueue_active(& cdu31a_irq_wait); #line 544 if (tmp___2) { #line 545 disable_interrupts(); #line 546 irq_flag = 1; #line 547 wake_up_interruptible(& cdu31a_irq_wait); } else { #line 549 disable_interrupts(); #line 550 printk("<5>CDU31A: Got an interrupt but nothing was waiting\n"); } } #line 553 return (1); } } #line 561 "cdu31a.c" static unsigned char errbuf[80] ; #line 559 "cdu31a.c" static unsigned char *translate_error(unsigned char err_code ) { { #line 563 switch ((int )err_code) { case 16: #line 564 return ((unsigned char *)"illegal command "); case 17: #line 565 return ((unsigned char *)"illegal parameter "); case 32: #line 567 return ((unsigned char *)"not loaded "); case 33: #line 568 return ((unsigned char *)"no disc "); case 34: #line 569 return ((unsigned char *)"not spinning "); case 35: #line 570 return ((unsigned char *)"spinning "); case 37: #line 571 return ((unsigned char *)"spindle servo "); case 38: #line 572 return ((unsigned char *)"focus servo "); case 41: #line 573 return ((unsigned char *)"eject mechanism "); case 42: #line 574 return ((unsigned char *)"audio playing "); case 44: #line 575 return ((unsigned char *)"emergency eject "); case 48: #line 577 return ((unsigned char *)"focus "); case 49: #line 578 return ((unsigned char *)"frame sync "); case 50: #line 579 return ((unsigned char *)"subcode address "); case 51: #line 580 return ((unsigned char *)"block sync "); case 52: #line 581 return ((unsigned char *)"header address "); case 64: #line 583 return ((unsigned char *)"illegal track read "); case 65: #line 584 return ((unsigned char *)"mode 0 read "); case 66: #line 585 return ((unsigned char *)"illegal mode read "); case 67: #line 586 return ((unsigned char *)"illegal block size read "); case 68: #line 587 return ((unsigned char *)"mode read "); case 69: #line 588 return ((unsigned char *)"form read "); case 70: #line 589 return ((unsigned char *)"leadout read "); case 71: #line 590 return ((unsigned char *)"buffer overrun "); case 83: #line 592 return ((unsigned char *)"unrecoverable CIRC "); case 87: #line 593 return ((unsigned char *)"unrecoverable LECC "); case 96: #line 595 return ((unsigned char *)"no TOC "); case 97: #line 596 return ((unsigned char *)"invalid subcode data "); case 99: #line 597 return ((unsigned char *)"focus on TOC read "); case 100: #line 598 return ((unsigned char *)"frame sync on TOC read "); case 101: #line 599 return ((unsigned char *)"TOC data "); case 112: #line 601 return ((unsigned char *)"hardware failure "); case 145: #line 602 return ((unsigned char *)"leadin "); case 146: #line 603 return ((unsigned char *)"leadout "); case 147: #line 604 return ((unsigned char *)"data track "); } #line 606 sprintf((char *)(errbuf), "unknown 0x%02x ", (int )err_code); #line 607 return (errbuf); } } #line 614 "cdu31a.c" static void set_drive_params(int want_doublespeed ) { unsigned char res_reg[12] ; unsigned int res_size ; unsigned char params[3] ; { #line 621 params[0] = (unsigned char)6; #line 622 params[1] = (unsigned char)0; #line 623 do_sony_cd_cmd((unsigned char)16, params, 2U, res_reg, & res_size); #line 625 if (res_size < 2U) { #line 626 printk("<5>CDU31A: Unable to set spin-down time: 0x%2.2x\n", (int )res_reg[1]); } else #line 625 if (((int )res_reg[0] & 240) == 32) { #line 626 printk("<5>CDU31A: Unable to set spin-down time: 0x%2.2x\n", (int )res_reg[1]); } #line 630 params[0] = (unsigned char)5; #line 631 params[1] = (unsigned char)1; #line 633 if (is_auto_eject) { #line 634 params[1] = (unsigned char )((int )params[1] | 2); } #line 636 if (is_double_speed) { #line 636 if (want_doublespeed) { #line 637 params[1] = (unsigned char )((int )params[1] | 4); } } #line 640 do_sony_cd_cmd((unsigned char)16, params, 2U, res_reg, & res_size); #line 642 if (res_size < 2U) { #line 643 printk("<5>CDU31A: Unable to set mechanical parameters: 0x%2.2x\n", (int )res_reg[1]); } else #line 642 if (((int )res_reg[0] & 240) == 32) { #line 643 printk("<5>CDU31A: Unable to set mechanical parameters: 0x%2.2x\n", (int )res_reg[1]); } #line 646 return; } } #line 652 "cdu31a.c" static int scd_select_speed(struct cdrom_device_info *cdi , int speed ) { int tmp ; { #line 654 if (speed == 0) { #line 655 sony_speed = 1; } else { #line 657 sony_speed = speed - 1; } #line 659 tmp = down_interruptible(& sony_sem); #line 659 if (tmp) { #line 660 return (-512); } #line 661 set_drive_params(sony_speed); #line 662 up(& sony_sem); #line 663 return (0); } } #line 670 "cdu31a.c" static int scd_lock_door(struct cdrom_device_info *cdi , int lock ) { int tmp ; { #line 672 if (lock == 0) { #line 673 is_auto_eject = 1; } else { #line 675 is_auto_eject = 0; } #line 677 tmp = down_interruptible(& sony_sem); #line 677 if (tmp) { #line 678 return (-512); } #line 679 set_drive_params(sony_speed); #line 680 up(& sony_sem); #line 681 return (0); } } #line 687 "cdu31a.c" static void restart_on_error(void) { unsigned char res_reg[12] ; unsigned int res_size ; unsigned long retry_count ; int tmp ; { #line 694 printk("<5>CDU31A: Resetting drive on error\n"); #line 695 reset_drive(); #line 696 retry_count = jiffies + 100UL; #line 697 while (1) { #line 697 if ((long )jiffies - (long )retry_count < 0L) { #line 697 tmp = is_attention(); #line 697 if (tmp) { #line 697 break; } } else { #line 697 break; } #line 698 sony_sleep(); } #line 700 set_drive_params(sony_speed); #line 701 do_sony_cd_cmd((unsigned char)81, (unsigned char *)((void *)0), 0U, res_reg, & res_size); #line 702 if (res_size < 2U) { #line 703 printk("<5>CDU31A: Unable to spin up drive: 0x%2.2x\n", (int )res_reg[1]); } else #line 702 if (((int )res_reg[0] & 240) == 32) { #line 703 printk("<5>CDU31A: Unable to spin up drive: 0x%2.2x\n", (int )res_reg[1]); } #line 707 msleep(2000U); #line 709 sony_get_toc(); #line 710 return; } } #line 716 "cdu31a.c" static int write_params(unsigned char *params , int num_params ) { unsigned int retry_count ; int tmp ; int tmp___0 ; { #line 721 retry_count = 20000U; #line 722 while (1) { #line 722 if (retry_count > 0U) { #line 722 tmp = is_param_write_rdy(); #line 722 if (tmp) { #line 722 break; } } else { #line 722 break; } #line 723 retry_count --; } #line 725 tmp___0 = is_param_write_rdy(); #line 725 if (! tmp___0) { #line 726 return (-5); } #line 729 while (num_params > 0) { #line 730 write_param(*params); #line 731 params ++; #line 732 num_params --; } #line 735 return (0); } } #line 745 "cdu31a.c" static void get_result(unsigned char *result_buffer , unsigned int *result_size ) { unsigned char a ; unsigned char b ; int i ; unsigned long retry_count ; int tmp ; int tmp___0 ; int tmp___1 ; int tmp___2 ; int tmp___3 ; int tmp___4 ; int tmp___5 ; int tmp___6 ; int tmp___7 ; int tmp___8 ; { #line 753 while (1) { #line 753 tmp = handle_sony_cd_attention(); #line 753 if (! tmp) { #line 753 break; } } #line 755 retry_count = jiffies + 1000UL; #line 756 while (1) { #line 756 if ((long )jiffies - (long )retry_count < 0L) { #line 756 tmp___1 = is_busy(); #line 756 if (! tmp___1) { #line 756 tmp___2 = is_result_ready(); #line 756 if (tmp___2) { #line 756 break; } } } else { #line 756 break; } #line 758 sony_sleep(); #line 760 while (1) { #line 760 tmp___0 = handle_sony_cd_attention(); #line 760 if (! tmp___0) { #line 760 break; } } } #line 762 tmp___3 = is_busy(); #line 762 if (tmp___3) { #line 762 goto _L; } else { #line 762 tmp___4 = is_result_ready(); #line 762 if (! tmp___4) { _L: /* CIL Label */ #line 763 while (1) { #line 763 break; } #line 764 *(result_buffer + 0) = (unsigned char)32; #line 765 *(result_buffer + 1) = (unsigned char)1; #line 766 *result_size = 2U; #line 767 return; } } #line 774 clear_result_ready(); #line 775 a = read_result_register(); #line 776 *result_buffer = a; #line 777 result_buffer ++; #line 780 if (((int )a & 240) == 80) { #line 781 *result_size = 1U; #line 782 return; } #line 785 b = read_result_register(); #line 786 *result_buffer = b; #line 787 result_buffer ++; #line 788 *result_size = 2U; #line 798 if (((int )a & 240) != 32) { #line 799 if ((int )b > 8) { #line 800 i = 0; #line 800 while (i < 8) { #line 801 *result_buffer = read_result_register(); #line 802 result_buffer ++; #line 803 (*result_size) ++; #line 800 i ++; } #line 805 b = (unsigned char )((int )b - 8); #line 807 while ((int )b > 10) { #line 808 retry_count = 20000UL; #line 809 while (1) { #line 809 if (retry_count > 0UL) { #line 809 tmp___5 = is_result_ready(); #line 809 if (tmp___5) { #line 809 break; } } else { #line 809 break; } #line 811 retry_count --; } #line 813 tmp___6 = is_result_ready(); #line 813 if (! tmp___6) { #line 814 while (1) { #line 814 break; } #line 816 *(result_buffer + 0) = (unsigned char)32; #line 817 *(result_buffer + 1) = (unsigned char)1; #line 819 *result_size = 2U; #line 820 return; } #line 823 clear_result_ready(); #line 825 i = 0; #line 825 while (i < 10) { #line 826 *result_buffer = read_result_register(); #line 828 result_buffer ++; #line 829 (*result_size) ++; #line 825 i ++; } #line 831 b = (unsigned char )((int )b - 10); } #line 834 if ((int )b > 0) { #line 835 retry_count = 20000UL; #line 836 while (1) { #line 836 if (retry_count > 0UL) { #line 836 tmp___7 = is_result_ready(); #line 836 if (tmp___7) { #line 836 break; } } else { #line 836 break; } #line 838 retry_count --; } #line 840 tmp___8 = is_result_ready(); #line 840 if (! tmp___8) { #line 841 while (1) { #line 841 break; } #line 843 *(result_buffer + 0) = (unsigned char)32; #line 844 *(result_buffer + 1) = (unsigned char)1; #line 846 *result_size = 2U; #line 847 return; } } } #line 852 while ((int )b > 0) { #line 853 *result_buffer = read_result_register(); #line 854 result_buffer ++; #line 855 (*result_size) ++; #line 856 b = (unsigned char )((int )b - 1); } } #line 859 return; } } #line 866 "cdu31a.c" static void do_sony_cd_cmd(unsigned char cmd , unsigned char *params , unsigned int num_params , unsigned char *result_buffer , unsigned int *result_size ) { unsigned long retry_count ; int num_retries ; int tmp ; int tmp___0 ; int tmp___1 ; int tmp___2 ; { #line 873 num_retries = 0; retry_cd_operation: #line 877 while (1) { #line 877 tmp = handle_sony_cd_attention(); #line 877 if (! tmp) { #line 877 break; } } #line 879 retry_count = jiffies + 1000UL; #line 880 while (1) { #line 880 if ((long )jiffies - (long )retry_count < 0L) { #line 880 tmp___1 = is_busy(); #line 880 if (! tmp___1) { #line 880 break; } } else { #line 880 break; } #line 881 sony_sleep(); #line 883 while (1) { #line 883 tmp___0 = handle_sony_cd_attention(); #line 883 if (! tmp___0) { #line 883 break; } } } #line 885 tmp___2 = is_busy(); #line 885 if (tmp___2) { #line 886 while (1) { #line 886 break; } #line 887 *(result_buffer + 0) = (unsigned char)32; #line 888 *(result_buffer + 1) = (unsigned char)1; #line 889 *result_size = 2U; } else { #line 891 clear_result_ready(); #line 892 clear_param_reg(); #line 894 write_params(params, (int )num_params); #line 895 write_cmd(cmd); #line 897 get_result(result_buffer, result_size); } #line 900 if (((int )*(result_buffer + 0) & 240) == 32) { #line 900 if (num_retries < 3) { #line 902 num_retries ++; #line 903 msleep(100U); #line 904 goto retry_cd_operation; } } #line 906 return; } } #line 921 "cdu31a.c" static int num_consecutive_attentions = 0; #line 918 "cdu31a.c" static int handle_sony_cd_attention(void) { unsigned char atten_code ; int volatile val ; unsigned char tmp ; int tmp___0 ; unsigned char tmp___1 ; int tmp___2 ; int tmp___3 ; { #line 928 tmp___3 = is_attention(); #line 928 if (tmp___3) { #line 929 if (num_consecutive_attentions > 10) { #line 931 printk("<5>CDU31A: Too many consecutive attentions: %d\n", num_consecutive_attentions); #line 933 num_consecutive_attentions = 0; #line 934 while (1) { #line 934 break; } #line 936 return (0); } #line 939 clear_attention(); #line 940 atten_code = read_result_register(); #line 942 switch ((int )atten_code) { case 128: #line 945 disk_changed = (char)1; #line 946 sony_toc_read = 0; #line 947 sony_audio_status = (int volatile )21; #line 948 sony_blocks_left = 0U; #line 949 break; case 39: #line 953 sony_spun_up = 0; #line 954 break; case 144: #line 957 sony_audio_status = (int volatile )19; #line 958 read_subcode(); #line 959 break; case 129: #line 962 if (is_auto_eject) { #line 963 sony_audio_status = (int volatile )0; } #line 965 break; case 148: case 147: case 146: case 145: #line 971 sony_audio_status = (int volatile )20; #line 972 break; } #line 975 num_consecutive_attentions ++; #line 976 while (1) { #line 976 break; } #line 977 return (1); } else #line 978 if (abort_read_started) { #line 979 while (1) { #line 979 tmp___0 = is_result_reg_not_empty(); #line 979 if (! tmp___0) { #line 979 break; } #line 980 tmp = read_result_register(); #line 980 val = (int volatile )tmp; } #line 982 clear_data_ready(); #line 983 clear_result_ready(); #line 985 while (1) { #line 985 tmp___2 = is_data_requested(); #line 985 if (! tmp___2) { #line 985 break; } #line 986 tmp___1 = read_data_register(); #line 986 val = (int volatile )tmp___1; } #line 988 abort_read_started = 0; #line 989 while (1) { #line 989 break; } #line 990 return (1); } #line 993 num_consecutive_attentions = 0; #line 997 return (0); } } #line 1002 "cdu31a.c" __inline static unsigned int int_to_bcd(unsigned int val ) { int retval ; { #line 1007 retval = (int )(val / 10U << 4); #line 1008 retval = (int )((unsigned int )retval | val % 10U); #line 1009 return ((unsigned int )retval); } } #line 1014 "cdu31a.c" static unsigned int bcd_to_int(unsigned int bcd ) { { #line 1016 return (((bcd >> 4) & 15U) * 10U + (bcd & 15U)); } } #line 1024 "cdu31a.c" static void log_to_msf(unsigned int log , unsigned char *msf ) { unsigned int tmp ; unsigned int tmp___0 ; unsigned int tmp___1 ; { #line 1026 log += 150U; #line 1027 tmp = int_to_bcd(log / 4500U); #line 1027 *(msf + 0) = (unsigned char )tmp; #line 1028 log %= 4500U; #line 1029 tmp___0 = int_to_bcd(log / 75U); #line 1029 *(msf + 1) = (unsigned char )tmp___0; #line 1030 tmp___1 = int_to_bcd(log % 75U); #line 1030 *(msf + 2) = (unsigned char )tmp___1; #line 1031 return; } } #line 1037 "cdu31a.c" static unsigned int msf_to_log(unsigned char *msf ) { unsigned int log ; { #line 1042 log = (unsigned int )*(msf + 2); #line 1043 log += (unsigned int )((int )*(msf + 1) * 75); #line 1044 log += (unsigned int )((int )*(msf + 0) * 4500); #line 1045 log -= 150U; #line 1047 return (log); } } #line 1055 "cdu31a.c" static void size_to_buf(unsigned int size , unsigned char *buf ) { { #line 1057 *(buf + 0) = (unsigned char )(size / 65536U); #line 1058 size %= 65536U; #line 1059 *(buf + 1) = (unsigned char )(size / 256U); #line 1060 *(buf + 2) = (unsigned char )(size % 256U); #line 1061 return; } } #line 1069 "cdu31a.c" static int start_request(unsigned int sector , unsigned int nsect ) { unsigned char params[6] ; unsigned long retry_count ; int tmp ; int tmp___0 ; int tmp___1 ; int tmp___2 ; { #line 1076 while (1) { #line 1076 break; } #line 1077 log_to_msf(sector, params); #line 1078 size_to_buf(nsect, & params[3]); #line 1084 while (1) { #line 1084 tmp = handle_sony_cd_attention(); #line 1084 if (! tmp) { #line 1084 break; } } #line 1086 retry_count = jiffies + 1000UL; #line 1087 while (1) { #line 1087 if ((long )jiffies - (long )retry_count < 0L) { #line 1087 tmp___1 = is_busy(); #line 1087 if (! tmp___1) { #line 1087 break; } } else { #line 1087 break; } #line 1088 sony_sleep(); #line 1090 while (1) { #line 1090 tmp___0 = handle_sony_cd_attention(); #line 1090 if (! tmp___0) { #line 1090 break; } } } #line 1093 tmp___2 = is_busy(); #line 1093 if (tmp___2) { #line 1094 printk("<5>CDU31A: Timeout while waiting to issue command\n"); #line 1096 while (1) { #line 1096 break; } #line 1097 return (1); } else { #line 1100 clear_result_ready(); #line 1101 clear_param_reg(); #line 1103 write_params(params, 6); #line 1104 write_cmd((unsigned char)52); #line 1106 sony_blocks_left = nsect * 4U; #line 1107 sony_next_block = sector * 4U; #line 1108 while (1) { #line 1108 break; } #line 1109 return (0); } #line 1111 while (1) { #line 1111 break; } } } #line 1115 "cdu31a.c" static void abort_read(void) { unsigned char result_reg[2] ; int result_size ; int volatile val ; unsigned char *tmp ; unsigned char tmp___0 ; int tmp___1 ; unsigned char tmp___2 ; int tmp___3 ; { #line 1122 do_sony_cd_cmd((unsigned char)53, (unsigned char *)((void *)0), 0U, result_reg, (unsigned int *)(& result_size)); #line 1123 if (((int )result_reg[0] & 240) == 32) { #line 1124 tmp = translate_error(result_reg[1]); #line 1124 printk("<3>CDU31A: Aborting read, %s error\n", tmp); } #line 1128 while (1) { #line 1128 tmp___1 = is_result_reg_not_empty(); #line 1128 if (! tmp___1) { #line 1128 break; } #line 1129 tmp___0 = read_result_register(); #line 1129 val = (int volatile )tmp___0; } #line 1131 clear_data_ready(); #line 1132 clear_result_ready(); #line 1134 while (1) { #line 1134 tmp___3 = is_data_requested(); #line 1134 if (! tmp___3) { #line 1134 break; } #line 1135 tmp___2 = read_data_register(); #line 1135 val = (int volatile )tmp___2; } #line 1138 sony_blocks_left = 0U; #line 1139 return; } } #line 1143 "cdu31a.c" static void handle_abort_timeout(unsigned long data ) { int tmp ; { #line 1145 while (1) { #line 1145 break; } #line 1147 tmp = down_trylock(& sony_sem); #line 1147 if (tmp == 0) { #line 1152 clear_result_ready(); #line 1153 clear_param_reg(); #line 1154 write_cmd((unsigned char)53); #line 1156 sony_blocks_left = 0U; #line 1157 abort_read_started = 1; #line 1158 up(& sony_sem); } #line 1160 while (1) { #line 1160 break; } #line 1161 return; } } #line 1164 "cdu31a.c" static void input_data_sector(char *buffer ) { { #line 1167 while (1) { #line 1167 break; } #line 1171 if (sony_xa_mode) { #line 1172 insb((unsigned int )sony_cd_read_reg, (void *)(audio_buffer), 12UL); } #line 1174 clear_data_ready(); #line 1176 insb((unsigned int )sony_cd_read_reg, (void *)buffer, 2048UL); #line 1180 if (sony_xa_mode) { #line 1181 insb((unsigned int )sony_cd_read_reg, (void *)(audio_buffer), 280UL); } #line 1183 while (1) { #line 1183 break; } #line 1184 return; } } #line 1187 "cdu31a.c" static void read_data_block(char *buffer , unsigned int block , unsigned int nblocks , unsigned char *res_reg , int *res_size ) { unsigned long retry_count ; int tmp ; int tmp___0 ; int tmp___1 ; int tmp___2 ; int tmp___3 ; int tmp___4 ; int tmp___5 ; { #line 1195 while (1) { #line 1195 break; } #line 1197 *(res_reg + 0) = (unsigned char)0; #line 1198 *(res_reg + 1) = (unsigned char)0; #line 1199 *res_size = 0; #line 1202 retry_count = jiffies + 1000UL; #line 1203 while (1) { #line 1203 if ((long )jiffies - (long )retry_count < 0L) { #line 1203 tmp___0 = is_data_ready(); #line 1203 if (tmp___0) { #line 1203 break; } } else { #line 1203 break; } #line 1204 while (1) { #line 1204 tmp = handle_sony_cd_attention(); #line 1204 if (! tmp) { #line 1204 break; } } #line 1206 sony_sleep(); } #line 1208 tmp___5 = is_data_ready(); #line 1208 if (tmp___5) { #line 1227 input_data_sector(buffer); #line 1228 sony_blocks_left -= nblocks; #line 1229 sony_next_block += nblocks; #line 1232 retry_count = jiffies + 1000UL; #line 1233 while (1) { #line 1233 if ((long )jiffies - (long )retry_count < 0L) { #line 1233 tmp___3 = is_result_ready(); #line 1233 if (tmp___3) { #line 1233 break; } } else { #line 1233 break; } #line 1235 while (1) { #line 1235 tmp___2 = handle_sony_cd_attention(); #line 1235 if (! tmp___2) { #line 1235 break; } } #line 1237 sony_sleep(); } #line 1240 tmp___4 = is_result_ready(); #line 1240 if (tmp___4) { #line 1247 get_result(res_reg, (unsigned int *)res_size); #line 1250 if (((int )*(res_reg + 0) & 240) == 80) { #line 1252 if (! ((int )*(res_reg + 0) == 80)) { #line 1252 if (! ((int )*(res_reg + 0) == 84)) { #line 1252 if (! ((int )*(res_reg + 0) == 85)) { #line 1260 printk("<3>CDU31A: Data block error: 0x%x\n", (int )*(res_reg + 0)); #line 1262 *(res_reg + 0) = (unsigned char)32; #line 1263 *(res_reg + 1) = (unsigned char)3; #line 1264 *res_size = 2; } } } #line 1268 if (sony_blocks_left == 0U) { #line 1269 get_result(res_reg, (unsigned int *)res_size); } } else #line 1271 if (((int )*(res_reg + 0) & 240) != 32) { #line 1274 printk("<3>CDU31A: Invalid block status: 0x%x\n", (int )*(res_reg + 0)); #line 1276 restart_on_error(); #line 1277 *(res_reg + 0) = (unsigned char)32; #line 1278 *(res_reg + 1) = (unsigned char)3; #line 1279 *res_size = 2; } } else { #line 1241 while (1) { #line 1241 break; } #line 1242 *(res_reg + 0) = (unsigned char)32; #line 1243 *(res_reg + 1) = (unsigned char)1; #line 1244 *res_size = 2; #line 1245 abort_read(); } } else { #line 1209 tmp___1 = is_result_ready(); #line 1209 if (tmp___1) { #line 1210 get_result(res_reg, (unsigned int *)res_size); #line 1211 if (((int )*(res_reg + 0) & 240) != 32) { #line 1212 printk("<5>CDU31A: Got result that should have been error: %d\n", (int )*(res_reg + 0)); #line 1214 *(res_reg + 0) = (unsigned char)32; #line 1215 *(res_reg + 1) = (unsigned char)3; #line 1216 *res_size = 2; } #line 1218 abort_read(); } else { #line 1220 while (1) { #line 1220 break; } #line 1221 *(res_reg + 0) = (unsigned char)32; #line 1222 *(res_reg + 1) = (unsigned char)1; #line 1223 *res_size = 2; #line 1224 abort_read(); } } #line 1283 while (1) { #line 1283 break; } #line 1284 return; } } #line 1294 "cdu31a.c" static void do_cdu31a_request(request_queue_t *q ) { struct request *req ; int block ; int nblock ; int num_retries ; unsigned char res_reg[12] ; unsigned int res_size ; int tmp ; int tmp___0 ; int tmp___1 ; int tmp___2 ; int tmp___3 ; int tmp___4 ; unsigned char *tmp___5 ; { #line 1301 while (1) { #line 1301 break; } #line 1303 spin_unlock_irq(q->queue_lock); #line 1304 tmp = down_interruptible(& sony_sem); #line 1304 if (tmp) { #line 1305 spin_lock_irq(q->queue_lock); #line 1306 return; } #line 1310 while (1) { #line 1310 tmp___0 = handle_sony_cd_attention(); #line 1310 if (! tmp___0) { #line 1310 break; } } #line 1313 sony_get_toc(); #line 1317 del_timer(& cdu31a_abort_timer); #line 1319 while (1) { #line 1324 req = elv_next_request(q); #line 1325 if (! req) { #line 1326 goto end_do_cdu31a_request; } #line 1328 if (! sony_spun_up) { #line 1329 scd_spinup(); } #line 1331 block = (int )req->sector; #line 1332 nblock = (int )req->nr_sectors; #line 1333 while (1) { #line 1333 break; } #line 1335 if (! sony_toc_read) { #line 1336 printk("<5>CDU31A: TOC not read\n"); #line 1337 end_request(req, 0); #line 1338 continue; } #line 1344 if ((req->cmd_flags & 1U) == 1U) { #line 1345 end_request(req, 0); #line 1346 continue; } #line 1353 if ((unsigned int )((block + nblock) / 4) >= sony_toc.lead_out_start_lba) { #line 1354 printk("<5>CDU31A: Request past end of media\n"); #line 1355 end_request(req, 0); #line 1356 continue; } #line 1359 if (nblock > 4) { #line 1360 nblock = 4; } #line 1361 num_retries = 0; try_read_again: #line 1364 while (1) { #line 1364 tmp___1 = handle_sony_cd_attention(); #line 1364 if (! tmp___1) { #line 1364 break; } } #line 1366 if (! sony_toc_read) { #line 1367 printk("<5>CDU31A: TOC not read\n"); #line 1368 end_request(req, 0); #line 1369 continue; } #line 1374 if (sony_blocks_left == 0U) { #line 1375 tmp___2 = start_request((unsigned int )(block / 4), (unsigned int )(nblock / 4)); #line 1375 if (tmp___2) { #line 1376 end_request(req, 0); #line 1377 continue; } } else #line 1383 if ((unsigned int )block != sony_next_block) { #line 1384 while (1) { #line 1384 break; } #line 1386 abort_read(); #line 1387 if (! sony_toc_read) { #line 1388 printk("<5>CDU31A: TOC not read\n"); #line 1389 end_request(req, 0); #line 1390 continue; } #line 1392 tmp___3 = start_request((unsigned int )(block / 4), (unsigned int )(nblock / 4)); #line 1392 if (tmp___3) { #line 1393 printk("<5>CDU31A: start request failed\n"); #line 1394 end_request(req, 0); #line 1395 continue; } } #line 1399 read_data_block(req->buffer, (unsigned int )block, (unsigned int )nblock, res_reg, (int *)(& res_size)); #line 1401 if ((int )res_reg[0] != 32) { #line 1402 tmp___4 = end_that_request_first(req, 1, nblock); #line 1402 if (! tmp___4) { #line 1403 spin_lock_irq(q->queue_lock); #line 1404 blkdev_dequeue_request(req); #line 1405 end_that_request_last(req, 1); #line 1406 spin_unlock_irq(q->queue_lock); } #line 1408 continue; } #line 1411 if (num_retries > 3) { #line 1412 end_request(req, 0); #line 1413 continue; } #line 1416 num_retries ++; #line 1417 if ((int )res_reg[1] == 34) { #line 1418 do_sony_cd_cmd((unsigned char)81, (unsigned char *)((void *)0), 0U, res_reg, & res_size); } else { #line 1421 tmp___5 = translate_error(res_reg[1]); #line 1421 printk("<5>CDU31A: %s error for block %d, nblock %d\n", tmp___5, block, nblock); } #line 1424 goto try_read_again; } end_do_cdu31a_request: #line 1433 cdu31a_abort_timer.expires = jiffies + 200UL; #line 1434 add_timer(& cdu31a_abort_timer); #line 1437 up(& sony_sem); #line 1438 spin_lock_irq(q->queue_lock); #line 1439 while (1) { #line 1439 break; } #line 1440 return; } } #line 1447 "cdu31a.c" static void sony_get_toc(void) { unsigned char res_reg[2] ; unsigned int res_size ; unsigned char parms[1] ; int session ; int num_spin_ups ; int totaltracks ; int mint ; int maxt ; unsigned char *tmp ; unsigned char *tmp___0 ; unsigned int tmp___1 ; unsigned int tmp___2 ; unsigned int tmp___3 ; unsigned int tmp___4 ; unsigned int tmp___5 ; unsigned int tmp___6 ; int i ; unsigned int tmp___7 ; unsigned int tmp___8 ; unsigned int tmp___9 ; unsigned int tmp___10 ; unsigned int tmp___11 ; unsigned int tmp___12 ; { #line 1454 totaltracks = 0; #line 1455 mint = 99; #line 1456 maxt = 0; #line 1458 while (1) { #line 1458 break; } #line 1460 num_spin_ups = 0; #line 1461 if (! sony_toc_read) { respinup_on_gettoc: #line 1464 do_sony_cd_cmd((unsigned char)81, (unsigned char *)((void *)0), 0U, res_reg, & res_size); #line 1467 do_sony_cd_cmd((unsigned char)48, (unsigned char *)((void *)0), 0U, res_reg, & res_size); #line 1472 if (res_size < 2U) { #line 1472 goto _L; } else #line 1472 if ((int )res_reg[0] != 0) { #line 1472 if ((int )res_reg[1] != 0) { _L: /* CIL Label */ #line 1475 if ((int )res_reg[1] == 42) { #line 1477 goto gettoc_drive_spinning; } else #line 1475 if ((int )res_reg[1] == 0) { #line 1477 goto gettoc_drive_spinning; } #line 1482 if ((int )res_reg[1] == 34) { #line 1482 if (num_spin_ups < 3) { #line 1484 num_spin_ups ++; #line 1485 goto respinup_on_gettoc; } } #line 1488 tmp = translate_error(res_reg[1]); #line 1488 printk("cdu31a: Error reading TOC: %x %s\n", (int )res_reg[0], tmp); #line 1490 return; } } gettoc_drive_spinning: #line 1501 memset((void *)(& sony_toc), 14, (unsigned int )sizeof(sony_toc)); #line 1502 memset((void *)(& single_toc), 15, (unsigned int )sizeof(single_toc)); #line 1504 session = 1; #line 1505 while (1) { #line 1509 while (1) { #line 1509 break; } #line 1510 parms[0] = (unsigned char )session; #line 1511 do_sony_cd_cmd((unsigned char)54, parms, 1U, res_reg, & res_size); #line 1514 while (1) { #line 1514 break; } #line 1516 if (res_size < 2U) { #line 1516 goto _L___0; } else #line 1516 if (((int )res_reg[0] & 240) == 32) { _L___0: /* CIL Label */ #line 1519 if (session == 1) { #line 1520 printk("Yikes! Couldn\'t read any sessions!"); } #line 1522 break; } #line 1524 while (1) { #line 1524 break; } #line 1526 parms[0] = (unsigned char )session; #line 1527 do_sony_cd_cmd((unsigned char)36, parms, 1U, (unsigned char *)(& single_toc), & res_size); #line 1532 if (res_size < 2U) { #line 1535 tmp___0 = translate_error(single_toc.exec_status[1]); #line 1535 printk("<3>CDU31A: Error reading session %d: %x %s\n", session, (int )single_toc.exec_status[0], tmp___0); #line 1542 return; } else #line 1532 if (((int )single_toc.exec_status[0] & 240) == 32) { #line 1535 tmp___0 = translate_error(single_toc.exec_status[1]); #line 1535 printk("<3>CDU31A: Error reading session %d: %x %s\n", session, (int )single_toc.exec_status[0], tmp___0); #line 1542 return; } #line 1544 while (1) { #line 1544 break; } #line 1550 while (1) { #line 1550 break; } #line 1556 while (1) { #line 1556 break; } #line 1563 if (res_size > 18U) { #line 1563 if ((int )single_toc.pointb0 > 175) { #line 1564 while (1) { #line 1564 break; } } } #line 1588 if (res_size > 27U) { #line 1588 if ((int )single_toc.pointb1 > 175) { #line 1589 while (1) { #line 1589 break; } } } #line 1600 if (res_size > 36U) { #line 1600 if ((int )single_toc.pointb2 > 175) { #line 1601 while (1) { #line 1601 break; } } } #line 1612 if (res_size > 45U) { #line 1612 if ((int )single_toc.pointb3 > 175) { #line 1613 while (1) { #line 1613 break; } } } #line 1624 if (res_size > 54U) { #line 1624 if ((int )single_toc.pointb4 > 175) { #line 1625 while (1) { #line 1625 break; } } } #line 1636 if (res_size > 63U) { #line 1636 if ((int )single_toc.pointc0 > 175) { #line 1637 while (1) { #line 1637 break; } } } #line 1651 tmp___1 = bcd_to_int((unsigned int )single_toc.lead_out_start_msf[0]); #line 1651 sony_toc.lead_out_start_msf[0] = (unsigned char )tmp___1; #line 1653 tmp___2 = bcd_to_int((unsigned int )single_toc.lead_out_start_msf[1]); #line 1653 sony_toc.lead_out_start_msf[1] = (unsigned char )tmp___2; #line 1655 tmp___3 = bcd_to_int((unsigned int )single_toc.lead_out_start_msf[2]); #line 1655 sony_toc.lead_out_start_msf[2] = (unsigned char )tmp___3; #line 1657 single_toc.lead_out_start_lba = msf_to_log(sony_toc.lead_out_start_msf); #line 1657 sony_toc.lead_out_start_lba = single_toc.lead_out_start_lba; #line 1663 if ((int )single_toc.pointb0 != 176) { #line 1664 memmove((void *)((char *)(& single_toc) + 27), (void const *)((char *)(& single_toc) + 18), res_size - 18U); #line 1667 res_size += 9U; } else #line 1668 if (res_size > 18U) { #line 1669 tmp___4 = bcd_to_int((unsigned int )single_toc.max_start_outer_leadout_msf[0]); #line 1669 sony_toc.lead_out_start_msf[0] = (unsigned char )tmp___4; #line 1673 tmp___5 = bcd_to_int((unsigned int )single_toc.max_start_outer_leadout_msf[1]); #line 1673 sony_toc.lead_out_start_msf[1] = (unsigned char )tmp___5; #line 1677 tmp___6 = bcd_to_int((unsigned int )single_toc.max_start_outer_leadout_msf[2]); #line 1677 sony_toc.lead_out_start_msf[2] = (unsigned char )tmp___6; #line 1681 sony_toc.lead_out_start_lba = msf_to_log(sony_toc.lead_out_start_msf); } #line 1685 if ((int )single_toc.pointb1 != 177) { #line 1686 memmove((void *)((char *)(& single_toc) + 36), (void const *)((char *)(& single_toc) + 27), res_size - 27U); #line 1689 res_size += 9U; } #line 1691 if ((int )single_toc.pointb2 != 178) { #line 1692 memmove((void *)((char *)(& single_toc) + 45), (void const *)((char *)(& single_toc) + 36), res_size - 36U); #line 1695 res_size += 9U; } #line 1697 if ((int )single_toc.pointb3 != 179) { #line 1698 memmove((void *)((char *)(& single_toc) + 54), (void const *)((char *)(& single_toc) + 45), res_size - 45U); #line 1701 res_size += 9U; } #line 1703 if ((int )single_toc.pointb4 != 180) { #line 1704 memmove((void *)((char *)(& single_toc) + 63), (void const *)((char *)(& single_toc) + 54), res_size - 54U); #line 1707 res_size += 9U; } #line 1709 if ((int )single_toc.pointc0 != 192) { #line 1710 memmove((void *)((char *)(& single_toc) + 72), (void const *)((char *)(& single_toc) + 63), res_size - 63U); #line 1713 res_size += 9U; } #line 1769 if ((int )single_toc.disk_type == 16) { #line 1769 if ((int )single_toc.first_track_num == 2) { #line 1769 if ((int )single_toc.last_track_num == 2) { #line 1772 sony_toc.tracks[totaltracks].address = (unsigned char)1; #line 1773 sony_toc.tracks[totaltracks].control = (unsigned char)4; #line 1774 sony_toc.tracks[totaltracks].track = (unsigned char)1; #line 1775 sony_toc.tracks[totaltracks].track_start_msf[0] = (unsigned char)0; #line 1777 sony_toc.tracks[totaltracks].track_start_msf[1] = (unsigned char)2; #line 1779 sony_toc.tracks[totaltracks].track_start_msf[2] = (unsigned char)0; #line 1781 maxt = 1; #line 1781 mint = maxt; #line 1782 totaltracks ++; } else { #line 1769 goto _L___2; } } else { #line 1769 goto _L___2; } } else { _L___2: /* CIL Label */ #line 1787 i = 0; #line 1787 while (1) { #line 1787 tmp___11 = bcd_to_int((unsigned int )single_toc.last_track_num); #line 1787 tmp___12 = bcd_to_int((unsigned int )single_toc.first_track_num); #line 1787 if (! ((unsigned int )i < (1U + tmp___11) - tmp___12)) { #line 1787 break; } #line 1795 sony_toc.tracks[totaltracks].address = single_toc.tracks[i].address; #line 1798 sony_toc.tracks[totaltracks].control = single_toc.tracks[i].control; #line 1801 tmp___7 = bcd_to_int((unsigned int )single_toc.tracks[i].track); #line 1801 sony_toc.tracks[totaltracks].track = (unsigned char )tmp___7; #line 1805 tmp___8 = bcd_to_int((unsigned int )single_toc.tracks[i].track_start_msf[0]); #line 1805 sony_toc.tracks[totaltracks].track_start_msf[0] = (unsigned char )tmp___8; #line 1810 tmp___9 = bcd_to_int((unsigned int )single_toc.tracks[i].track_start_msf[1]); #line 1810 sony_toc.tracks[totaltracks].track_start_msf[1] = (unsigned char )tmp___9; #line 1815 tmp___10 = bcd_to_int((unsigned int )single_toc.tracks[i].track_start_msf[2]); #line 1815 sony_toc.tracks[totaltracks].track_start_msf[2] = (unsigned char )tmp___10; #line 1820 if (i == 0) { #line 1821 single_toc.start_track_lba = msf_to_log(sony_toc.tracks[totaltracks].track_start_msf); } #line 1827 if (mint > (int )sony_toc.tracks[totaltracks].track) { #line 1830 mint = (int )sony_toc.tracks[totaltracks].track; } #line 1834 if (maxt < (int )sony_toc.tracks[totaltracks].track) { #line 1837 maxt = (int )sony_toc.tracks[totaltracks].track; } #line 1787 i ++; #line 1787 totaltracks ++; } } #line 1843 sony_toc.first_track_num = (unsigned char )mint; #line 1844 sony_toc.last_track_num = (unsigned char )maxt; #line 1851 sony_toc.disk_type = single_toc.disk_type; #line 1852 sony_toc.sessions = (unsigned char )session; #line 1855 if (session == 1) { #line 1856 single_toc.start_track_lba = 0U; } #line 1857 sony_toc.start_track_lba = single_toc.start_track_lba; #line 1860 if (session > 1) { #line 1860 if ((int )single_toc.pointb0 == 176) { #line 1860 if (sony_toc.lead_out_start_lba == single_toc.lead_out_start_lba) { #line 1863 break; } } } #line 1867 if (session > 40) { #line 1868 printk("<5>CDU31A: too many sessions: %d\n", session); #line 1870 break; } #line 1872 session ++; } #line 1874 sony_toc.track_entries = (unsigned int )totaltracks; #line 1876 sony_toc.tracks[totaltracks].address = single_toc.address2; #line 1877 sony_toc.tracks[totaltracks].control = single_toc.control2; #line 1878 sony_toc.tracks[totaltracks].track = (unsigned char)170; #line 1879 sony_toc.tracks[totaltracks].track_start_msf[0] = sony_toc.lead_out_start_msf[0]; #line 1881 sony_toc.tracks[totaltracks].track_start_msf[1] = sony_toc.lead_out_start_msf[1]; #line 1883 sony_toc.tracks[totaltracks].track_start_msf[2] = sony_toc.lead_out_start_msf[2]; #line 1886 sony_toc_read = 1; #line 1888 while (1) { #line 1888 break; } } #line 1893 while (1) { #line 1893 break; } #line 1894 return; } } #line 1901 "cdu31a.c" static int scd_get_last_session(struct cdrom_device_info *cdi , struct cdrom_multisession *ms_info ) { int tmp ; int tmp___0 ; { #line 1904 if ((unsigned long )ms_info == (unsigned long )((void *)0)) { #line 1905 return (1); } #line 1907 if (! sony_toc_read) { #line 1908 tmp = down_interruptible(& sony_sem); #line 1908 if (tmp) { #line 1909 return (-512); } #line 1910 sony_get_toc(); #line 1911 up(& sony_sem); } #line 1914 ms_info->addr_format = (__u8 )1; #line 1915 ms_info->addr.lba = (int )sony_toc.start_track_lba; #line 1916 if ((int )sony_toc.disk_type == 32) { #line 1916 tmp___0 = 1; } else #line 1916 if ((int )sony_toc.disk_type == 16) { #line 1916 tmp___0 = 1; } else { #line 1916 tmp___0 = 0; } #line 1916 ms_info->xa_flag = (__u8 )tmp___0; #line 1919 return (0); } } #line 1925 "cdu31a.c" static int find_track(int track ) { int i ; { #line 1929 i = 0; #line 1929 while ((unsigned int )i <= sony_toc.track_entries) { #line 1930 if ((int )sony_toc.tracks[i].track == track) { #line 1931 return (i); } #line 1929 i ++; } #line 1935 return (-1); } } #line 1942 "cdu31a.c" static int read_subcode(void) { unsigned int res_size ; unsigned char *tmp ; unsigned int tmp___0 ; unsigned int tmp___1 ; unsigned int tmp___2 ; unsigned int tmp___3 ; unsigned int tmp___4 ; unsigned int tmp___5 ; unsigned int tmp___6 ; unsigned int tmp___7 ; { #line 1947 do_sony_cd_cmd((unsigned char)33, (unsigned char *)((void *)0), 0U, (unsigned char *)(& last_sony_subcode), & res_size); #line 1950 if (res_size < 2U) { #line 1952 tmp = translate_error(last_sony_subcode.exec_status[1]); #line 1952 printk("<3>CDU31A: Sony CDROM error %s (read_subcode)\n", tmp); #line 1954 return (-5); } else #line 1950 if (((int )last_sony_subcode.exec_status[0] & 240) == 32) { #line 1952 tmp = translate_error(last_sony_subcode.exec_status[1]); #line 1952 printk("<3>CDU31A: Sony CDROM error %s (read_subcode)\n", tmp); #line 1954 return (-5); } #line 1957 tmp___0 = bcd_to_int((unsigned int )last_sony_subcode.track_num); #line 1957 last_sony_subcode.track_num = (unsigned char )tmp___0; #line 1959 tmp___1 = bcd_to_int((unsigned int )last_sony_subcode.index_num); #line 1959 last_sony_subcode.index_num = (unsigned char )tmp___1; #line 1961 tmp___2 = bcd_to_int((unsigned int )last_sony_subcode.abs_msf[0]); #line 1961 last_sony_subcode.abs_msf[0] = (unsigned char )tmp___2; #line 1963 tmp___3 = bcd_to_int((unsigned int )last_sony_subcode.abs_msf[1]); #line 1963 last_sony_subcode.abs_msf[1] = (unsigned char )tmp___3; #line 1965 tmp___4 = bcd_to_int((unsigned int )last_sony_subcode.abs_msf[2]); #line 1965 last_sony_subcode.abs_msf[2] = (unsigned char )tmp___4; #line 1968 tmp___5 = bcd_to_int((unsigned int )last_sony_subcode.rel_msf[0]); #line 1968 last_sony_subcode.rel_msf[0] = (unsigned char )tmp___5; #line 1970 tmp___6 = bcd_to_int((unsigned int )last_sony_subcode.rel_msf[1]); #line 1970 last_sony_subcode.rel_msf[1] = (unsigned char )tmp___6; #line 1972 tmp___7 = bcd_to_int((unsigned int )last_sony_subcode.rel_msf[2]); #line 1972 last_sony_subcode.rel_msf[2] = (unsigned char )tmp___7; #line 1974 return (0); } } #line 1981 "cdu31a.c" static int scd_get_mcn(struct cdrom_device_info *cdi , struct cdrom_mcn *mcn ) { unsigned char resbuffer[16] ; unsigned char *mcnp ; unsigned char *resp ; unsigned int res_size ; int tmp ; unsigned char *tmp___0 ; unsigned char *tmp___1 ; unsigned char *tmp___2 ; unsigned char *tmp___3 ; unsigned char *tmp___4 ; unsigned char *tmp___5 ; unsigned char *tmp___6 ; unsigned char *tmp___7 ; unsigned char *tmp___8 ; unsigned char *tmp___9 ; unsigned char *tmp___10 ; unsigned char *tmp___11 ; unsigned char *tmp___12 ; unsigned char *tmp___13 ; unsigned char *tmp___14 ; unsigned char *tmp___15 ; unsigned char *tmp___16 ; unsigned char *tmp___17 ; unsigned char *tmp___18 ; { #line 1985 mcnp = mcn->medium_catalog_number; #line 1986 resp = resbuffer + 3; #line 1989 memset((void *)(mcn->medium_catalog_number), 0, 14U); #line 1990 tmp = down_interruptible(& sony_sem); #line 1990 if (tmp) { #line 1991 return (-512); } #line 1992 do_sony_cd_cmd((unsigned char)34, (unsigned char *)((void *)0), 0U, resbuffer, & res_size); #line 1994 up(& sony_sem); #line 1995 if (! (res_size < 2U)) { #line 1995 if (! (((int )resbuffer[0] & 240) == 32)) { #line 1998 tmp___0 = mcnp; #line 1998 mcnp ++; #line 1998 *tmp___0 = (unsigned char )(((int )*resp >> 4) + 48); #line 1999 tmp___1 = mcnp; #line 1999 mcnp ++; #line 1999 tmp___2 = resp; #line 1999 resp ++; #line 1999 *tmp___1 = (unsigned char )(((int )*tmp___2 & 15) + 48); #line 2000 tmp___3 = mcnp; #line 2000 mcnp ++; #line 2000 *tmp___3 = (unsigned char )(((int )*resp >> 4) + 48); #line 2001 tmp___4 = mcnp; #line 2001 mcnp ++; #line 2001 tmp___5 = resp; #line 2001 resp ++; #line 2001 *tmp___4 = (unsigned char )(((int )*tmp___5 & 15) + 48); #line 2002 tmp___6 = mcnp; #line 2002 mcnp ++; #line 2002 *tmp___6 = (unsigned char )(((int )*resp >> 4) + 48); #line 2003 tmp___7 = mcnp; #line 2003 mcnp ++; #line 2003 tmp___8 = resp; #line 2003 resp ++; #line 2003 *tmp___7 = (unsigned char )(((int )*tmp___8 & 15) + 48); #line 2004 tmp___9 = mcnp; #line 2004 mcnp ++; #line 2004 *tmp___9 = (unsigned char )(((int )*resp >> 4) + 48); #line 2005 tmp___10 = mcnp; #line 2005 mcnp ++; #line 2005 tmp___11 = resp; #line 2005 resp ++; #line 2005 *tmp___10 = (unsigned char )(((int )*tmp___11 & 15) + 48); #line 2006 tmp___12 = mcnp; #line 2006 mcnp ++; #line 2006 *tmp___12 = (unsigned char )(((int )*resp >> 4) + 48); #line 2007 tmp___13 = mcnp; #line 2007 mcnp ++; #line 2007 tmp___14 = resp; #line 2007 resp ++; #line 2007 *tmp___13 = (unsigned char )(((int )*tmp___14 & 15) + 48); #line 2008 tmp___15 = mcnp; #line 2008 mcnp ++; #line 2008 *tmp___15 = (unsigned char )(((int )*resp >> 4) + 48); #line 2009 tmp___16 = mcnp; #line 2009 mcnp ++; #line 2009 tmp___17 = resp; #line 2009 resp ++; #line 2009 *tmp___16 = (unsigned char )(((int )*tmp___17 & 15) + 48); #line 2010 tmp___18 = mcnp; #line 2010 mcnp ++; #line 2010 *tmp___18 = (unsigned char )(((int )*resp >> 4) + 48); } } #line 2012 *mcnp = (unsigned char )'\000'; #line 2013 return (0); } } #line 2024 "cdu31a.c" static int sony_get_subchnl_info(struct cdrom_subchnl *schi ) { int tmp ; int tmp___0 ; unsigned int tmp___1 ; unsigned int tmp___2 ; { #line 2027 while (1) { #line 2027 tmp = handle_sony_cd_attention(); #line 2027 if (! tmp) { #line 2027 break; } } #line 2029 sony_get_toc(); #line 2030 if (! sony_toc_read) { #line 2031 return (-5); } #line 2034 switch (sony_audio_status) { case (int volatile )17: case (int volatile )21: #line 2037 tmp___0 = read_subcode(); #line 2037 if (tmp___0 < 0) { #line 2038 return (-5); } #line 2040 break; case (int volatile )19: case (int volatile )18: #line 2044 break; default: #line 2055 return (-5); } #line 2058 schi->cdsc_audiostatus = (__u8 )sony_audio_status; #line 2059 schi->cdsc_adr = last_sony_subcode.address; #line 2060 schi->cdsc_ctrl = last_sony_subcode.control; #line 2061 schi->cdsc_trk = last_sony_subcode.track_num; #line 2062 schi->cdsc_ind = last_sony_subcode.index_num; #line 2063 if ((int )schi->cdsc_format == 2) { #line 2064 schi->cdsc_absaddr.msf.minute = last_sony_subcode.abs_msf[0]; #line 2066 schi->cdsc_absaddr.msf.second = last_sony_subcode.abs_msf[1]; #line 2068 schi->cdsc_absaddr.msf.frame = last_sony_subcode.abs_msf[2]; #line 2071 schi->cdsc_reladdr.msf.minute = last_sony_subcode.rel_msf[0]; #line 2073 schi->cdsc_reladdr.msf.second = last_sony_subcode.rel_msf[1]; #line 2075 schi->cdsc_reladdr.msf.frame = last_sony_subcode.rel_msf[2]; } else #line 2077 if ((int )schi->cdsc_format == 1) { #line 2078 tmp___1 = msf_to_log(last_sony_subcode.abs_msf); #line 2078 schi->cdsc_absaddr.lba = (int )tmp___1; #line 2080 tmp___2 = msf_to_log(last_sony_subcode.rel_msf); #line 2080 schi->cdsc_reladdr.lba = (int )tmp___2; } #line 2084 return (0); } } #line 2091 "cdu31a.c" static void read_audio_data(char *buffer , unsigned char *res_reg , int *res_size ) { unsigned long retry_count ; int result_read ; int tmp ; int tmp___0 ; int tmp___1 ; int tmp___2 ; int tmp___3 ; int tmp___4 ; int tmp___5 ; int tmp___6 ; { #line 2098 *(res_reg + 0) = (unsigned char)0; #line 2099 *(res_reg + 1) = (unsigned char)0; #line 2100 *res_size = 0; #line 2101 result_read = 0; #line 2104 retry_count = jiffies + 1000UL; continue_read_audio_wait: #line 2106 while (1) { #line 2106 if ((long )jiffies - (long )retry_count < 0L) { #line 2106 tmp___0 = is_data_ready(); #line 2106 if (tmp___0) { #line 2106 break; } else { #line 2106 tmp___1 = is_result_ready(); #line 2106 if (tmp___1) { #line 2106 break; } else #line 2106 if (result_read) { #line 2106 break; } } } else { #line 2106 break; } #line 2108 while (1) { #line 2108 tmp = handle_sony_cd_attention(); #line 2108 if (! tmp) { #line 2108 break; } } #line 2110 sony_sleep(); } #line 2112 tmp___6 = is_data_ready(); #line 2112 if (tmp___6) { #line 2139 clear_data_ready(); #line 2142 if (sony_raw_data_mode) { #line 2143 insb((unsigned int )sony_cd_read_reg, (void *)(buffer + 12), 2340UL); } else { #line 2147 insb((unsigned int )sony_cd_read_reg, (void *)buffer, 2352UL); } #line 2151 if (! result_read) { #line 2153 retry_count = jiffies + 1000UL; #line 2154 while (1) { #line 2154 if ((long )jiffies - (long )retry_count < 0L) { #line 2154 tmp___4 = is_result_ready(); #line 2154 if (tmp___4) { #line 2154 break; } } else { #line 2154 break; } #line 2156 while (1) { #line 2156 tmp___3 = handle_sony_cd_attention(); #line 2156 if (! tmp___3) { #line 2156 break; } } #line 2158 sony_sleep(); } #line 2161 tmp___5 = is_result_ready(); #line 2161 if (tmp___5) { #line 2169 get_result(res_reg, (unsigned int *)res_size); } else { #line 2162 while (1) { #line 2162 break; } #line 2163 *(res_reg + 0) = (unsigned char)32; #line 2164 *(res_reg + 1) = (unsigned char)1; #line 2165 *res_size = 2; #line 2166 abort_read(); #line 2167 return; } } #line 2173 if (((int )*(res_reg + 0) & 240) == 80) { #line 2174 if (! ((int )*(res_reg + 0) == 80)) { #line 2174 if (! ((int )*(res_reg + 0) == 84)) { #line 2174 if (! ((int )*(res_reg + 0) == 85)) { #line 2174 if (! ((int )*(res_reg + 0) == 89)) { #line 2180 printk("<3>CDU31A: Data block error: 0x%x\n", (int )*(res_reg + 0)); #line 2182 *(res_reg + 0) = (unsigned char)32; #line 2183 *(res_reg + 1) = (unsigned char)3; #line 2184 *res_size = 2; } } } } } else #line 2186 if (((int )*(res_reg + 0) & 240) != 32) { #line 2189 printk("<5>CDU31A: Invalid block status: 0x%x\n", (int )*(res_reg + 0)); #line 2191 restart_on_error(); #line 2192 *(res_reg + 0) = (unsigned char)32; #line 2193 *(res_reg + 1) = (unsigned char)3; #line 2194 *res_size = 2; } } else { #line 2113 tmp___2 = is_result_ready(); #line 2113 if (tmp___2) { #line 2113 if (! result_read) { #line 2114 get_result(res_reg, (unsigned int *)res_size); #line 2117 if (((int )*(res_reg + 0) & 240) == 80) { #line 2118 result_read = 1; #line 2119 goto continue_read_audio_wait; } else #line 2122 if (((int )*(res_reg + 0) & 240) != 32) { #line 2123 printk("<4>CDU31A: Got result that should have been error: %d\n", (int )*(res_reg + 0)); #line 2126 *(res_reg + 0) = (unsigned char)32; #line 2127 *(res_reg + 1) = (unsigned char)3; #line 2128 *res_size = 2; } #line 2130 abort_read(); } else { #line 2113 goto _L; } } else { _L: /* CIL Label */ #line 2132 while (1) { #line 2132 break; } #line 2133 *(res_reg + 0) = (unsigned char)32; #line 2134 *(res_reg + 1) = (unsigned char)1; #line 2135 *res_size = 2; #line 2136 abort_read(); } } #line 2197 return; } } #line 2201 "cdu31a.c" static int read_audio(struct cdrom_read_audio *ra ) { int retval ; unsigned char params[2] ; unsigned char res_reg[12] ; unsigned int res_size ; unsigned int cframe ; int tmp ; int tmp___0 ; int tmp___1 ; unsigned char *tmp___2 ; unsigned long tmp___3 ; unsigned char *tmp___4 ; unsigned long tmp___5 ; unsigned char *tmp___6 ; { #line 2209 tmp = down_interruptible(& sony_sem); #line 2209 if (tmp) { #line 2210 return (-512); } #line 2211 if (! sony_spun_up) { #line 2212 scd_spinup(); } #line 2215 params[0] = (unsigned char)0; #line 2216 params[1] = (unsigned char )(6 | sony_raw_data_mode); #line 2217 do_sony_cd_cmd((unsigned char)16, params, 2U, res_reg, & res_size); #line 2219 if (res_size < 2U) { #line 2220 printk("<3>CDU31A: Unable to set decode params: 0x%2.2x\n", (int )res_reg[1]); #line 2222 retval = -5; #line 2223 goto out_up; } else #line 2219 if (((int )res_reg[0] & 240) == 32) { #line 2220 printk("<3>CDU31A: Unable to set decode params: 0x%2.2x\n", (int )res_reg[1]); #line 2222 retval = -5; #line 2223 goto out_up; } #line 2230 retval = 0; #line 2231 tmp___0 = start_request((unsigned int )ra->addr.lba, (unsigned int )ra->nframes); #line 2231 if (tmp___0) { #line 2232 retval = -5; #line 2233 goto exit_read_audio; } #line 2237 cframe = 0U; #line 2238 while (cframe < (unsigned int )ra->nframes) { #line 2239 read_audio_data(audio_buffer, res_reg, (int *)(& res_size)); #line 2240 if (((int )res_reg[0] & 240) == 32) { #line 2241 if ((int )res_reg[1] == 3) { #line 2242 printk("<3>CDU31A: Data error on audio sector %d\n", (unsigned int )ra->addr.lba + cframe); } else #line 2245 if ((int )res_reg[1] == 64) { #line 2247 if (sony_raw_data_mode) { #line 2247 sony_raw_data_mode = 0; } else { #line 2247 sony_raw_data_mode = 1; } #line 2251 params[0] = (unsigned char)0; #line 2252 params[1] = (unsigned char )(6 | sony_raw_data_mode); #line 2253 do_sony_cd_cmd((unsigned char)16, params, 2U, res_reg, & res_size); #line 2256 if (res_size < 2U) { #line 2258 printk("<3>CDU31A: Unable to set decode params: 0x%2.2x\n", (int )res_reg[1]); #line 2261 retval = -5; #line 2262 goto exit_read_audio; } else #line 2256 if (((int )res_reg[0] & 240) == 32) { #line 2258 printk("<3>CDU31A: Unable to set decode params: 0x%2.2x\n", (int )res_reg[1]); #line 2261 retval = -5; #line 2262 goto exit_read_audio; } #line 2266 tmp___1 = start_request((unsigned int )ra->addr.lba + cframe, (unsigned int )ra->nframes - cframe); #line 2266 if (tmp___1) { #line 2269 retval = -5; #line 2270 goto exit_read_audio; } #line 2276 read_audio_data(audio_buffer, res_reg, (int *)(& res_size)); #line 2278 if (((int )res_reg[0] & 240) == 32) { #line 2279 if ((int )res_reg[1] == 3) { #line 2281 printk("<3>CDU31A: Data error on audio sector %d\n", (unsigned int )ra->addr.lba + cframe); } else { #line 2286 tmp___2 = translate_error(res_reg[1]); #line 2286 printk("<3>CDU31A: Error reading audio data on sector %d: %s\n", (unsigned int )ra->addr.lba + cframe, tmp___2); #line 2290 retval = -5; #line 2291 goto exit_read_audio; } } else { #line 2293 tmp___3 = copy_to_user((void *)(ra->buf + 2352U * cframe), (void const *)(audio_buffer), 2352UL); #line 2293 if (tmp___3) { #line 2298 retval = -14; #line 2299 goto exit_read_audio; } } } else { #line 2302 tmp___4 = translate_error(res_reg[1]); #line 2302 printk("<3>CDU31A: Error reading audio data on sector %d: %s\n", (unsigned int )ra->addr.lba + cframe, tmp___4); #line 2306 retval = -5; #line 2307 goto exit_read_audio; } } else { #line 2309 tmp___5 = copy_to_user((void *)(ra->buf + 2352U * cframe), (void const *)(audio_buffer), 2352UL); #line 2309 if (tmp___5) { #line 2312 retval = -14; #line 2313 goto exit_read_audio; } } #line 2316 cframe ++; } #line 2319 get_result(res_reg, & res_size); #line 2320 if (((int )res_reg[0] & 240) == 32) { #line 2321 tmp___6 = translate_error(res_reg[1]); #line 2321 printk("<3>CDU31A: Error return from audio read: %s\n", tmp___6); #line 2323 retval = -5; #line 2324 goto exit_read_audio; } exit_read_audio: #line 2330 params[0] = (unsigned char)0; #line 2331 if (! sony_xa_mode) { #line 2332 params[1] = (unsigned char)15; } else { #line 2334 params[1] = (unsigned char)7; } #line 2336 do_sony_cd_cmd((unsigned char)16, params, 2U, res_reg, & res_size); #line 2338 if (res_size < 2U) { #line 2339 printk("<3>CDU31A: Unable to reset decode params: 0x%2.2x\n", (int )res_reg[1]); #line 2341 retval = -5; } else #line 2338 if (((int )res_reg[0] & 240) == 32) { #line 2339 printk("<3>CDU31A: Unable to reset decode params: 0x%2.2x\n", (int )res_reg[1]); #line 2341 retval = -5; } out_up: #line 2345 up(& sony_sem); #line 2347 return (retval); } } #line 2350 "cdu31a.c" static int do_sony_cd_cmd_chk(char const *name , unsigned char cmd , unsigned char *params , unsigned int num_params , unsigned char *result_buffer , unsigned int *result_size ) { unsigned char *tmp ; { #line 2357 do_sony_cd_cmd(cmd, params, num_params, result_buffer, result_size); #line 2359 if (*result_size < 2U) { #line 2360 tmp = translate_error(*(result_buffer + 1)); #line 2360 printk("<3>CDU31A: Error %s (CDROM%s)\n", tmp, name); #line 2362 return (-5); } else #line 2359 if (((int )*(result_buffer + 0) & 240) == 32) { #line 2360 tmp = translate_error(*(result_buffer + 1)); #line 2360 printk("<3>CDU31A: Error %s (CDROM%s)\n", tmp, name); #line 2362 return (-5); } #line 2364 return (0); } } #line 2371 "cdu31a.c" static int scd_tray_move(struct cdrom_device_info *cdi , int position ) { int retval ; int tmp ; unsigned char res_reg[12] ; unsigned int res_size ; int tmp___0 ; { #line 2375 tmp = down_interruptible(& sony_sem); #line 2375 if (tmp) { #line 2376 return (-512); } #line 2377 if (position == 1) { #line 2381 do_sony_cd_cmd((unsigned char)65, (unsigned char *)((void *)0), 0U, res_reg, & res_size); #line 2383 do_sony_cd_cmd((unsigned char)82, (unsigned char *)((void *)0), 0U, res_reg, & res_size); #line 2386 sony_audio_status = (int volatile )0; #line 2387 retval = do_sony_cd_cmd_chk("EJECT", (unsigned char)80, (unsigned char *)((void *)0), 0U, res_reg, & res_size); } else { #line 2390 tmp___0 = scd_spinup(); #line 2390 if (0 == tmp___0) { #line 2391 sony_spun_up = 1; } #line 2392 retval = 0; } #line 2394 up(& sony_sem); #line 2395 return (retval); } } #line 2401 "cdu31a.c" static int scd_audio_ioctl(struct cdrom_device_info *cdi , unsigned int cmd , void *arg ) { unsigned char res_reg[12] ; unsigned int res_size ; unsigned char params[7] ; int i ; int retval ; int tmp ; int tmp___0 ; int tmp___1 ; unsigned int tmp___2 ; unsigned int tmp___3 ; unsigned int tmp___4 ; unsigned int tmp___5 ; unsigned int tmp___6 ; unsigned int tmp___7 ; int tmp___8 ; unsigned int tmp___9 ; int tmp___10 ; unsigned int tmp___11 ; unsigned int tmp___12 ; unsigned int tmp___13 ; struct cdrom_tochdr *hdr ; struct cdrom_tocentry *entry ; int track_idx ; unsigned char *msf_val ; unsigned int tmp___14 ; struct cdrom_ti *ti ; int track_idx___0 ; unsigned int tmp___15 ; unsigned int tmp___16 ; unsigned int tmp___17 ; unsigned int tmp___18 ; unsigned int tmp___19 ; unsigned int tmp___20 ; unsigned char *tmp___21 ; unsigned int tmp___22 ; unsigned int tmp___23 ; unsigned int tmp___24 ; struct cdrom_volctrl *volctrl ; { #line 2409 tmp = down_interruptible(& sony_sem); #line 2409 if (tmp) { #line 2410 return (-512); } #line 2411 switch (cmd) { case 21256U: #line 2413 retval = do_sony_cd_cmd_chk("START", (unsigned char)81, (unsigned char *)((void *)0), 0U, res_reg, & res_size); #line 2415 break; case 21255U: #line 2418 do_sony_cd_cmd((unsigned char)65, (unsigned char *)((void *)0), 0U, res_reg, & res_size); #line 2425 sony_audio_status = (int volatile )21; #line 2426 retval = do_sony_cd_cmd_chk("STOP", (unsigned char)82, (unsigned char *)((void *)0), 0U, res_reg, & res_size); #line 2428 break; case 21249U: #line 2431 tmp___0 = do_sony_cd_cmd_chk("PAUSE", (unsigned char)65, (unsigned char *)((void *)0), 0U, res_reg, & res_size); #line 2431 if (tmp___0) { #line 2434 retval = -5; #line 2435 break; } #line 2438 tmp___1 = read_subcode(); #line 2438 if (tmp___1 < 0) { #line 2439 retval = -5; #line 2440 break; } #line 2442 cur_pos_msf[0] = (unsigned char volatile )last_sony_subcode.abs_msf[0]; #line 2443 cur_pos_msf[1] = (unsigned char volatile )last_sony_subcode.abs_msf[1]; #line 2444 cur_pos_msf[2] = (unsigned char volatile )last_sony_subcode.abs_msf[2]; #line 2445 sony_audio_status = (int volatile )18; #line 2446 retval = 0; #line 2447 break; case 21250U: #line 2450 if (sony_audio_status != (int volatile )18) { #line 2451 retval = -22; #line 2452 break; } #line 2455 do_sony_cd_cmd((unsigned char)81, (unsigned char *)((void *)0), 0U, res_reg, & res_size); #line 2459 tmp___2 = int_to_bcd((unsigned int )cur_pos_msf[0]); #line 2459 params[1] = (unsigned char )tmp___2; #line 2460 tmp___3 = int_to_bcd((unsigned int )cur_pos_msf[1]); #line 2460 params[2] = (unsigned char )tmp___3; #line 2461 tmp___4 = int_to_bcd((unsigned int )cur_pos_msf[2]); #line 2461 params[3] = (unsigned char )tmp___4; #line 2462 tmp___5 = int_to_bcd((unsigned int )final_pos_msf[0]); #line 2462 params[4] = (unsigned char )tmp___5; #line 2463 tmp___6 = int_to_bcd((unsigned int )final_pos_msf[1]); #line 2463 params[5] = (unsigned char )tmp___6; #line 2464 tmp___7 = int_to_bcd((unsigned int )final_pos_msf[2]); #line 2464 params[6] = (unsigned char )tmp___7; #line 2465 params[0] = (unsigned char)3; #line 2466 tmp___8 = do_sony_cd_cmd_chk("RESUME", (unsigned char)64, params, 7U, res_reg, & res_size); #line 2466 if (tmp___8 < 0) { #line 2469 retval = -5; #line 2470 break; } #line 2472 sony_audio_status = (int volatile )17; #line 2473 retval = 0; #line 2474 break; case 21251U: #line 2477 do_sony_cd_cmd((unsigned char)81, (unsigned char *)((void *)0), 0U, res_reg, & res_size); #line 2481 i = 1; #line 2481 while (i < 7) { #line 2482 tmp___9 = int_to_bcd((unsigned int )*((unsigned char *)arg + (i - 1))); #line 2482 params[i] = (unsigned char )tmp___9; #line 2481 i ++; } #line 2485 params[0] = (unsigned char)3; #line 2486 tmp___10 = do_sony_cd_cmd_chk("PLAYMSF", (unsigned char)64, params, 7U, res_reg, & res_size); #line 2486 if (tmp___10 < 0) { #line 2489 retval = -5; #line 2490 break; } #line 2494 tmp___11 = bcd_to_int((unsigned int )params[4]); #line 2494 final_pos_msf[0] = (unsigned char volatile )tmp___11; #line 2495 tmp___12 = bcd_to_int((unsigned int )params[5]); #line 2495 final_pos_msf[1] = (unsigned char volatile )tmp___12; #line 2496 tmp___13 = bcd_to_int((unsigned int )params[6]); #line 2496 final_pos_msf[2] = (unsigned char volatile )tmp___13; #line 2497 sony_audio_status = (int volatile )17; #line 2498 retval = 0; #line 2499 break; case 21253U: #line 2505 sony_get_toc(); #line 2506 if (! sony_toc_read) { #line 2507 retval = -5; #line 2508 break; } #line 2511 hdr = (struct cdrom_tochdr *)arg; #line 2512 hdr->cdth_trk0 = sony_toc.first_track_num; #line 2513 hdr->cdth_trk1 = sony_toc.last_track_num; #line 2515 retval = 0; #line 2516 break; case 21254U: #line 2522 msf_val = (unsigned char *)((void *)0); #line 2524 sony_get_toc(); #line 2525 if (! sony_toc_read) { #line 2526 retval = -5; #line 2527 break; } #line 2530 entry = (struct cdrom_tocentry *)arg; #line 2532 track_idx = find_track((int )entry->cdte_track); #line 2533 if (track_idx < 0) { #line 2534 retval = -22; #line 2535 break; } #line 2538 entry->cdte_adr = sony_toc.tracks[track_idx].address; #line 2540 entry->cdte_ctrl = sony_toc.tracks[track_idx].control; #line 2542 msf_val = sony_toc.tracks[track_idx].track_start_msf; #line 2546 if ((int )entry->cdte_format == 1) { #line 2547 tmp___14 = msf_to_log(msf_val); #line 2547 entry->cdte_addr.lba = (int )tmp___14; } else #line 2548 if ((int )entry->cdte_format == 2) { #line 2549 entry->cdte_addr.msf.minute = *msf_val; #line 2550 entry->cdte_addr.msf.second = *(msf_val + 1); #line 2552 entry->cdte_addr.msf.frame = *(msf_val + 2); } #line 2556 retval = 0; #line 2557 break; case 21252U: #line 2561 ti = (struct cdrom_ti *)arg; #line 2564 sony_get_toc(); #line 2565 if (! sony_toc_read) { #line 2566 retval = -5; #line 2567 break; } #line 2570 if ((int )ti->cdti_trk0 < (int )sony_toc.first_track_num) { #line 2573 retval = -22; #line 2574 break; } else #line 2570 if ((int )ti->cdti_trk0 > (int )sony_toc.last_track_num) { #line 2573 retval = -22; #line 2574 break; } else #line 2570 if ((int )ti->cdti_trk1 < (int )ti->cdti_trk0) { #line 2573 retval = -22; #line 2574 break; } #line 2577 track_idx___0 = find_track((int )ti->cdti_trk0); #line 2578 if (track_idx___0 < 0) { #line 2579 retval = -22; #line 2580 break; } #line 2582 tmp___15 = int_to_bcd((unsigned int )sony_toc.tracks[track_idx___0].track_start_msf[0]); #line 2582 params[1] = (unsigned char )tmp___15; #line 2585 tmp___16 = int_to_bcd((unsigned int )sony_toc.tracks[track_idx___0].track_start_msf[1]); #line 2585 params[2] = (unsigned char )tmp___16; #line 2588 tmp___17 = int_to_bcd((unsigned int )sony_toc.tracks[track_idx___0].track_start_msf[2]); #line 2588 params[3] = (unsigned char )tmp___17; #line 2596 if ((int )ti->cdti_trk1 >= (int )sony_toc.last_track_num) { #line 2597 track_idx___0 = find_track(170); } else { #line 2599 track_idx___0 = find_track((int )ti->cdti_trk1 + 1); } #line 2601 if (track_idx___0 < 0) { #line 2602 retval = -22; #line 2603 break; } #line 2605 tmp___18 = int_to_bcd((unsigned int )sony_toc.tracks[track_idx___0].track_start_msf[0]); #line 2605 params[4] = (unsigned char )tmp___18; #line 2608 tmp___19 = int_to_bcd((unsigned int )sony_toc.tracks[track_idx___0].track_start_msf[1]); #line 2608 params[5] = (unsigned char )tmp___19; #line 2611 tmp___20 = int_to_bcd((unsigned int )sony_toc.tracks[track_idx___0].track_start_msf[2]); #line 2611 params[6] = (unsigned char )tmp___20; #line 2614 params[0] = (unsigned char)3; #line 2616 do_sony_cd_cmd((unsigned char)81, (unsigned char *)((void *)0), 0U, res_reg, & res_size); #line 2619 do_sony_cd_cmd((unsigned char)64, params, 7U, res_reg, & res_size); #line 2622 if (res_size < 2U) { #line 2624 printk("<3>CDU31A: Params: %x %x %x %x %x %x %x\n", (int )params[0], (int )params[1], (int )params[2], (int )params[3], (int )params[4], (int )params[5], (int )params[6]); #line 2629 tmp___21 = translate_error(res_reg[1]); #line 2629 printk("<3>CDU31A: Error %s (CDROMPLAYTRKIND)\n", tmp___21); #line 2632 retval = -5; #line 2633 break; } else #line 2622 if (((int )res_reg[0] & 240) == 32) { #line 2624 printk("<3>CDU31A: Params: %x %x %x %x %x %x %x\n", (int )params[0], (int )params[1], (int )params[2], (int )params[3], (int )params[4], (int )params[5], (int )params[6]); #line 2629 tmp___21 = translate_error(res_reg[1]); #line 2629 printk("<3>CDU31A: Error %s (CDROMPLAYTRKIND)\n", tmp___21); #line 2632 retval = -5; #line 2633 break; } #line 2637 tmp___22 = bcd_to_int((unsigned int )params[4]); #line 2637 final_pos_msf[0] = (unsigned char volatile )tmp___22; #line 2638 tmp___23 = bcd_to_int((unsigned int )params[5]); #line 2638 final_pos_msf[1] = (unsigned char volatile )tmp___23; #line 2639 tmp___24 = bcd_to_int((unsigned int )params[6]); #line 2639 final_pos_msf[2] = (unsigned char volatile )tmp___24; #line 2640 sony_audio_status = (int volatile )17; #line 2641 retval = 0; #line 2642 break; case 21258U: #line 2647 volctrl = (struct cdrom_volctrl *)arg; #line 2650 params[0] = (unsigned char)4; #line 2651 params[1] = volctrl->channel0; #line 2652 params[2] = volctrl->channel1; #line 2653 retval = do_sony_cd_cmd_chk("VOLCTRL", (unsigned char)16, params, 3U, res_reg, & res_size); #line 2657 break; case 21259U: #line 2660 retval = sony_get_subchnl_info((struct cdrom_subchnl *)arg); #line 2661 break; default: #line 2664 retval = -22; #line 2665 break; } #line 2667 up(& sony_sem); #line 2668 return (retval); } } #line 2671 "cdu31a.c" static int scd_dev_ioctl(struct cdrom_device_info *cdi , unsigned int cmd , unsigned long arg ) { void *argp ; int retval ; int tmp ; struct cdrom_read_audio ra ; unsigned long tmp___0 ; int tmp___1 ; { #line 2674 argp = (void *)arg; #line 2677 tmp = down_interruptible(& sony_sem); #line 2677 if (tmp) { #line 2678 return (-512); } #line 2679 switch (cmd) { case 21262U: #line 2686 sony_get_toc(); #line 2687 if (! sony_toc_read) { #line 2688 retval = -5; #line 2689 break; } #line 2692 tmp___0 = copy_from_user((void *)(& ra), argp, sizeof(ra)); #line 2692 if (tmp___0) { #line 2693 retval = -14; #line 2694 break; } #line 2697 if (ra.nframes == 0) { #line 2698 retval = 0; #line 2699 break; } #line 2702 tmp___1 = access_ok(1, (void const *)ra.buf, (unsigned long )(2352 * ra.nframes)); #line 2702 if (! tmp___1) { #line 2704 return (-14); } #line 2706 if ((int )ra.addr_format == 1) { #line 2707 if ((unsigned int )ra.addr.lba >= sony_toc.lead_out_start_lba) { #line 2711 retval = -22; #line 2712 break; } else #line 2707 if ((unsigned int )(ra.addr.lba + ra.nframes) >= sony_toc.lead_out_start_lba) { #line 2711 retval = -22; #line 2712 break; } } else #line 2714 if ((int )ra.addr_format == 2) { #line 2715 if ((int )ra.addr.msf.minute >= 75) { #line 2718 retval = -22; #line 2719 break; } else #line 2715 if ((int )ra.addr.msf.second >= 60) { #line 2718 retval = -22; #line 2719 break; } else #line 2715 if ((int )ra.addr.msf.frame >= 75) { #line 2718 retval = -22; #line 2719 break; } #line 2722 ra.addr.lba = ((int )ra.addr.msf.minute * 4500 + (int )ra.addr.msf.second * 75) + (int )ra.addr.msf.frame; #line 2725 if ((unsigned int )ra.addr.lba >= sony_toc.lead_out_start_lba) { #line 2729 retval = -22; #line 2730 break; } else #line 2725 if ((unsigned int )(ra.addr.lba + ra.nframes) >= sony_toc.lead_out_start_lba) { #line 2729 retval = -22; #line 2730 break; } #line 2736 ra.addr.lba -= 150; } else { #line 2738 retval = -22; #line 2739 break; } #line 2742 retval = read_audio(& ra); #line 2743 break; #line 2745 retval = 0; #line 2746 break; default: #line 2749 retval = -22; } #line 2751 up(& sony_sem); #line 2752 return (retval); } } #line 2755 "cdu31a.c" static int scd_spinup(void) { unsigned char res_reg[12] ; unsigned int res_size ; int num_spin_ups ; unsigned char *tmp ; unsigned char *tmp___0 ; { #line 2761 num_spin_ups = 0; respinup_on_open: #line 2764 do_sony_cd_cmd((unsigned char)81, (unsigned char *)((void *)0), 0U, res_reg, & res_size); #line 2768 if (res_size < 2U) { #line 2769 tmp = translate_error(res_reg[1]); #line 2769 printk("<3>CDU31A: %s error (scd_open, spin up)\n", tmp); #line 2771 return (1); } else #line 2768 if ((int )res_reg[0] != 0) { #line 2768 if ((int )res_reg[1] != 0) { #line 2769 tmp = translate_error(res_reg[1]); #line 2769 printk("<3>CDU31A: %s error (scd_open, spin up)\n", tmp); #line 2771 return (1); } } #line 2774 do_sony_cd_cmd((unsigned char)48, (unsigned char *)((void *)0), 0U, res_reg, & res_size); #line 2778 if (res_size < 2U) { #line 2778 goto _L; } else #line 2778 if ((int )res_reg[0] != 0) { #line 2778 if ((int )res_reg[1] != 0) { _L: /* CIL Label */ #line 2780 if ((int )res_reg[1] == 42) { #line 2782 return (0); } else #line 2780 if ((int )res_reg[1] == 0) { #line 2782 return (0); } #line 2787 if ((int )res_reg[1] == 34) { #line 2787 if (num_spin_ups < 3) { #line 2789 num_spin_ups ++; #line 2790 goto respinup_on_open; } } #line 2793 tmp___0 = translate_error(res_reg[1]); #line 2793 printk("<3>CDU31A: Error %s (scd_open, read toc)\n", tmp___0); #line 2795 do_sony_cd_cmd((unsigned char)82, (unsigned char *)((void *)0), 0U, res_reg, & res_size); #line 2797 return (1); } } #line 2799 return (0); } } #line 2806 "cdu31a.c" static int scd_open(struct cdrom_device_info *cdi , int purpose ) { unsigned char res_reg[12] ; unsigned int res_size ; unsigned char params[2] ; int tmp ; { #line 2812 if (purpose == 1) { #line 2814 sony_usage ++; #line 2815 return (0); } #line 2818 if (sony_usage == 0U) { #line 2819 tmp = scd_spinup(); #line 2819 if (tmp != 0) { #line 2820 return (-5); } #line 2821 sony_get_toc(); #line 2822 if (! sony_toc_read) { #line 2823 do_sony_cd_cmd((unsigned char)82, (unsigned char *)((void *)0), 0U, res_reg, & res_size); #line 2825 return (-5); } #line 2831 if ((int )sony_toc.disk_type != 0) { #line 2831 if (! is_double_speed) { #line 2833 params[0] = (unsigned char)0; #line 2834 params[1] = (unsigned char)7; #line 2835 do_sony_cd_cmd((unsigned char)16, params, 2U, res_reg, & res_size); #line 2837 if (res_size < 2U) { #line 2839 printk("<4>CDU31A: Unable to set XA params: 0x%2.2x\n", (int )res_reg[1]); } else #line 2837 if (((int )res_reg[0] & 240) == 32) { #line 2839 printk("<4>CDU31A: Unable to set XA params: 0x%2.2x\n", (int )res_reg[1]); } #line 2842 sony_xa_mode = 1; } else { #line 2831 goto _L; } } else _L: /* CIL Label */ #line 2845 if (sony_xa_mode) { #line 2846 params[0] = (unsigned char)0; #line 2847 params[1] = (unsigned char)15; #line 2848 do_sony_cd_cmd((unsigned char)16, params, 2U, res_reg, & res_size); #line 2850 if (res_size < 2U) { #line 2852 printk("<4>CDU31A: Unable to reset XA params: 0x%2.2x\n", (int )res_reg[1]); } else #line 2850 if (((int )res_reg[0] & 240) == 32) { #line 2852 printk("<4>CDU31A: Unable to reset XA params: 0x%2.2x\n", (int )res_reg[1]); } #line 2855 sony_xa_mode = 0; } #line 2858 sony_spun_up = 1; } #line 2861 sony_usage ++; #line 2863 return (0); } } #line 2871 "cdu31a.c" static void scd_release(struct cdrom_device_info *cdi ) { unsigned char res_reg[12] ; unsigned int res_size ; { #line 2873 if (sony_usage == 1U) { #line 2877 do_sony_cd_cmd((unsigned char)82, (unsigned char *)((void *)0), 0U, res_reg, & res_size); #line 2880 sony_spun_up = 0; } #line 2882 sony_usage --; #line 2883 return; } } #line 2885 "cdu31a.c" static struct cdrom_device_ops scd_dops = #line 2885 {& scd_open, & scd_release, & scd_drive_status, & scd_media_changed, & scd_tray_move, & scd_lock_door, & scd_select_speed, (int (*)(struct cdrom_device_info * , int ))0, & scd_get_last_session, & scd_get_mcn, & scd_reset, & scd_audio_ioctl, & scd_dev_ioctl, (int const )4079, 1, (int (*)(struct cdrom_device_info * , struct packet_command * ))0}; #line 2905 "cdu31a.c" static struct cdrom_device_info scd_info = #line 2905 {& scd_dops, (struct cdrom_device_info *)0, (struct gendisk *)0, (void *)0, 0, 2, 1, 0, 0U, 0, {(char )'c', (char )'d', (char )'u', (char )'3', (char )'1', (char )'a', (char )'\000'}, (unsigned char)0, (unsigned char)0, 0, (unsigned char)0, (unsigned char)0, (unsigned short)0, 0, (int (*)(struct cdrom_device_info * ))0, 0}; #line 2912 "cdu31a.c" static int scd_block_open(struct inode *inode , struct file *file ) { int tmp ; { #line 2914 tmp = cdrom_open(& scd_info, inode, file); #line 2914 return (tmp); } } #line 2917 "cdu31a.c" static int scd_block_release(struct inode *inode , struct file *file ) { int tmp ; { #line 2919 tmp = cdrom_release(& scd_info, file); #line 2919 return (tmp); } } #line 2922 "cdu31a.c" static int scd_block_ioctl(struct inode *inode , struct file *file , unsigned int cmd , unsigned long arg ) { int retval ; { #line 2931 switch (cmd) { case 21257U: #line 2933 scd_lock_door(& scd_info, 0); #line 2934 retval = scd_tray_move(& scd_info, 1); #line 2935 break; case 21273U: #line 2937 retval = scd_tray_move(& scd_info, 0); #line 2938 break; default: #line 2940 retval = cdrom_ioctl(file, & scd_info, inode, cmd, arg); } #line 2942 return (retval); } } #line 2945 "cdu31a.c" static int scd_block_media_changed(struct gendisk *disk ) { int tmp ; { #line 2947 tmp = cdrom_media_changed(& scd_info); #line 2947 return (tmp); } } #line 2950 "cdu31a.c" static struct block_device_operations scd_bdops = #line 2950 {& scd_block_open, & scd_block_release, & scd_block_ioctl, (long (*)(struct file * , unsigned int , unsigned long ))0, (long (*)(struct file * , unsigned int , unsigned long ))0, (int (*)(struct block_device * , sector_t , unsigned long * ))0, & scd_block_media_changed, (int (*)(struct gendisk * ))0, (int (*)(struct block_device * , struct hd_geometry * ))0, (struct module *)0}; #line 2959 "cdu31a.c" static struct gendisk *scd_gendisk ; #line 2962 "cdu31a.c" static char *load_mech[4] = { (char *)"caddy", (char *)"tray", (char *)"pop-up", (char *)"unknown"}; #line 2965 "cdu31a.c" static int get_drive_configuration(unsigned short base_io , unsigned char *res_reg , unsigned int *res_size ) { unsigned long retry_count ; struct resource *tmp ; int tmp___0 ; unsigned char tmp___1 ; { #line 2972 tmp = request_region((unsigned long )base_io, 4UL, "cdu31a"); #line 2972 if (! tmp) { #line 2973 return (0); } #line 2976 cdu31a_port = (unsigned int )base_io; #line 2979 sony_cd_cmd_reg = (unsigned short volatile )cdu31a_port; #line 2980 sony_cd_param_reg = (unsigned short volatile )(cdu31a_port + 1U); #line 2981 sony_cd_write_reg = (unsigned short volatile )(cdu31a_port + 2U); #line 2982 sony_cd_control_reg = (unsigned short volatile )(cdu31a_port + 3U); #line 2983 sony_cd_status_reg = (unsigned short volatile )cdu31a_port; #line 2984 sony_cd_result_reg = (unsigned short volatile )(cdu31a_port + 1U); #line 2985 sony_cd_read_reg = (unsigned short volatile )(cdu31a_port + 2U); #line 2986 sony_cd_fifost_reg = (unsigned short volatile )(cdu31a_port + 3U); #line 2993 tmp___1 = read_status_register(); #line 2993 if ((int )tmp___1 != 255) { #line 2998 reset_drive(); #line 2999 retry_count = jiffies + 100UL; #line 3000 while (1) { #line 3000 if ((long )jiffies - (long )retry_count < 0L) { #line 3000 tmp___0 = is_attention(); #line 3000 if (tmp___0) { #line 3000 break; } } else { #line 3000 break; } #line 3002 sony_sleep(); } #line 3016 do_sony_cd_cmd((unsigned char)0, (unsigned char *)((void *)0), 0U, res_reg, res_size); #line 3019 if (*res_size <= 2U) { #line 3020 goto out_err; } else #line 3019 if (((int )*(res_reg + 0) & 240) != 0) { #line 3020 goto out_err; } #line 3021 return (1); } #line 3025 *(res_reg + 0) = (unsigned char)32; out_err: #line 3027 release_region((unsigned long )cdu31a_port, 4UL); #line 3028 cdu31a_port = 0U; #line 3029 return (0); } } #line 3068 "cdu31a.c" int cdu31a_init(void) { struct s_sony_drive_config drive_config ; struct gendisk *disk ; int deficiency ; unsigned int res_size ; char msg[255] ; char buf[40] ; int i ; int tmp_irq ; int tmp ; int tmp___0 ; int tmp___1 ; int tmp___2 ; int tmp___3 ; int tmp___4 ; { #line 3072 deficiency = 0; #line 3086 if (sony_pas_init) { #line 3087 outb((unsigned char)188, 39425U); #line 3088 outb((unsigned char)226, 39425U); } #line 3092 if (cdu31a_port == 65535U) { #line 3093 goto errout3; } #line 3095 if (cdu31a_port != 0U) { #line 3097 tmp_irq = cdu31a_irq; #line 3098 cdu31a_irq = 0; #line 3099 tmp = get_drive_configuration((unsigned short )cdu31a_port, drive_config.exec_status, & res_size); #line 3099 if (! tmp) { #line 3102 goto errout3; } #line 3103 cdu31a_irq = tmp_irq; } else { #line 3105 cdu31a_irq = 0; #line 3106 i = 0; #line 3106 while (cdu31a_addresses[i].base) { #line 3107 tmp___0 = get_drive_configuration(cdu31a_addresses[i].base, drive_config.exec_status, & res_size); #line 3107 if (tmp___0) { #line 3110 cdu31a_irq = (int )cdu31a_addresses[i].int_num; #line 3111 break; } #line 3106 i ++; } #line 3114 if (! cdu31a_port) { #line 3115 goto errout3; } } #line 3118 tmp___1 = register_blkdev(15U, "cdu31a"); #line 3118 if (tmp___1) { #line 3119 goto errout2; } #line 3121 disk = alloc_disk(1); #line 3122 if (! disk) { #line 3123 goto errout1; } #line 3124 disk->major = 15; #line 3125 disk->first_minor = 0; #line 3126 sprintf(disk->disk_name, "cdu31a"); #line 3127 disk->fops = & scd_bdops; #line 3128 disk->flags = 8; #line 3130 if ((int )drive_config.hw_config[0] & 16) { #line 3131 is_double_speed = 1; } #line 3133 tmp_irq = cdu31a_irq; #line 3134 cdu31a_irq = 0; #line 3136 sony_speed = is_double_speed; #line 3137 set_drive_params(sony_speed); #line 3139 cdu31a_irq = tmp_irq; #line 3141 if (cdu31a_irq > 0) { #line 3142 tmp___2 = request_irq((unsigned int )cdu31a_irq, & cdu31a_interrupt, 536870912UL, "cdu31a", (void *)0); #line 3142 if (tmp___2) { #line 3145 printk("<4>CDU31A: Unable to grab IRQ%d for the CDU31A driver\n", cdu31a_irq); #line 3147 cdu31a_irq = 0; } } #line 3151 sprintf(msg, "Sony I/F CDROM : %8.8s %16.16s %8.8s\n", drive_config.vendor_id, drive_config.product_id, drive_config.product_rev_level); #line 3155 sprintf(buf, " Capabilities: %s", load_mech[(int )drive_config.hw_config[0] & 3]); #line 3157 strcat(msg, (char const *)(buf)); #line 3158 if ((int )drive_config.hw_config[1] & 1) { #line 3159 strcat(msg, ", audio"); } else { #line 3161 deficiency |= 256; } #line 3162 if ((int )drive_config.hw_config[0] & 4) { #line 3163 strcat(msg, ", eject"); } else { #line 3165 deficiency |= 2; } #line 3166 if ((int )drive_config.hw_config[0] & 8) { #line 3167 strcat(msg, ", LED"); } #line 3168 if ((int )drive_config.hw_config[1] & 2) { #line 3169 strcat(msg, ", elec. Vol"); } #line 3170 if ((int )drive_config.hw_config[1] & 4) { #line 3171 strcat(msg, ", sep. Vol"); } #line 3172 if (is_double_speed) { #line 3173 strcat(msg, ", double speed"); } else { #line 3175 deficiency |= 8; } #line 3176 if (cdu31a_irq > 0) { #line 3177 sprintf(buf, ", irq %d", cdu31a_irq); #line 3178 strcat(msg, (char const *)(buf)); } #line 3180 strcat(msg, "\n"); #line 3181 printk("<6>CDU31A: %s", msg); #line 3183 cdu31a_queue = blk_init_queue(& do_cdu31a_request, & cdu31a_lock); #line 3184 if (! cdu31a_queue) { #line 3185 goto errout0; } #line 3186 blk_queue_hardsect_size(cdu31a_queue, (unsigned short)2048); #line 3188 init_timer(& cdu31a_abort_timer); #line 3189 cdu31a_abort_timer.function = & handle_abort_timeout; #line 3191 scd_info.mask = deficiency; #line 3192 scd_gendisk = disk; #line 3193 tmp___3 = register_cdrom(& scd_info); #line 3193 if (tmp___3) { #line 3194 goto err; } #line 3195 disk->queue = cdu31a_queue; #line 3196 add_disk(disk); #line 3198 disk_changed = (char)1; #line 3199 return (0); err: #line 3202 blk_cleanup_queue(cdu31a_queue); errout0: #line 3204 if (cdu31a_irq) { #line 3205 free_irq((unsigned int )cdu31a_irq, (void *)0); } #line 3206 printk("<3>CDU31A: Unable to register with Uniform cdrom driver\n"); #line 3207 put_disk(disk); errout1: #line 3209 tmp___4 = unregister_blkdev(15U, "cdu31a"); #line 3209 if (tmp___4) { #line 3210 printk("<4>CDU31A: Can\'t unregister block device\n"); } errout2: #line 3213 release_region((unsigned long )cdu31a_port, 4UL); errout3: #line 3215 return (-5); } } #line 3219 "cdu31a.c" static void cdu31a_exit(void) { int tmp ; int tmp___0 ; { #line 3221 del_gendisk(scd_gendisk); #line 3222 put_disk(scd_gendisk); #line 3223 tmp = unregister_cdrom(& scd_info); #line 3223 if (tmp) { #line 3224 printk("<4>CDU31A: Can\'t unregister from Uniform cdrom driver\n"); #line 3226 return; } #line 3228 tmp___0 = unregister_blkdev(15U, "cdu31a"); #line 3228 if (tmp___0 == -22) { #line 3229 printk("<4>CDU31A: Can\'t unregister\n"); #line 3230 return; } #line 3233 blk_cleanup_queue(cdu31a_queue); #line 3235 if (cdu31a_irq > 0) { #line 3236 free_irq((unsigned int )cdu31a_irq, (void *)0); } #line 3238 release_region((unsigned long )cdu31a_port, 4UL); #line 3239 printk("<6>CDU31A: module released.\n"); #line 3240 return; } } #line 3243 "cdu31a.c" int (*_ddv_tmp_init)(void) = & cdu31a_init; #line 3245 "cdu31a.c" void (*_ddv_tmp_exit)(void) = & cdu31a_exit; #line 3247 "cdu31a.c" char _ddv_module_license[4] = { (char )'G', (char )'P', (char )'L', (char )'\000'}; #line 3248 "cdu31a.c" int _ddv_module_param_major = 15; #line 4 "__main.c" int main(void) { { #line 6 _ddv_module_init = & cdu31a_init; #line 7 _ddv_module_exit = & cdu31a_exit; #line 8 call_ddv(); #line 10 return (0); } } #line 1 "manage.o" #pragma merger("0","/tmp/cil-6AH8C_XZ.i","") #line 4 "/usr/local/ddv/models/con2/src/linux/kernel/irq/manage.c" int request_irq(unsigned int irq , irqreturn_t (*handler)(int , void * , struct pt_regs * ) , unsigned long irqflags , char const *devname , void *dev_id ) { int tmp ; { #line 7 tmp = nondet_int(); #line 7 if (tmp) { #line 8 registered_irq[irq].handler = handler; #line 9 registered_irq[irq].dev_id = dev_id; #line 11 return (0); } else { #line 13 return (-1); } } } #line 17 "/usr/local/ddv/models/con2/src/linux/kernel/irq/manage.c" void free_irq(unsigned int irq , void *dev_id ) { { #line 19 registered_irq[irq].handler = (irqreturn_t (*)(int , void * , struct pt_regs * ))((void *)0); #line 20 registered_irq[irq].dev_id = (void *)0; #line 21 return; } } #line 1 "misc.o" #pragma merger("0","/tmp/cil-XqqdI_Me.i","") #line 40 "/usr/local/ddv/models/con2/include/linux/miscdevice.h" int misc_register(struct miscdevice *misc ) ; #line 11 "/usr/local/ddv/models/con2/include/linux/proc_fs.h" struct proc_dir_entry *proc_root_driver ; #line 18 "/usr/local/ddv/models/con2/src/linux/drivers/char/misc.c" int misc_register(struct miscdevice *misc ) { int i ; dev_t dev ; int tmp ; { #line 23 if (fixed_cdev_used < 10) { #line 24 i = fixed_cdev_used; #line 25 fixed_cdev_used ++; #line 27 fixed_cdev[i].owner = (struct module *)0; #line 28 fixed_cdev[i].ops = misc->fops; #line 30 dev = (dev_t )((10 << 20) | misc->minor); #line 32 tmp = cdev_add(& fixed_cdev[i], dev, 0U); #line 32 return (tmp); } else { #line 34 return (-1); } } } #line 1 "mutex.o" #pragma merger("0","/tmp/cil-sXp5trps.i","") #line 32 "/usr/local/ddv/models/con2/include/ddverify/ddverify.h" __inline static int assert_context_process(void) { { #line 34 return (0); } } #line 32 "/usr/local/ddv/models/con2/include/linux/mutex.h" __inline void mutex_init(struct mutex *lock ) ; #line 34 __inline void mutex_lock(struct mutex *lock ) ; #line 36 __inline void mutex_unlock(struct mutex *lock ) ; #line 4 "/usr/local/ddv/models/con2/src/linux/kernel/mutex.c" __inline void mutex_init(struct mutex *lock ) { { #line 7 __CPROVER_atomic_begin(); #line 11 lock->locked = 0; #line 12 lock->init = 1; #line 13 __CPROVER_atomic_end(); #line 14 return; } } #line 16 "/usr/local/ddv/models/con2/src/linux/kernel/mutex.c" __inline void mutex_lock(struct mutex *lock ) { { #line 27 while (1) { #line 29 __CPROVER_atomic_begin(); #line 30 if (lock->locked == 0) { #line 32 lock->locked = 1; #line 33 __CPROVER_atomic_end(); #line 34 return; } #line 36 __CPROVER_atomic_end(); } } } #line 41 "/usr/local/ddv/models/con2/src/linux/kernel/mutex.c" __inline void mutex_unlock(struct mutex *lock ) { { #line 44 __CPROVER_atomic_begin(); #line 45 assert_context_process(); #line 49 lock->locked = 0; #line 50 __CPROVER_atomic_end(); #line 51 return; } } #line 1 "page_alloc.o" #pragma merger("0","/tmp/cil-tj9rpXJ9.i","") #line 55 "/usr/local/ddv/models/con2/include/linux/gfp.h" __inline unsigned long __get_free_pages(gfp_t gfp_mask , unsigned int order ) ; #line 57 __inline unsigned long __get_free_page(gfp_t gfp_mask ) ; #line 59 __inline unsigned long get_zeroed_page(gfp_t gfp_mask ) ; #line 70 __inline struct page *alloc_pages(gfp_t gfp_mask , unsigned int order ) ; #line 72 __inline struct page *alloc_page(gfp_t gfp_mask ) ; #line 5 "/usr/local/ddv/models/con2/src/linux/mm/page_alloc.c" __inline unsigned long __get_free_pages(gfp_t gfp_mask , unsigned int order ) { { #line 8 if (gfp_mask & 16U) { #line 9 assert_context_process(); } #line 11 return (0UL); } } #line 13 "/usr/local/ddv/models/con2/src/linux/mm/page_alloc.c" __inline unsigned long __get_free_page(gfp_t gfp_mask ) { { #line 16 if (gfp_mask & 16U) { #line 17 assert_context_process(); } #line 19 return (0UL); } } #line 38 "/usr/local/ddv/models/con2/src/linux/mm/page_alloc.c" __inline struct page *alloc_pages(gfp_t gfp_mask , unsigned int order ) { { #line 41 if (gfp_mask & 16U) { #line 42 assert_context_process(); } #line 44 return ((struct page *)0); } } #line 46 "/usr/local/ddv/models/con2/src/linux/mm/page_alloc.c" __inline struct page *alloc_page(gfp_t gfp_mask ) { { #line 49 if (gfp_mask & 16U) { #line 50 assert_context_process(); } #line 52 return ((struct page *)0); } } #line 1 "pci.o" #pragma merger("0","/tmp/cil-KA7ONeAL.i","") #line 96 "/usr/local/ddv/models/con2/include/linux/ioport.h" extern struct resource *request_mem_region(unsigned long start , unsigned long len , char const *name ) ; #line 98 extern void release_mem_region(unsigned long start , unsigned long len ) ; #line 87 "/usr/local/ddv/models/con2/include/linux/pci.h" __inline struct pci_dev *pci_get_class(unsigned int class , struct pci_dev *from ) ; #line 141 __inline int pci_register_driver(struct pci_driver *driver ) ; #line 143 __inline void pci_unregister_driver(struct pci_driver *driver ) ; #line 145 __inline int pci_enable_device(struct pci_dev *dev ) ; #line 152 __inline int pci_request_regions(struct pci_dev *pdev , char const *res_name ) ; #line 154 __inline void pci_release_regions(struct pci_dev *pdev ) ; #line 156 __inline int pci_request_region(struct pci_dev *pdev , int bar , char const *res_name ) ; #line 158 __inline void pci_release_region(struct pci_dev *pdev , int bar ) ; #line 8 "/usr/local/ddv/models/con2/src/linux/pci.c" __inline int pci_enable_device(struct pci_dev *dev ) { int i ; unsigned int tmp ; unsigned short tmp___0 ; { #line 12 i = 0; #line 12 while (i < 12) { #line 13 dev->resource[i].flags = 256UL; #line 14 tmp = nondet_uint(); #line 14 dev->resource[i].start = (unsigned long )tmp; #line 15 tmp___0 = nondet_ushort(); #line 15 dev->resource[i].end = dev->resource[i].start + (unsigned long )tmp___0; #line 12 i ++; } #line 17 return (0); } } #line 19 "/usr/local/ddv/models/con2/src/linux/pci.c" __inline struct pci_dev *pci_get_class(unsigned int class , struct pci_dev *from ) { void *tmp ; int tmp___0 ; { #line 21 if ((unsigned long )from == (unsigned long )((void *)0)) { #line 22 tmp = malloc((size_t )sizeof(struct pci_dev )); #line 22 from = (struct pci_dev *)tmp; } #line 25 tmp___0 = nondet_int(); #line 25 if (tmp___0) { #line 26 from->vendor = nondet_ushort(); #line 27 from->device = nondet_ushort(); #line 28 from->irq = nondet_uint(); #line 29 __CPROVER_assume(from->irq < 16U); #line 31 return (from); } else { #line 33 return ((struct pci_dev *)((void *)0)); } } } #line 37 "/usr/local/ddv/models/con2/src/linux/pci.c" __inline int pci_register_driver(struct pci_driver *driver ) { int tmp ; { #line 39 tmp = nondet_int(); #line 39 if (tmp) { #line 40 registered_pci_driver.pci_driver = driver; #line 41 registered_pci_driver.no_pci_device_id = (unsigned int )(sizeof(driver->id_table) / sizeof(struct pci_device_id )); #line 42 registered_pci_driver.dev_initialized = 0; #line 44 return (0); } else { #line 46 return (-1); } } } #line 50 "/usr/local/ddv/models/con2/src/linux/pci.c" __inline void pci_unregister_driver(struct pci_driver *driver ) { { #line 52 registered_pci_driver.pci_driver = (struct pci_driver *)((void *)0); #line 53 registered_pci_driver.no_pci_device_id = 0U; #line 54 return; } } #line 56 "/usr/local/ddv/models/con2/src/linux/pci.c" __inline void pci_release_region(struct pci_dev *pdev , int bar ) { unsigned long tmp ; unsigned long tmp___0 ; unsigned long tmp___1 ; { #line 58 if (pdev->resource[bar].start == 0UL) { #line 58 if (pdev->resource[bar].end == pdev->resource[bar].start) { #line 58 tmp = 0UL; } else { #line 58 tmp = (pdev->resource[bar].end - pdev->resource[bar].start) + 1UL; } } else { #line 58 tmp = (pdev->resource[bar].end - pdev->resource[bar].start) + 1UL; } #line 58 if (tmp == 0UL) { #line 59 return; } #line 60 if (pdev->resource[bar].flags & 256UL) { #line 61 if (pdev->resource[bar].start == 0UL) { #line 61 if (pdev->resource[bar].end == pdev->resource[bar].start) { #line 61 tmp___0 = 0UL; } else { #line 61 tmp___0 = (pdev->resource[bar].end - pdev->resource[bar].start) + 1UL; } } else { #line 61 tmp___0 = (pdev->resource[bar].end - pdev->resource[bar].start) + 1UL; } #line 61 release_region(pdev->resource[bar].start, tmp___0); } else #line 63 if (pdev->resource[bar].flags & 512UL) { #line 64 if (pdev->resource[bar].start == 0UL) { #line 64 if (pdev->resource[bar].end == pdev->resource[bar].start) { #line 64 tmp___1 = 0UL; } else { #line 64 tmp___1 = (pdev->resource[bar].end - pdev->resource[bar].start) + 1UL; } } else { #line 64 tmp___1 = (pdev->resource[bar].end - pdev->resource[bar].start) + 1UL; } #line 64 release_mem_region(pdev->resource[bar].start, tmp___1); } #line 66 return; } } #line 68 "/usr/local/ddv/models/con2/src/linux/pci.c" __inline int pci_request_region(struct pci_dev *pdev , int bar , char const *res_name ) { unsigned long tmp ; unsigned long tmp___0 ; struct resource *tmp___1 ; unsigned long tmp___2 ; struct resource *tmp___3 ; { #line 70 if (pdev->resource[bar].start == 0UL) { #line 70 if (pdev->resource[bar].end == pdev->resource[bar].start) { #line 70 tmp = 0UL; } else { #line 70 tmp = (pdev->resource[bar].end - pdev->resource[bar].start) + 1UL; } } else { #line 70 tmp = (pdev->resource[bar].end - pdev->resource[bar].start) + 1UL; } #line 70 if (tmp == 0UL) { #line 71 return (0); } #line 73 if (pdev->resource[bar].flags & 256UL) { #line 74 if (pdev->resource[bar].start == 0UL) { #line 74 if (pdev->resource[bar].end == pdev->resource[bar].start) { #line 74 tmp___0 = 0UL; } else { #line 74 tmp___0 = (pdev->resource[bar].end - pdev->resource[bar].start) + 1UL; } } else { #line 74 tmp___0 = (pdev->resource[bar].end - pdev->resource[bar].start) + 1UL; } #line 74 tmp___1 = request_region(pdev->resource[bar].start, tmp___0, res_name); #line 74 if (! tmp___1) { #line 76 return (-16); } } else #line 78 if (pdev->resource[bar].flags & 512UL) { #line 79 if (pdev->resource[bar].start == 0UL) { #line 79 if (pdev->resource[bar].end == pdev->resource[bar].start) { #line 79 tmp___2 = 0UL; } else { #line 79 tmp___2 = (pdev->resource[bar].end - pdev->resource[bar].start) + 1UL; } } else { #line 79 tmp___2 = (pdev->resource[bar].end - pdev->resource[bar].start) + 1UL; } #line 79 tmp___3 = request_mem_region(pdev->resource[bar].start, tmp___2, res_name); #line 79 if (! tmp___3) { #line 81 return (-16); } } #line 84 return (0); } } #line 87 "/usr/local/ddv/models/con2/src/linux/pci.c" __inline void pci_release_regions(struct pci_dev *pdev ) { int i ; { #line 91 i = 0; #line 91 while (i < 6) { #line 92 pci_release_region(pdev, i); #line 91 i ++; } #line 93 return; } } #line 95 "/usr/local/ddv/models/con2/src/linux/pci.c" __inline int pci_request_regions(struct pci_dev *pdev , char const *res_name ) { int i ; int tmp ; { #line 99 i = 0; #line 99 while (i < 6) { #line 100 tmp = pci_request_region(pdev, i, res_name); #line 100 if (tmp) { #line 101 goto err_out; } #line 99 i ++; } #line 102 return (0); err_out: #line 105 while (1) { #line 105 i --; #line 105 if (! (i >= 0)) { #line 105 break; } #line 106 pci_release_region(pdev, i); } #line 108 return (-16); } } #line 1 "resource.o" #pragma merger("0","/tmp/cil-_bb963FQ.i","") #line 21 "/usr/local/ddv/models/con2/include/ddverify/satabs.h" extern unsigned char nondet_uchar() ; #line 22 extern unsigned int nondet_unsigned() ; #line 10 "/usr/local/ddv/models/con2/include/ddverify/ioport.h" int ddv_ioport_request_start ; #line 11 "/usr/local/ddv/models/con2/include/ddverify/ioport.h" int ddv_ioport_request_len ; #line 6 "/usr/local/ddv/models/con2/src/linux/kernel/resource.c" struct resource *request_region(unsigned long start , unsigned long len , char const *name ) { struct resource *resource ; void *tmp ; { #line 9 tmp = malloc((size_t )sizeof(struct resource )); #line 9 resource = (struct resource *)tmp; #line 14 ddv_ioport_request_start = (int )start; #line 15 ddv_ioport_request_len = (int )len; #line 17 return (resource); } } #line 20 "/usr/local/ddv/models/con2/src/linux/kernel/resource.c" void release_region(unsigned long start , unsigned long len ) { unsigned int i ; { #line 22 i = 0U; #line 28 ddv_ioport_request_start = 0; #line 29 ddv_ioport_request_len = 0; #line 30 return; } } #line 32 "/usr/local/ddv/models/con2/src/linux/kernel/resource.c" unsigned char inb(unsigned int port ) { int tmp ; unsigned char tmp___0 ; { #line 35 if (port >= (unsigned int )ddv_ioport_request_start) { #line 35 if (port < (unsigned int )(ddv_ioport_request_start + ddv_ioport_request_len)) { #line 35 tmp = 1; } else { #line 35 tmp = 0; } } else { #line 35 tmp = 0; } #line 35 __CPROVER_assert(tmp, "I/O port is requested"); #line 37 tmp___0 = nondet_uchar(); #line 37 return (tmp___0); } } #line 40 "/usr/local/ddv/models/con2/src/linux/kernel/resource.c" void outb(unsigned char byte , unsigned int port ) { int tmp ; { #line 43 if (port >= (unsigned int )ddv_ioport_request_start) { #line 43 if (port < (unsigned int )(ddv_ioport_request_start + ddv_ioport_request_len)) { #line 43 tmp = 1; } else { #line 43 tmp = 0; } } else { #line 43 tmp = 0; } #line 43 __CPROVER_assert(tmp, "I/O port is requested"); #line 44 return; } } #line 46 "/usr/local/ddv/models/con2/src/linux/kernel/resource.c" __inline unsigned short inw(unsigned int port ) { int tmp ; unsigned short tmp___0 ; { #line 49 if (port >= (unsigned int )ddv_ioport_request_start) { #line 49 if (port < (unsigned int )(ddv_ioport_request_start + ddv_ioport_request_len)) { #line 49 tmp = 1; } else { #line 49 tmp = 0; } } else { #line 49 tmp = 0; } #line 49 __CPROVER_assert(tmp, "I/O port is requested"); #line 51 tmp___0 = nondet_ushort(); #line 51 return (tmp___0); } } #line 54 "/usr/local/ddv/models/con2/src/linux/kernel/resource.c" __inline void outw(unsigned short word , unsigned int port ) { int tmp ; { #line 57 if (port >= (unsigned int )ddv_ioport_request_start) { #line 57 if (port < (unsigned int )(ddv_ioport_request_start + ddv_ioport_request_len)) { #line 57 tmp = 1; } else { #line 57 tmp = 0; } } else { #line 57 tmp = 0; } #line 57 __CPROVER_assert(tmp, "I/O port is requested"); #line 58 return; } } #line 60 "/usr/local/ddv/models/con2/src/linux/kernel/resource.c" __inline unsigned int inl(unsigned int port ) { int tmp ; unsigned int tmp___0 ; { #line 63 if (port >= (unsigned int )ddv_ioport_request_start) { #line 63 if (port < (unsigned int )(ddv_ioport_request_start + ddv_ioport_request_len)) { #line 63 tmp = 1; } else { #line 63 tmp = 0; } } else { #line 63 tmp = 0; } #line 63 __CPROVER_assert(tmp, "I/O port is requested"); #line 65 tmp___0 = nondet_unsigned(); #line 65 return (tmp___0); } } #line 68 "/usr/local/ddv/models/con2/src/linux/kernel/resource.c" __inline void outl(unsigned int doubleword , unsigned int port ) { int tmp ; { #line 71 if (port >= (unsigned int )ddv_ioport_request_start) { #line 71 if (port < (unsigned int )(ddv_ioport_request_start + ddv_ioport_request_len)) { #line 71 tmp = 1; } else { #line 71 tmp = 0; } } else { #line 71 tmp = 0; } #line 71 __CPROVER_assert(tmp, "I/O port is requested"); #line 72 return; } } #line 74 "/usr/local/ddv/models/con2/src/linux/kernel/resource.c" __inline unsigned char inb_p(unsigned int port ) { int tmp ; unsigned char tmp___0 ; { #line 77 if (port >= (unsigned int )ddv_ioport_request_start) { #line 77 if (port < (unsigned int )(ddv_ioport_request_start + ddv_ioport_request_len)) { #line 77 tmp = 1; } else { #line 77 tmp = 0; } } else { #line 77 tmp = 0; } #line 77 __CPROVER_assert(tmp, "I/O port is requested"); #line 79 tmp___0 = nondet_uchar(); #line 79 return (tmp___0); } } #line 82 "/usr/local/ddv/models/con2/src/linux/kernel/resource.c" __inline void outb_p(unsigned char byte , unsigned int port ) { int tmp ; { #line 85 if (port >= (unsigned int )ddv_ioport_request_start) { #line 85 if (port < (unsigned int )(ddv_ioport_request_start + ddv_ioport_request_len)) { #line 85 tmp = 1; } else { #line 85 tmp = 0; } } else { #line 85 tmp = 0; } #line 85 __CPROVER_assert(tmp, "I/O port is requested"); #line 86 return; } } #line 1 "sched.o" #pragma merger("0","/tmp/cil-HAF20JpW.i","") #line 18 "/usr/local/ddv/models/con2/include/ddverify/satabs.h" extern long nondet_long() ; #line 45 "/usr/local/ddv/models/con2/include/linux/sched.h" long schedule_timeout(long timeout ) ; #line 8 "/usr/local/ddv/models/con2/src/linux/kernel/sched.c" void schedule(void) { { #line 10 assert_context_process(); #line 11 return; } } #line 13 "/usr/local/ddv/models/con2/src/linux/kernel/sched.c" long schedule_timeout(long timeout ) { long tmp ; { #line 15 assert_context_process(); #line 17 tmp = nondet_long(); #line 17 return (tmp); } } #line 1 "semaphore.o" #pragma merger("0","/tmp/cil-5eb7QHdw.i","") #line 23 "/usr/local/ddv/models/con2/include/asm/semaphore.h" __inline void sema_init(struct semaphore *sem , int val ) ; #line 25 __inline void init_MUTEX(struct semaphore *sem ) ; #line 27 __inline void init_MUTEX_LOCKED(struct semaphore *sem ) ; #line 29 __inline void down(struct semaphore *sem ) ; #line 6 "/usr/local/ddv/models/con2/src/linux/kernel/semaphore.c" __inline void sema_init(struct semaphore *sem , int val ) { { #line 9 __CPROVER_atomic_begin(); #line 10 sem->init = 1; #line 11 sem->locked = 0; #line 12 __CPROVER_atomic_end(); #line 13 return; } } #line 15 "/usr/local/ddv/models/con2/src/linux/kernel/semaphore.c" __inline void init_MUTEX(struct semaphore *sem ) { { #line 18 __CPROVER_atomic_begin(); #line 19 sem->init = 1; #line 20 sem->locked = 0; #line 21 __CPROVER_atomic_end(); #line 22 return; } } #line 24 "/usr/local/ddv/models/con2/src/linux/kernel/semaphore.c" __inline void init_MUTEX_LOCKED(struct semaphore *sem ) { { #line 27 __CPROVER_atomic_begin(); #line 28 sem->init = 1; #line 29 sem->locked = 1; #line 30 __CPROVER_atomic_end(); #line 31 return; } } #line 33 "/usr/local/ddv/models/con2/src/linux/kernel/semaphore.c" __inline void down(struct semaphore *sem ) { { #line 44 while (1) { #line 46 __CPROVER_atomic_begin(); #line 47 if (sem->locked == 0) { #line 49 sem->locked = 1; #line 50 __CPROVER_atomic_end(); #line 51 return; } #line 53 __CPROVER_atomic_end(); } } } #line 58 "/usr/local/ddv/models/con2/src/linux/kernel/semaphore.c" int down_interruptible(struct semaphore *sem ) { int tmp ; { #line 69 while (1) { #line 71 __CPROVER_atomic_begin(); #line 72 if (sem->locked == 0) { #line 74 sem->locked = 1; #line 75 __CPROVER_atomic_end(); #line 76 return (0); } #line 78 tmp = nondet_int(); #line 78 if (tmp) { #line 79 __CPROVER_atomic_end(); #line 80 return (-1); } #line 83 __CPROVER_atomic_end(); } } } #line 88 "/usr/local/ddv/models/con2/src/linux/kernel/semaphore.c" int down_trylock(struct semaphore *sem ) { { #line 91 __CPROVER_atomic_begin(); #line 97 if (sem->locked == 0) { #line 98 sem->locked = 1; #line 99 __CPROVER_atomic_end(); #line 100 return (-1); } #line 102 __CPROVER_atomic_end(); #line 103 return (0); } } #line 106 "/usr/local/ddv/models/con2/src/linux/kernel/semaphore.c" void up(struct semaphore *sem ) { { #line 109 __CPROVER_atomic_begin(); #line 110 assert_context_process(); #line 114 sem->locked = 0; #line 115 __CPROVER_atomic_end(); #line 116 return; } } #line 1 "slab.o" #pragma merger("0","/tmp/cil-VoE7MPwK.i","") #line 10 "/usr/local/ddv/models/con2/include/linux/slab.h" void *kmalloc(size_t size , gfp_t flags ) ; #line 12 void *kzalloc(size_t size , gfp_t flags ) ; #line 6 "/usr/local/ddv/models/con2/src/linux/mm/slab.c" void *kmalloc(size_t size , gfp_t flags ) { void *tmp ; { #line 8 if (flags & 16U) { #line 9 assert_context_process(); } #line 12 tmp = malloc(size); #line 12 return (tmp); } } #line 15 "/usr/local/ddv/models/con2/src/linux/mm/slab.c" void *kzalloc(size_t size , gfp_t flags ) { void *tmp ; { #line 17 if (flags & 16U) { #line 18 assert_context_process(); } #line 21 tmp = malloc(size); #line 21 return (tmp); } } #line 1 "softirq.o" #pragma merger("0","/tmp/cil-xUyerbuy.i","") #line 50 "/usr/local/ddv/models/con2/include/linux/interrupt.h" __inline void tasklet_schedule(struct tasklet_struct *t ) ; #line 65 __inline void tasklet_init(struct tasklet_struct *t , void (*func)(unsigned long ) , unsigned long data ) ; #line 4 "/usr/local/ddv/models/con2/src/linux/kernel/softirq.c" __inline void tasklet_schedule(struct tasklet_struct *t ) { int i ; int next_free ; { #line 7 next_free = -1; #line 13 i = 0; #line 13 while (i < 10) { #line 14 if ((unsigned long )tasklet_registered[i].tasklet == (unsigned long )((void *)0)) { #line 15 next_free = i; } #line 17 if ((unsigned long )tasklet_registered[i].tasklet == (unsigned long )t) { #line 17 if ((int )tasklet_registered[i].is_running == 0) { #line 19 return; } } #line 13 i ++; } #line 28 tasklet_registered[next_free].tasklet = t; #line 29 tasklet_registered[next_free].is_running = (unsigned short)0; #line 30 return; } } #line 32 "/usr/local/ddv/models/con2/src/linux/kernel/softirq.c" __inline void tasklet_init(struct tasklet_struct *t , void (*func)(unsigned long ) , unsigned long data ) { { #line 36 t->count = 0; #line 37 t->init = 0; #line 38 t->func = func; #line 39 t->data = data; #line 40 return; } } #line 1 "spinlock.o" #pragma merger("0","/tmp/cil-t4HK8DhF.i","") #line 10 "/usr/local/ddv/models/con2/include/linux/spinlock.h" __inline void spin_lock(spinlock_t *lock ) ; #line 11 __inline void spin_lock_irqsave(spinlock_t *lock , unsigned long flags ) ; #line 13 __inline void spin_lock_bh(spinlock_t *lock ) ; #line 15 __inline void spin_unlock(spinlock_t *lock ) ; #line 16 __inline void spin_unlock_irqrestore(spinlock_t *lock , unsigned long flags ) ; #line 18 __inline void spin_unlock_bh(spinlock_t *lock ) ; #line 4 "/usr/local/ddv/models/con2/src/linux/kernel/spinlock.c" void spin_lock_init(spinlock_t *lock ) { { #line 6 lock->init = 1; #line 7 lock->locked = 0; #line 8 return; } } #line 10 "/usr/local/ddv/models/con2/src/linux/kernel/spinlock.c" __inline void spin_lock(spinlock_t *lock ) { { #line 20 while (1) { #line 22 __CPROVER_atomic_begin(); #line 23 if (lock->locked == 0) { #line 25 lock->locked = 1; #line 26 __CPROVER_atomic_end(); #line 27 return; } #line 29 __CPROVER_atomic_end(); } } } #line 34 "/usr/local/ddv/models/con2/src/linux/kernel/spinlock.c" __inline void spin_lock_irqsave(spinlock_t *lock , unsigned long flags ) { { #line 44 while (1) { #line 46 __CPROVER_atomic_begin(); #line 47 if (lock->locked == 0) { #line 49 lock->locked = 1; #line 50 __CPROVER_atomic_end(); #line 51 return; } #line 53 __CPROVER_atomic_end(); } } } #line 58 "/usr/local/ddv/models/con2/src/linux/kernel/spinlock.c" void spin_lock_irq(spinlock_t *lock ) { { #line 68 while (1) { #line 70 __CPROVER_atomic_begin(); #line 71 if (lock->locked == 0) { #line 73 lock->locked = 1; #line 74 __CPROVER_atomic_end(); #line 75 return; } #line 77 __CPROVER_atomic_end(); } } } #line 106 "/usr/local/ddv/models/con2/src/linux/kernel/spinlock.c" __inline void spin_unlock(spinlock_t *lock ) { { #line 109 __CPROVER_atomic_begin(); #line 113 lock->locked = 0; #line 114 __CPROVER_atomic_end(); #line 115 return; } } #line 117 "/usr/local/ddv/models/con2/src/linux/kernel/spinlock.c" __inline void spin_unlock_irqrestore(spinlock_t *lock , unsigned long flags ) { { #line 120 __CPROVER_atomic_begin(); #line 124 lock->locked = 0; #line 125 __CPROVER_atomic_end(); #line 126 return; } } #line 128 "/usr/local/ddv/models/con2/src/linux/kernel/spinlock.c" void spin_unlock_irq(spinlock_t *lock ) { { #line 131 __CPROVER_atomic_begin(); #line 135 lock->locked = 0; #line 136 __CPROVER_atomic_end(); #line 137 return; } } #line 1 "tasklet.o" #pragma merger("0","/tmp/cil-CirswWBL.i","") #line 3 "/usr/local/ddv/models/con2/src/ddverify/tasklet.c" void call_tasklet_functions(void) { unsigned int i ; { #line 6 __CPROVER_assume(i < 10U); #line 8 if ((unsigned long )tasklet_registered[i].tasklet != (unsigned long )((void *)0)) { #line 8 if ((tasklet_registered[i].tasklet)->count == 0) { #line 10 tasklet_registered[i].is_running = (unsigned short)1; #line 11 (*((tasklet_registered[i].tasklet)->func))((tasklet_registered[i].tasklet)->data); #line 12 tasklet_registered[i].is_running = (unsigned short)0; #line 13 tasklet_registered[i].tasklet = (struct tasklet_struct *)((void *)0); } } #line 15 return; } } #line 1 "timer.o" #pragma merger("0","/tmp/cil-H4pRe0m2.i","") #line 27 "/usr/local/ddv/models/con2/include/linux/timer.h" __inline void add_timer_on(struct timer_list *timer , int cpu ) ; #line 30 __inline int mod_timer(struct timer_list *timer , unsigned long expires ) ; #line 4 "/usr/local/ddv/models/con2/src/linux/kernel/timer.c" void init_timer(struct timer_list *timer ) { { #line 6 if ((int )number_timer_registered < 5) { #line 7 timer->__ddv_active = (short)0; #line 8 timer->__ddv_init = (short)1; #line 9 timer_registered[number_timer_registered].timer = timer; #line 11 number_timer_registered = (short )((int )number_timer_registered + 1); } #line 13 return; } } #line 15 "/usr/local/ddv/models/con2/src/linux/kernel/timer.c" void add_timer(struct timer_list *timer ) { { #line 21 timer->__ddv_active = (short)1; #line 22 return; } } #line 24 "/usr/local/ddv/models/con2/src/linux/kernel/timer.c" __inline void add_timer_on(struct timer_list *timer , int cpu ) { { #line 27 add_timer(timer); #line 28 return; } } #line 30 "/usr/local/ddv/models/con2/src/linux/kernel/timer.c" int del_timer(struct timer_list *timer ) { { #line 32 timer->__ddv_active = (short)0; #line 33 return (0); } } #line 35 "/usr/local/ddv/models/con2/src/linux/kernel/timer.c" __inline int mod_timer(struct timer_list *timer , unsigned long expires ) { { #line 41 timer->expires = expires; #line 42 timer->__ddv_active = (short)1; #line 43 return (0); } } #line 1 "tty_io.o" #pragma merger("0","/tmp/cil-_Yc9pxXh.i","") #line 97 "/usr/local/ddv/models/con2/include/linux/tty_driver.h" struct tty_driver *alloc_tty_driver(int lines ) ; #line 101 void tty_set_operations(struct tty_driver *driver , struct tty_operations const *op ) ; #line 13 "/usr/local/ddv/models/con2/include/ddverify/tty.h" struct ddv_tty_driver global_tty_driver ; #line 4 "/usr/local/ddv/models/con2/src/linux/drivers/char/tty_io.c" struct tty_driver *alloc_tty_driver(int lines ) { { #line 6 if (! global_tty_driver.allocated) { #line 7 global_tty_driver.driver.magic = 21506; #line 8 global_tty_driver.driver.num = lines; } else { #line 10 return ((struct tty_driver *)((void *)0)); } #line 12 return ((struct tty_driver *)0); } } #line 14 "/usr/local/ddv/models/con2/src/linux/drivers/char/tty_io.c" void tty_set_operations(struct tty_driver *driver , struct tty_operations const *op ) { { #line 17 driver->open = (int (*)(struct tty_struct *tty , struct file *filp ))op->open; #line 18 driver->close = (void (*)(struct tty_struct *tty , struct file *filp ))op->close; #line 19 driver->write = (int (*)(struct tty_struct *tty , unsigned char const *buf , int count ))op->write; #line 20 driver->put_char = (void (*)(struct tty_struct *tty , unsigned char ch ))op->put_char; #line 21 driver->flush_chars = (void (*)(struct tty_struct *tty ))op->flush_chars; #line 22 driver->write_room = (int (*)(struct tty_struct *tty ))op->write_room; #line 23 driver->chars_in_buffer = (int (*)(struct tty_struct *tty ))op->chars_in_buffer; #line 24 driver->ioctl = (int (*)(struct tty_struct *tty , struct file *file , unsigned int cmd , unsigned long arg ))op->ioctl; #line 25 driver->set_termios = (void (*)(struct tty_struct *tty , struct termios *old ))op->set_termios; #line 26 driver->throttle = (void (*)(struct tty_struct *tty ))op->throttle; #line 27 driver->unthrottle = (void (*)(struct tty_struct *tty ))op->unthrottle; #line 28 driver->stop = (void (*)(struct tty_struct *tty ))op->stop; #line 29 driver->start = (void (*)(struct tty_struct *tty ))op->start; #line 30 driver->hangup = (void (*)(struct tty_struct *tty ))op->hangup; #line 31 driver->break_ctl = (void (*)(struct tty_struct *tty , int state ))op->break_ctl; #line 32 driver->flush_buffer = (void (*)(struct tty_struct *tty ))op->flush_buffer; #line 33 driver->set_ldisc = (void (*)(struct tty_struct *tty ))op->set_ldisc; #line 34 driver->wait_until_sent = (void (*)(struct tty_struct *tty , int timeout ))op->wait_until_sent; #line 35 driver->send_xchar = (void (*)(struct tty_struct *tty , char ch ))op->send_xchar; #line 36 driver->read_proc = (int (*)(char *page , char **start , off_t off , int count , int *eof , void *data ))op->read_proc; #line 37 driver->write_proc = (int (*)(struct file *file , char const *buffer , unsigned long count , void *data ))op->write_proc; #line 38 driver->tiocmget = (int (*)(struct tty_struct *tty , struct file *file ))op->tiocmget; #line 39 driver->tiocmset = (int (*)(struct tty_struct *tty , struct file *file , unsigned int set , unsigned int clear ))op->tiocmset; #line 40 return; } } #line 1 "usercopy.o" #pragma merger("0","/tmp/cil-PtMzrsBA.i","") #line 41 "/usr/local/ddv/models/con2/include/asm/uaccess.h" __inline int __get_user(int size , void *ptr ) ; #line 43 __inline int get_user(int size , void *ptr ) ; #line 46 __inline int __put_user(int size , void *ptr ) ; #line 48 __inline int put_user(int size , void *ptr ) ; #line 5 "/usr/local/ddv/models/con2/src/linux/arch/i386/lib/usercopy.c" __inline int __get_user(int size , void *ptr ) { int tmp ; { #line 8 assert_context_process(); #line 10 tmp = nondet_int(); #line 10 return (tmp); } } #line 37 "/usr/local/ddv/models/con2/src/linux/arch/i386/lib/usercopy.c" unsigned long copy_to_user(void *to , void const *from , unsigned long n ) { unsigned long tmp ; { #line 40 assert_context_process(); #line 42 tmp = nondet_ulong(); #line 42 return (tmp); } } #line 45 "/usr/local/ddv/models/con2/src/linux/arch/i386/lib/usercopy.c" unsigned long copy_from_user(void *to , void *from , unsigned long n ) { unsigned long tmp ; { #line 48 assert_context_process(); #line 50 tmp = nondet_ulong(); #line 50 return (tmp); } } #line 1 "vmalloc.o" #pragma merger("0","/tmp/cil-yOpNggBm.i","") #line 6 "/usr/local/ddv/models/con2/include/linux/vmalloc.h" void *vmalloc(unsigned long size ) ; #line 6 "/usr/local/ddv/models/con2/src/linux/mm/vmalloc.c" void *vmalloc(unsigned long size ) { void *tmp ; { #line 8 tmp = malloc((size_t )size); #line 8 return (tmp); } } #line 1 "wait.o" #pragma merger("0","/tmp/cil-RsxTaMGP.i","") #line 64 "/usr/local/ddv/models/con2/include/linux/wait.h" __inline void init_waitqueue_head(wait_queue_head_t *q ) ; #line 71 __inline void wake_up(wait_queue_head_t *q ) ; #line 73 __inline void wake_up_all(wait_queue_head_t *q ) ; #line 88 __inline void sleep_on(wait_queue_head_t *q ) ; #line 90 __inline void interruptible_sleep_on(wait_queue_head_t *q ) ; #line 3 "/usr/local/ddv/models/con2/src/linux/kernel/wait.c" __inline void init_waitqueue_head(wait_queue_head_t *q ) { { #line 5 q->init = 1; #line 6 return; } } #line 8 "/usr/local/ddv/models/con2/src/linux/kernel/wait.c" __inline void wake_up(wait_queue_head_t *q ) { { #line 14 return; } } #line 24 "/usr/local/ddv/models/con2/src/linux/kernel/wait.c" void wake_up_interruptible(wait_queue_head_t *q ) { { #line 30 return; } } #line 1 "workqueue.o" #pragma merger("0","/tmp/cil-nmRdD6dK.i","") #line 46 "/usr/local/ddv/models/con2/include/linux/workqueue.h" __inline int schedule_work(struct work_struct *work ) ; #line 5 "/usr/local/ddv/models/con2/src/linux/kernel/workqueue.c" __inline int schedule_work(struct work_struct *work ) { int i ; { #line 14 i = 0; #line 14 while (i < 10) { #line 15 if ((unsigned long )shared_workqueue[i] == (unsigned long )work) { #line 16 return (0); } #line 19 if ((unsigned long )shared_workqueue[i] == (unsigned long )((void *)0)) { #line 20 shared_workqueue[i] = work; #line 22 return (1); } #line 14 i ++; } #line 27 return (-1); } } #line 30 "/usr/local/ddv/models/con2/src/linux/kernel/workqueue.c" void call_shared_workqueue_functions(void) { unsigned short i ; unsigned short tmp ; { #line 32 tmp = nondet_ushort(); #line 32 i = tmp; #line 33 __CPROVER_assume((int )i < 10); #line 35 if ((unsigned long )shared_workqueue[i] != (unsigned long )((void *)0)) { #line 36 (*((shared_workqueue[i])->func))((shared_workqueue[i])->data); #line 37 shared_workqueue[i] = (struct work_struct *)((void *)0); } #line 39 return; } }
the_stack_data/504575.c
/* Taking INPUT in Arrays */ // ================================================= void main() { // Taking size int len; printf("Enter size of array : "); scanf("%d", &len); // Taking array int arr[50]; printf("Enter elements of array : "); for (int i = 0; i < len; i++) scanf("%d", &arr[i]); } // ================================================ /* Code by Abel Roy */
the_stack_data/182952996.c
int f(int n) { int i = 0; int j = 0; while (i < n) { j = j + 2; i++; } return j; }
the_stack_data/1253561.c
/* * Copyright (c) 2004 Topspin Communications. All rights reserved. * * This software is available to you under a choice of one of two * licenses. You may choose to be licensed under the terms of the GNU * General Public License (GPL) Version 2, available from the file * COPYING in the main directory of this source tree, or the * OpenIB.org BSD license below: * * 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. * * 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. */ #if HAVE_CONFIG_H # include <config.h> #endif /* HAVE_CONFIG_H */ #include <stdio.h> #include <endian.h> #include <byteswap.h> #include <infiniband/verbs.h> #include <infiniband/arch.h> int main(int argc, char *argv[]) { struct ibv_device **dev_list; int num_devices, i; dev_list = ibv_get_device_list(&num_devices); if (!dev_list) { perror("Failed to get IB devices list"); return 1; } printf(" %-16s\t node GUID\n", "device"); printf(" %-16s\t----------------\n", "------"); for (i = 0; i < num_devices; ++i) { printf(" %-16s\t%016llx\n", ibv_get_device_name(dev_list[i]), (unsigned long long) ntohll(ibv_get_device_guid(dev_list[i]))); } ibv_free_device_list(dev_list); return 0; }
the_stack_data/161079564.c
#include <stdio.h> int getPentagonalNumber(int n){ return (n*(3*n-1))/2; } int main(){ for(int i = 1;i<=100;i++){ printf("%7d ", getPentagonalNumber(i)); if(!(i%10))printf("\n"); } }
the_stack_data/198580865.c
#include <stdio.h> #include <stdlib.h> int main(void) { int t, n, i, j, sum=0; int *array; scanf("%d", &t); if(t < 0 || t >= 100) return 0; for(i=0; i<t; i++) { scanf("%d", &n); array = malloc(sizeof(int) * n); for(j=0; j<n; j++) { scanf("%d", &array[j]); sum+=array[j]; } printf("%d\n", sum); sum = 0; } return 0; }
the_stack_data/15763102.c
/** @file * Copyright (c) 2019-2020, Arm Limited or its affiliates. All rights reserved. * SPDX-License-Identifier : Apache-2.0 * * 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. **/ #ifdef SENSOR_PROTOCOL #include "val_interface.h" #include "val_sensor.h" static SENSOR_INFO_s g_sensor_info_table; /** @brief This API is called from app layer to execute sensor domain tests @param none @return test execution result **/ uint32_t val_sensor_execute_tests(void) { uint32_t version = 0; val_memset((void *)&g_sensor_info_table, 0, sizeof(g_sensor_info_table)); if (val_agent_check_protocol_support(PROTOCOL_SENSOR)) { if (RUN_TEST(sensor_query_protocol_version(&version))) return VAL_STATUS_FAIL; RUN_TEST(sensor_query_protocol_attributes()); RUN_TEST(sensor_query_mandatory_command_support()); RUN_TEST(sensor_invalid_messageid_call()); RUN_TEST(sensor_trip_point_nfy_event_ctrl_check()); RUN_TEST(sensor_trip_point_nfy_invalid_id_check()); RUN_TEST(sensor_trip_point_config_invalid_param_check()); RUN_TEST(sensor_trip_point_config_invalid_id_check()); RUN_TEST(sensor_trip_point_config_check()); RUN_TEST(sensor_reading_get_invalid_flag_check()); RUN_TEST(sensor_reading_get_invalid_id_check()); RUN_TEST(sensor_reading_get_sync_mode()); RUN_TEST(sensor_reading_get_async_mode()); RUN_TEST(sensor_reading_get_async_mode_not_supported()); if (version == SENSOR_PROTOCOL_VERSION_1) RUN_TEST(sensor_query_description_get()); if (version == SENSOR_PROTOCOL_VERSION_2) { RUN_TEST(sensor_query_description_get_scmi_v3()); RUN_TEST(sensor_axis_description_check()); RUN_TEST(sensor_axis_desc_invalid_id_check()); RUN_TEST(sensor_supported_update_intervals_check()); RUN_TEST(sensor_update_interval_invalid_id_check()); RUN_TEST(sensor_read_configuration_check()); RUN_TEST(sensor_read_configuration_invalid_id_check()); RUN_TEST(sensor_set_configuration_check()); RUN_TEST(sensor_set_configuration_invalid_id_check()); RUN_TEST(sensor_request_sensor_notification_check()); RUN_TEST(sensor_request_notification_invalid_id_check()); } } else val_print(VAL_PRINT_ERR, "\n Calling agent have no access to SENSOR protocol"); return VAL_STATUS_PASS; } /** @brief This API is used to set sensor protocol info 1. Caller - Test Suite. 2. Prerequisite - Sensor protocol info table. @param param_identifier id of parameter which will be set @param param_value value of parameter @return none **/ void val_sensor_save_info(uint32_t param_identifier, uint32_t param_value) { switch (param_identifier) { case NUM_SENSORS: g_sensor_info_table.num_sensors = param_value; break; case SENSOR_STATS_ADDR_LOW: g_sensor_info_table.sensor_stats_addr_low = param_value; break; case SENSOR_STATS_ADDR_HIGH: g_sensor_info_table.sensor_stats_addr_high = param_value; break; case SENSOR_STATS_ADDR_LEN: g_sensor_info_table.sensor_stats_addr_len = param_value; break; default: val_print(VAL_PRINT_ERR, "\nUnidentified parameter %d", param_identifier); } } /** @brief This API is used to get sensor protocol info 1. Caller - Test Suite. 2. Prerequisite - Sensor protocol info table. @param param_identifier id of parameter which will be set @return param_value value of the parameter **/ uint32_t val_sensor_get_info(uint32_t param_identifier) { uint32_t param_value = 0; switch (param_identifier) { case NUM_SENSORS: param_value = g_sensor_info_table.num_sensors; break; case SENSOR_STATS_ADDR_LOW: param_value = g_sensor_info_table.sensor_stats_addr_low; break; case SENSOR_STATS_ADDR_HIGH: param_value = g_sensor_info_table.sensor_stats_addr_high; break; case SENSOR_STATS_ADDR_LEN: param_value = g_sensor_info_table.sensor_stats_addr_len; break; default: val_print(VAL_PRINT_ERR, "\nUnidentified parameter %d", param_identifier); } return param_value; } /** @brief This API is used to set sensor protocol info 1. Caller - Test Suite. 2. Prerequisite - Sensor protocol info table. @param param_identifier id of parameter which will be set @param sensor_id Sensor id @param param_value value of parameter @return none **/ void val_sensor_save_desc_info(uint32_t param_identifier, uint32_t sensor_id, uint32_t param_value) { switch (param_identifier) { case SENSOR_NUM_OF_TRIP_POINTS: g_sensor_info_table.desc_info[sensor_id].num_trip_points = param_value; break; case SENSOR_ASYNC_READ_SUPPORT: g_sensor_info_table.desc_info[sensor_id].async_read_support = param_value; break; default: val_print(VAL_PRINT_ERR, "\nUnidentified parameter %d", param_identifier); } } /** @brief This API is used to get sensor protocol info 1. Caller - Test Suite. 2. Prerequisite - Sensor protocol info table. @param param_identifier id of parameter which will be set @param sensor_id Sensor id @return param_value value of the parameter **/ uint32_t val_sensor_get_desc_info(uint32_t param_identifier, uint32_t sensor_id) { uint32_t param_value = 0; switch (param_identifier) { case SENSOR_NUM_OF_TRIP_POINTS: param_value = g_sensor_info_table.desc_info[sensor_id].num_trip_points; break; case SENSOR_ASYNC_READ_SUPPORT: param_value = g_sensor_info_table.desc_info[sensor_id].async_read_support; break; default: val_print(VAL_PRINT_ERR, "\nUnidentified parameter %d", param_identifier); } return param_value; } /** @brief This API is used for checking num of sensors @param none @return num of sensors **/ uint32_t val_sensor_get_expected_num_sensors(void) { return pal_sensor_get_expected_num_sensors(); } /** @brief This API is used for checking sensor statistics addr low @param none @return statistics addr low **/ uint32_t val_sensor_get_expected_stats_addr_low(void) { return pal_sensor_get_expected_stats_addr_low(); } /** @brief This API is used for checking sensor statistics addr high @param none @return statistics addr high **/ uint32_t val_sensor_get_expected_stats_addr_high(void) { return pal_sensor_get_expected_stats_addr_high(); } /** @brief This API is used for checking sensor statistics addr len @param none @return statistics addr len **/ uint32_t val_sensor_get_expected_stats_addr_len(void) { return pal_sensor_get_expected_stats_addr_len(); } /** @brief This API is used to set extended sensor protocol info 1. Caller - Test Suite. 2. Prerequisite - Sensor protocol info table. @param param_identifier id of parameter which will be set @param sensor_id Sensor id @param param_value value of parameter @return none **/ void val_sensor_ext_save_desc_info(uint32_t param_identifier, uint32_t sensor_id, uint32_t param_value) { switch (param_identifier) { case SENSOR_CONT_NOTIFY_UPDATE_SUPPORT: g_sensor_info_table.ext_desc_info[sensor_id].cont_update_notify_support = param_value; break; case SENSOR_TIMESTAMP_SUPPORT: g_sensor_info_table.ext_desc_info[sensor_id].timestamp_support = param_value; break; case SENSOR_NUM_OF_AXIS: g_sensor_info_table.ext_desc_info[sensor_id].num_axis = param_value; break; case SENSOR_AXIS_SUPPORT: g_sensor_info_table.ext_desc_info[sensor_id].axis_support = param_value; break; case SENSOR_STATE: g_sensor_info_table.ext_desc_info[sensor_id].sensor_state = param_value; break; default: val_print(VAL_PRINT_ERR, "\nUnidentified parameter %d", param_identifier); } } /** @brief This API is used to get extended sensor protocol info 1. Caller - Test Suite. 2. Prerequisite - Sensor protocol info table. @param param_identifier id of parameter which will be set @param sensor_id Sensor id @return param_value value of the parameter **/ uint32_t val_sensor_ext_get_desc_info(uint32_t param_identifier, uint32_t sensor_id) { uint32_t param_value = 0; switch (param_identifier) { case SENSOR_CONT_NOTIFY_UPDATE_SUPPORT: param_value = g_sensor_info_table.ext_desc_info[sensor_id].cont_update_notify_support; break; case SENSOR_TIMESTAMP_SUPPORT: param_value = g_sensor_info_table.ext_desc_info[sensor_id].timestamp_support; break; case SENSOR_NUM_OF_AXIS: param_value = g_sensor_info_table.ext_desc_info[sensor_id].num_axis; break; case SENSOR_AXIS_SUPPORT: param_value = g_sensor_info_table.ext_desc_info[sensor_id].axis_support; break; case SENSOR_STATE: param_value = g_sensor_info_table.ext_desc_info[sensor_id].sensor_state; break; default: val_print(VAL_PRINT_ERR, "\nUnidentified parameter %d", param_identifier); } return param_value; } /** @brief This API is used to get sensor state 1. Caller - Test Suite. @param update_interval Sensor update interval @param update_interval_exp Sensor update interval exponent @param round_up_down round up/down config @param timestamp_reporting Sensor timestamp reporting config @param sensor_state sensor state @return param_value sensor configuration **/ uint32_t val_sensor_set_config(uint32_t update_interval, uint32_t update_interval_exp, uint32_t round_up_down, uint32_t timestamp_reporting, uint32_t sensor_state) { uint32_t sensor_config = 0; sensor_config = sensor_config | (update_interval << 16); sensor_config = sensor_config | (update_interval_exp << 11); sensor_config = sensor_config | (round_up_down << 9); sensor_config = sensor_config | (timestamp_reporting << 1); sensor_config = sensor_config | (sensor_state); return sensor_config; } /** @brief This API is used to get notify enable config 1. Caller - Test Suite. @param enable config flag Enable config flag value @return enable config Enable config **/ uint32_t val_get_notify_enable_config(uint32_t notify_enable_flag) { uint32_t notify_enable_config = 0; notify_enable_config = notify_enable_config | notify_enable_flag; return notify_enable_config; } #endif
the_stack_data/50138208.c
extern const unsigned char ReachabilityVersionString[]; extern const double ReachabilityVersionNumber; const unsigned char ReachabilityVersionString[] __attribute__ ((used)) = "@(#)PROGRAM:Reachability PROJECT:Pods-1" "\n"; const double ReachabilityVersionNumber __attribute__ ((used)) = (double)1.;
the_stack_data/70449576.c
#include<stdio.h> #include<ctype.h> #include<string.h> int top=-1, stack[15]; void push(char x) { stack[++top] = x; } char pop() { return stack[top--]; } void postfixEvaluation(char postfix[]) { char ch; int a,b,i; for(i=0; postfix[i] != '\0'; i++) { ch = postfix[i]; if(isdigit(ch)) { push(ch-'0'); } else { b = pop(); a = pop(); switch(ch) { case '+': push(a+b); break; case '-': push(a-b); break; case '*': push(a*b); break; case '/': push(a/b); break; } } } printf("\n The postfix evaluation is : %d", stack[top]); } void main() { char infix[15],postfix[15]; printf("\n Enter the postfix expression : "); scanf("%s", postfix); postfixEvaluation(postfix); printf("\n"); }
the_stack_data/43059.c
/* SLK_make - a build-system Written in 2021 by Lukas Holzbeierlein (Captain4LK) email: captain4lk [at] tutanota [dot] com To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty. You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>. */ //External includes #include <stdio.h> #include <stdlib.h> #include <stdarg.h> #include <string.h> //------------------------------------- //Internal includes #include "error.h" //------------------------------------- //#defines //------------------------------------- //Typedefs //------------------------------------- //Variables int line_on = 0; char *file_on = 0; int mk_debug_on = 0; char *file_contents = 0; //------------------------------------- //Function prototypes //------------------------------------- //Function implementations void mk_error(char *format, ...) { if(file_on) fprintf(stderr, "%s:%d: ", file_on, line_on); va_list args; va_start(args, format); vfprintf(stderr, format, args); va_end(args); exit(1); } void mk_debug(char *format, ...) { if(mk_debug_on) { va_list args; va_start(args, format); vfprintf(stderr, format, args); va_end(args); } } //-------------------------------------
the_stack_data/165766632.c
#include <stdio.h> int main () { int x,y,z; x=30,y=5,z; for(x=10;x<=10;x=x+10) { if(x=10) printf("%d\n",z++ ); } return 0; }
the_stack_data/57949071.c
#define _POSIX_C_SOURCE 200809L #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <stdbool.h> #include <errno.h> #include <mqueue.h> void display_usage(void) { printf("usage: mqrecv [options]\n" "options:\n" " -n <name> Message Queue name\n" " -b Block for a message to receive\n"); exit(EXIT_FAILURE); } int main(int argc, char ** argv) { char * name = NULL; bool blocking = false; for (int c = 0; (c = getopt(argc, argv, "n:bh?")) != -1;) { switch (c) { case 'n': name = optarg; break; case 'b': blocking = true; break; case 'h': case '?': display_usage(); break; default: abort(); } } errno = 0; mqd_t queue; if (blocking) { queue = mq_open(name, O_RDONLY); } else { queue = mq_open(name, O_RDONLY | O_NONBLOCK); } if (queue == (mqd_t)-1) { if (errno == ENOENT) { fprintf(stderr, "No queue with that name exists.\n"); exit(EXIT_FAILURE); } else { perror("mq_open"); exit(EXIT_FAILURE); } } struct mq_attr attr; int r = mq_getattr(queue, &attr); if (r == -1) { perror("getattr"); return 1; } long buflen = attr.mq_msgsize + 1; char buf[buflen]; unsigned int msg_prio; errno = 0; ssize_t len = mq_receive(queue, buf, buflen, &msg_prio); if (len == -1) { if (errno == EAGAIN) { fprintf(stderr, "No message available.\n"); return 2; } else { perror("mq_receive"); return 1; } } printf("%d %s\n", msg_prio, buf); r = mq_close(queue); if (r == -1) { perror("mq_close"); return 1; } }
the_stack_data/879272.c
extern const unsigned char QBPwdModuleVersionString[]; extern const double QBPwdModuleVersionNumber; const unsigned char QBPwdModuleVersionString[] __attribute__ ((used)) = "@(#)PROGRAM:QBPwdModule PROJECT:Pods-1" "\n"; const double QBPwdModuleVersionNumber __attribute__ ((used)) = (double)1.;
the_stack_data/231392974.c
#define _GNU_SOURCE #include <stdio.h> #include <stdlib.h> #include <errno.h> #include <syscall.h> #include <stdint.h> #include <time.h> #include <unistd.h> #include <sys/types.h> #include <sched.h> int dtp_get_cpu() { int i; pid_t tid; cpu_set_t cpu_set; CPU_ZERO(&cpu_set); tid = syscall(SYS_gettid); if (sched_getaffinity(tid, sizeof(cpu_set), &cpu_set) < 0) { fprintf(stderr, "get_cpu error\n"); exit(EXIT_FAILURE); } for ( i = 0 ; i < CPU_SETSIZE ; i ++ ) { if (CPU_ISSET(i, &cpu_set)) { fprintf(stderr, "CPU running on %d\n", i); break; } } return i; } int dtp_set_cpu(int cpun) { pid_t tid; cpu_set_t cpu_set; CPU_ZERO(&cpu_set); CPU_SET(cpun, &cpu_set); tid = syscall(SYS_gettid); if (sched_setaffinity(tid, sizeof(cpu_set), &cpu_set) < 0) { fprintf(stderr, "set_cpu error\n"); exit(EXIT_FAILURE); } return 0; } int main(int argc, char **argv) { if (argc != 3) { fprintf(stderr, "usage: %s <cpu> <memory>\n", argv[0]); exit(EXIT_FAILURE); } int i, j; int cpu = atoi(argv[1]); srand(time(NULL)); uint64_t memory = atoi(argv[2]); // given in MB memory = memory * 1024 * 1024 / 4; int * x = calloc(sizeof(int) , memory); dtp_set_cpu(cpu); dtp_get_cpu(); while(1) { // int addr = rand() % G; // x[i] = rand(); for ( i = 0 ; i < memory ; i ++ ) { if (i != 0) x[i ] = rand(); else x[i] = rand() * x[i-1]; } } return 0; }
the_stack_data/9511565.c
#include <stdio.h> #include <string.h> #define SIZE_NAME 10 #define CPF 12 typedef struct person { char name[SIZE_NAME]; char cpf[CPF]; int age; } PERSON; int insert_person(char name[], char cpf[], int age, FILE* file) { PERSON person; strcpy(person.name, name); strcpy(person.cpf, cpf); person.age = age; if(fwrite(&person, sizeof(PERSON), 1, file) != 1) { return -1; } return 0; } int find_person(char cpf[], PERSON* person, FILE* file) { int position; rewind(file); while(1) { position = ftell(file); fread(person, sizeof(PERSON), 1, file); if(feof(file)) { break; } if(!strcmp(person->cpf, cpf)) { return position; } } return -1; } int main() { FILE* people; PERSON person; int position; char cpf[CPF]; int result; people = fopen("list_of_people.bin", "wb+"); if(people == NULL) { printf("Error.\n"); return 0; } if(insert_person("person1", "12345678901", 20, people) == -1) { printf("Error.\n"); return -1; } if(insert_person("person2", "12345678902", 25, people) == -1) { printf("Error.\n"); return -1; } if(insert_person("person3", "12345678903", 30, people) == -1) { printf("Error.\n"); return -1; } printf("Enter cpf: \n"); scanf("%s", cpf); printf("[%s]\n", cpf); position = find_person(cpf, &person, people); if(position == -1) { printf("Not found.\n"); } else { printf("Person found:\nposition: %d\tname: %s\tcpf: %s\tage: %d\n", position, person.name, person.cpf, person.age); } fclose(people); return 0; }
the_stack_data/84259.c
#define NULL ((void*)0) typedef unsigned long size_t; // Customize by platform. typedef long intptr_t; typedef unsigned long uintptr_t; typedef long scalar_t__; // Either arithmetic or pointer type. /* By default, we understand bool (as a convenience). */ typedef int bool; #define false 0 #define true 1 /* Forward declarations */ /* Type definitions */ typedef int /*<<< orphan*/ u32 ; struct sk_buff {int dummy; } ; struct nlmsghdr {int dummy; } ; struct fib_rules_ops {scalar_t__ (* fill ) (struct fib_rule*,struct sk_buff*,struct fib_rule_hdr*) ;int /*<<< orphan*/ family; } ; struct fib_rule_hdr {int table; scalar_t__ action; int /*<<< orphan*/ flags; scalar_t__ res2; scalar_t__ res1; int /*<<< orphan*/ family; } ; struct fib_rule {int table; int suppress_prefixlen; scalar_t__ action; int iifindex; int oifindex; int pref; int mark; int mark_mask; int target; int suppress_ifgroup; scalar_t__ ip_proto; int /*<<< orphan*/ dport_range; int /*<<< orphan*/ sport_range; int /*<<< orphan*/ uid_range; scalar_t__ l3mdev; scalar_t__ tun_id; scalar_t__* oifname; scalar_t__* iifname; int /*<<< orphan*/ ctarget; scalar_t__ proto; int /*<<< orphan*/ flags; } ; /* Variables and functions */ int EMSGSIZE ; int /*<<< orphan*/ FIB_RULE_IIF_DETACHED ; int /*<<< orphan*/ FIB_RULE_OIF_DETACHED ; int /*<<< orphan*/ FIB_RULE_UNRESOLVED ; int /*<<< orphan*/ FRA_DPORT_RANGE ; int /*<<< orphan*/ FRA_FWMARK ; int /*<<< orphan*/ FRA_FWMASK ; int /*<<< orphan*/ FRA_GOTO ; int /*<<< orphan*/ FRA_IIFNAME ; int /*<<< orphan*/ FRA_IP_PROTO ; int /*<<< orphan*/ FRA_L3MDEV ; int /*<<< orphan*/ FRA_OIFNAME ; int /*<<< orphan*/ FRA_PAD ; int /*<<< orphan*/ FRA_PRIORITY ; int /*<<< orphan*/ FRA_PROTOCOL ; int /*<<< orphan*/ FRA_SPORT_RANGE ; int /*<<< orphan*/ FRA_SUPPRESS_IFGROUP ; int /*<<< orphan*/ FRA_SUPPRESS_PREFIXLEN ; int /*<<< orphan*/ FRA_TABLE ; int /*<<< orphan*/ FRA_TUN_ID ; scalar_t__ FR_ACT_GOTO ; scalar_t__ fib_rule_port_range_set (int /*<<< orphan*/ *) ; scalar_t__ nla_put_be64 (struct sk_buff*,int /*<<< orphan*/ ,scalar_t__,int /*<<< orphan*/ ) ; scalar_t__ nla_put_port_range (struct sk_buff*,int /*<<< orphan*/ ,int /*<<< orphan*/ *) ; scalar_t__ nla_put_string (struct sk_buff*,int /*<<< orphan*/ ,scalar_t__*) ; scalar_t__ nla_put_u32 (struct sk_buff*,int /*<<< orphan*/ ,int) ; scalar_t__ nla_put_u8 (struct sk_buff*,int /*<<< orphan*/ ,scalar_t__) ; scalar_t__ nla_put_uid_range (struct sk_buff*,int /*<<< orphan*/ *) ; int /*<<< orphan*/ nlmsg_cancel (struct sk_buff*,struct nlmsghdr*) ; struct fib_rule_hdr* nlmsg_data (struct nlmsghdr*) ; int /*<<< orphan*/ nlmsg_end (struct sk_buff*,struct nlmsghdr*) ; struct nlmsghdr* nlmsg_put (struct sk_buff*,int /*<<< orphan*/ ,int /*<<< orphan*/ ,int,int,int) ; int /*<<< orphan*/ * rcu_access_pointer (int /*<<< orphan*/ ) ; scalar_t__ stub1 (struct fib_rule*,struct sk_buff*,struct fib_rule_hdr*) ; scalar_t__ uid_range_set (int /*<<< orphan*/ *) ; __attribute__((used)) static int fib_nl_fill_rule(struct sk_buff *skb, struct fib_rule *rule, u32 pid, u32 seq, int type, int flags, struct fib_rules_ops *ops) { struct nlmsghdr *nlh; struct fib_rule_hdr *frh; nlh = nlmsg_put(skb, pid, seq, type, sizeof(*frh), flags); if (nlh == NULL) return -EMSGSIZE; frh = nlmsg_data(nlh); frh->family = ops->family; frh->table = rule->table; if (nla_put_u32(skb, FRA_TABLE, rule->table)) goto nla_put_failure; if (nla_put_u32(skb, FRA_SUPPRESS_PREFIXLEN, rule->suppress_prefixlen)) goto nla_put_failure; frh->res1 = 0; frh->res2 = 0; frh->action = rule->action; frh->flags = rule->flags; if (nla_put_u8(skb, FRA_PROTOCOL, rule->proto)) goto nla_put_failure; if (rule->action == FR_ACT_GOTO && rcu_access_pointer(rule->ctarget) == NULL) frh->flags |= FIB_RULE_UNRESOLVED; if (rule->iifname[0]) { if (nla_put_string(skb, FRA_IIFNAME, rule->iifname)) goto nla_put_failure; if (rule->iifindex == -1) frh->flags |= FIB_RULE_IIF_DETACHED; } if (rule->oifname[0]) { if (nla_put_string(skb, FRA_OIFNAME, rule->oifname)) goto nla_put_failure; if (rule->oifindex == -1) frh->flags |= FIB_RULE_OIF_DETACHED; } if ((rule->pref && nla_put_u32(skb, FRA_PRIORITY, rule->pref)) || (rule->mark && nla_put_u32(skb, FRA_FWMARK, rule->mark)) || ((rule->mark_mask || rule->mark) && nla_put_u32(skb, FRA_FWMASK, rule->mark_mask)) || (rule->target && nla_put_u32(skb, FRA_GOTO, rule->target)) || (rule->tun_id && nla_put_be64(skb, FRA_TUN_ID, rule->tun_id, FRA_PAD)) || (rule->l3mdev && nla_put_u8(skb, FRA_L3MDEV, rule->l3mdev)) || (uid_range_set(&rule->uid_range) && nla_put_uid_range(skb, &rule->uid_range)) || (fib_rule_port_range_set(&rule->sport_range) && nla_put_port_range(skb, FRA_SPORT_RANGE, &rule->sport_range)) || (fib_rule_port_range_set(&rule->dport_range) && nla_put_port_range(skb, FRA_DPORT_RANGE, &rule->dport_range)) || (rule->ip_proto && nla_put_u8(skb, FRA_IP_PROTO, rule->ip_proto))) goto nla_put_failure; if (rule->suppress_ifgroup != -1) { if (nla_put_u32(skb, FRA_SUPPRESS_IFGROUP, rule->suppress_ifgroup)) goto nla_put_failure; } if (ops->fill(rule, skb, frh) < 0) goto nla_put_failure; nlmsg_end(skb, nlh); return 0; nla_put_failure: nlmsg_cancel(skb, nlh); return -EMSGSIZE; }
the_stack_data/65497.c
/* 题目内容: 请在上一题的基础上,采用递归的方法,计算含多个运算符的四则运算表达式字符串的值(无括号,但要考虑优先级) 输入格式: 多个运算符的四则运算表达式字符串 输出格式: 运算结果 输入样例: 3*2+3 输出样例: 9 */ #include <stdio.h> int calc(int*,char*,int); int main(){ int i,j,k,uuzi[100]; char srui[100]; for(i=0;;i++){ scanf("%d",&uuzi[i]); scanf("%c",&srui[i]); if(srui[i]=='\n') break; } for(j=0;srui[j]!='\n';j++){ if(srui[j]=='*'||srui[j]=='/'){ if(srui[j]=='*'){ uuzi[j]*=uuzi[j+1]; for(k=j;srui[k]!='\n';k++){ uuzi[k+1]=uuzi[k+2]; srui[k]=srui[k+1]; } }else if(srui[j]=='/'){ uuzi[j]/=uuzi[j+1]; for(k=j;srui[k]!='\n';k++){ uuzi[k+1]=uuzi[k+2]; srui[k]=srui[k+1]; } } j--;i--; } } printf("%d",calc(uuzi,srui,i)); } int calc(int uuzi[],char srui[],int j){ --j; if(j==-1) return uuzi[j+1]; else{ switch(srui[j]){ case '+': return calc(uuzi,srui,j)+uuzi[j+1]; break; case '-': return calc(uuzi,srui,j)-uuzi[j+1]; break; } } }
the_stack_data/4012.c
#include <stdio.h> #include <stdlib.h> #include <math.h> int NReps; int printLevel; int N; int* v; int *vQSort; int *vNew; void compareVectors(int * a, int * b) { // DO NOT MODIFY int i; for(i = 0; i < N; i++) { if(a[i]!=b[i]) { printf("Sorted incorrectly\n"); return; } } printf("Sorted correctly\n"); } void displayVector(int * v) { // DO NOT MODIFY int i; int displayWidth = 2 + log10(v[N-1]); for(i = 0; i < N; i++) { printf("%*i", displayWidth, v[i]); if(!((i+1) % 20)) printf("\n"); } printf("\n"); } int cmp(const void *a, const void *b) { // DO NOT MODIFY int A = *(int*)a; int B = *(int*)b; return A-B; } void getArgs(int argc, char **argv) { if(argc < 4) { printf("Not enough paramters: ./program N NReps printLevel\nprintLevel: 0=no, 1=some, 2=verbouse\n"); exit(1); } N = atoi(argv[1]); NReps = atoi(argv[2]); printLevel = atoi(argv[3]); } void init() { int i; v = malloc(sizeof(int) * N); vQSort = malloc(sizeof(int) * N); vNew = malloc(sizeof(int) * N); if(v == NULL) { printf("malloc failed!"); exit(1); } // generate the vector v with random values // DO NOT MODIFY srand(42); for(i = 0; i < N; i++) v[i] = rand()%N; } void printPartial() { compareVectors(v, vQSort); } void printAll() { displayVector(v); displayVector(vQSort); compareVectors(v, vQSort); } void print() { if(printLevel == 0) return; else if(printLevel == 1) printPartial(); else printAll(); } int main(int argc, char *argv[]) { int i, aux; getArgs(argc, argv); init(); // make copy to check it against qsort // DO NOT MODIFY for(i = 0; i < N; i++) vQSort[i] = v[i]; qsort(vQSort, N, sizeof(int), cmp); // sort the vector v // PARALLELIZE ME int sorted = 0; while(!sorted) { sorted = 1; for(i = 0; i < N-1; i++) { if(v[i] > v[i + 1]) { aux = v[i]; v[i] = v[i + 1]; v[i + 1] = aux; sorted = 0; } } } print(); return 0; }
the_stack_data/68887599.c
// C program to print all permutations with duplicates allowed #include <stdio.h> #include <string.h> //global count var int cnt = 0; /* Function to swap values at two pointers */ void swap(char *x, char *y) { char temp; temp = *x; *x = *y; *y = temp; } /* Function to print permutations of string This function takes three parameters: 1. String 2. Starting index of the string 3. Ending index of the string. */ void permute(char *a, int l, int r) { int i; if (l == r) { printf("%s\n", a); cnt++; } else { for (i = l; i <= r; i++) { swap((a+l), (a+i)); permute(a, l+1, r); swap((a+l), (a+i)); //backtrack } } } void print_usage() { printf("usage: print_anagram <n>\n"); } /* Driver program to test above functions */ int main(int argc, char *argv[]) { //skip over program name ++argv;--argc; //@handle: no values condition if (argc == 0) { print_usage(); return -1; } permute(argv[0], 0, strlen(argv[0]) - 1); printf("Total permutations: %d\n", cnt); return 0; }
the_stack_data/295987.c
#include <stdio.h> #include <time.h> void dump_time_struct_bytes(struct tm *time_ptr, int size) { int i; unsigned char *raw_ptr; printf("bytes of struct located at 0x%08x\n", time_ptr); raw_ptr = (unsigned char *) time_ptr; for (i=0; i<size; i++) { printf("%02x ", raw_ptr[i]); if (i%16 == 15) printf("\n"); } printf("\n"); } int main() { long int seconds_since_epoch; struct tm current_time, *time_ptr; int hour, minute, second, i, *int_ptr; seconds_since_epoch = time(0); printf("time() - seconds since epoch: %ld\n", seconds_since_epoch); time_ptr = &current_time; localtime_r(&seconds_since_epoch, time_ptr); hour = current_time.tm_hour; minute = time_ptr->tm_min; second = *((int *) time_ptr); printf("Current time is: %02d:%02d:%02d:\n", hour, minute, second); dump_time_struct_bytes(time_ptr, sizeof(struct tm)); minute = hour = 0; int_ptr = (int *) time_ptr; for (i=0; i<3; i++) { printf("int_ptr @ 0x%08x : %d\n", int_ptr, *int_ptr); int_ptr++; } }
the_stack_data/159514874.c
#include<stdio.h> int max(int,int); int min(int,int); int main() { int n,K,a[1000],N,i,M,max1,min1,H,l,r; scanf("%d%d",&n,&K); for(i=0;i<n;i++) scanf("%d",&a[i]); while(~scanf("%d%d",&l,&r)) {for(i=l,N=0,M=1;i<=r;i++) {N+=a[i]%n; M=((M%n)*(a[i]%n))%n;} N=N%n; max1=max(M,N); min1=min(M,N); H=a[min1]; for(i=min1+1;i<=max1;i++) {H=H^a[i];} printf("%d\n",H); } return 0; } int max(int x,int y) { if(x>y) return x; return y; } int min(int x,int y) {if(x>y) return y; return x; }
the_stack_data/72013146.c
// SPDX-License-Identifier: BSD-3-Clause /* Copyright 2020, Intel Corporation */ /* * template-snippet -- documentation snippets */ // ! [template_example] void template_example() { } // ! [template_example] // ! [template_base_example] void template_base_example() { } // ! [template_base_example]
the_stack_data/68886611.c
#include <stdio.h> char cLetra; //Caracter de una posicion int main(void){ cLetra = 's'; //Asignacion de un valor /* cLetra = '\'' //Asignacion de un valor El caracter blackslash \ es un caracter de escape */ printf("La letra es %c.\nSu valor en ASCII es %d\n" ,cLetra,cLetra); return 0; }//fin int main
the_stack_data/513200.c
/*numPass=7, numTotal=7 Verdict:ACCEPTED, Visibility:1, Input:"4 4 1 2 3 4", ExpOutput:"10 ", Output:"10" Verdict:ACCEPTED, Visibility:1, Input:"5 0 55 32 56 12 83", ExpOutput:"55 ", Output:"55" Verdict:ACCEPTED, Visibility:1, Input:"20 30 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", ExpOutput:"19457 ", Output:"19457" Verdict:ACCEPTED, Visibility:1, Input:"20 30 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -2", ExpOutput:"-1365 ", Output:"-1365" Verdict:ACCEPTED, Visibility:1, Input:"2 5 1 1", ExpOutput:"8 ", Output:"8" Verdict:ACCEPTED, Visibility:0, Input:"10 30 1 2 3 4 5 6 7 8 9 10", ExpOutput:"55312397 ", Output:"55312397" Verdict:ACCEPTED, Visibility:0, Input:"20 30 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1", ExpOutput:"-341 ", Output:"-341" */ #include <stdio.h> void read_into_array(int arr[],int size) { int i; for(i=0;i<size;i++) { scanf("%d ",&arr[i]); } } void extension(int arr[],int size,int d) { int i,j=d; while(j<=size) { arr[j]=0; for(i=1;i<=d;i++) { arr[j]+=arr[j-i]; } j++; } } int main() { int d,N,a[30]; scanf("%d %d\n",&d,&N); read_into_array(a,d); extension(a,N,d); printf("%d",a[N]); }
the_stack_data/159516527.c
int main(void) { unsigned int x = 0; while (x < 0x0fffffff) { if (x < 0xfff1) { x++; } else { x += 2; } } __CPROVER_assert(!(x % 2), "A"); return 0; }
the_stack_data/243892972.c
//===-- CBackend.cpp - Library for converting LLVM code to C //-----------------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===-------------------------------------------------------------------------------===// // // This code tests to see that the CBE can handle declaring and // returning an unsigned long int. // *TW //===-------------------------------------------------------------------------------===// int main() { unsigned long int a = 6; int ia = 0; ia = (int)a; return ia; }
the_stack_data/3262851.c
#define _XOPEN_SOURCE 600 /* Or higher */ #include <stdio.h> #include <stdlib.h> #include <semaphore.h> #include <pthread.h> #include <time.h> #define THREADS_NUMBER 4 #define GEN_LIMIT 1000 #define TRUE 1 #define FALSE 0 typedef unsigned char cell_t; int size; int width = 0, height = 0; int stop = FALSE, k; int num_threads, lines, reminder; cell_t ** prev, ** next, ** tmp; pthread_barrier_t barrier; cell_t ** allocate_board () { cell_t ** board = (cell_t **) malloc(sizeof(cell_t*)*size); int i; for (i=0; i<size; i++) board[i] = (cell_t *) malloc(sizeof(cell_t)*size); return board; } void free_board (cell_t ** board) { int i; for (i=0; i<size; i++) free(board[i]); free(board); } int empty (cell_t ** board) { int i, j; for (i=0; i<height; i++) for (j = 0; j < width; j++) if(board[i][j] == 1) return FALSE; return TRUE; } /* return the number of on cells adjacent to the i,j cell */ int adjacent_to (cell_t ** board, int i, int j) { int k, l, count=0; int sk = (i>0) ? i-1 : i; //IZQ int ek = (i+1 < size) ? i+1 : i; //DES int sl = (j>0) ? j-1 : j; //ARR int el = (j+1 < size) ? j+1 : j; //ABA for (k=sk; k<=ek; k++) for (l=sl; l<=el; l++) count+=board[k][l]; count-=board[i][j]; return count; } /* read a file into the life board */ void read_file (FILE * f, cell_t ** board) { int i, j; char *s = (char *) malloc(size); /* read the life board */ for (j=0; j<size; j++) { /* get a string */ fgets (s, size,f); /* copy the string to the life board */ for (i=0; i<size; i++) board[i][j] = s[i] == '1'; // !!! Cambiado para poner 1 y no x } } void print_to_file(cell_t **univ, int width, int height) { FILE *fout = fopen("./game_output.out", "w"); // printing the result to a file with // 1 or 0 (1 being an alive cell and 0 a dead cell) for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { fprintf(fout, "%c", (univ[i][j] == 1) ? '1': '0' ); } fprintf(fout, "\n"); } fflush(fout); fclose(fout); } void play (int this_start, int this_end, int thread_id) { /* for each cell, apply the rules of Life */ int a; while (k < GEN_LIMIT) { //!!! De donde vendra esa k? //SOL: k es la generacion x la que van entiendo, la acutaliada threadID == 0 for (int i=this_start; i<this_end; i++) { for (int j=0; j<size; j++) { a = adjacent_to (prev, i, j); if (a == 2) next[i][j] = prev[i][j]; if (a == 3) next[i][j] = 1; if (a < 2) next[i][j] = 0; if (a > 3) next[i][j] = 0; } } // Barreira pra todas as threads terminarem de processar pthread_barrier_wait(&barrier); // Uma única thread executa o final do step if(thread_id == 0) { if(empty(prev)) stop = TRUE; else { tmp = next; next = prev; prev = tmp; k++; } } // Barreira para esperarem o final do step pthread_barrier_wait(&barrier); if (stop) break; } pthread_exit(NULL); } void* defineWork(void* arg) { int thread_id = *((int *) arg); int this_start = thread_id * lines; int this_end = this_start + lines; // El ultimo thread usa el resto if (thread_id == num_threads - 1) { this_end+= reminder; } play(this_start, this_end, thread_id); return 0; } int main (int argc, char ** argv) { // !!!!! A MODIFICAR PARA HACER MISMO IMPUT QUE EL RESTO //Establecer tamaño if (argc > 1) width = atoi(argv[1]); if (argc > 2) height = atoi(argv[2]); size = width*height; prev = allocate_board (); FILE* f = fopen(argv[3], "r"); read_file (f, prev); fclose(f); next = allocate_board (); num_threads = THREADS_NUMBER; // Dividiendo trabajo lines = size/num_threads; reminder = size%num_threads; // Inicializar threads pthread_barrier_init(&barrier, NULL, num_threads); pthread_t threads[num_threads]; for (int i = 0; i < num_threads; ++i) { int *arg = malloc(sizeof(int)); *arg = i; pthread_create(&threads[i], NULL, defineWork, arg); } time_t start, end; start = clock(); for (int i = 0; i < num_threads; ++i) { pthread_join(threads[i], NULL); } end = clock(); float msecs = ((float) (end - start)*1000) / CLOCKS_PER_SEC; //Escribir en final print_to_file(prev, width, height); printf("Generations:\t%d\n", k); printf("Execution time:\t%.2f msecs\n", msecs); printf("Finished\n"); pthread_barrier_destroy(&barrier); free_board(prev); free_board(next); }
the_stack_data/1167722.c
/* Generated automatically by H5make_libsettings -- do not edit */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Copyright by The HDF Group. * * Copyright by the Board of Trustees of the University of Illinois. * * All rights reserved. * * * * This file is part of HDF5. The full HDF5 copyright notice, including * * terms governing use, modification, and redistribution, is contained in * * the COPYING file, which can be found at the root of the source code * * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * * If you do not have access to either file, you may request a copy from * * [email protected]. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Created: Apr 8, 2018 * * <u0_a68@localhost> * * Purpose: This machine-generated source code contains * information about the library build configuration * * Modifications: * * DO NOT MAKE MODIFICATIONS TO THIS FILE! * It was generated by code in `H5make_libsettings.c'. * *------------------------------------------------------------------------- */ char H5libhdf5_settings[]= " SUMMARY OF THE HDF5 CONFIGURATION\n" " =================================\n" "\n" "General Information:\n" "-------------------\n" " HDF5 Version: 1.10.1\n" " Configured on: 2018-04-08\n" " Configured by: Ninja\n" " Host system: Linux-3.4.112-B--B-PWR-CORE-AOSP-v1.5\n" " Uname information: Linux\n" " Byte sex: little-endian\n" " Installation point: /data/data/com.mininix/files/usr\n" "\n" "Compiling Options:\n" "------------------\n" " Build Mode: \n" " Debugging Symbols: \n" " Asserts: \n" " Profiling: \n" " Optimization Level: \n" "\n" "Linking Options:\n" "----------------\n" " Libraries: \n" " Statically Linked Executables: OFF\n" " LDFLAGS: \n" " H5_LDFLAGS: \n" " AM_LDFLAGS: \n" " Extra libraries: m;dl\n" " Archiver: /data/data/com.mininix/files/usr/bin/ar\n" " Ranlib: /data/data/com.mininix/files/usr/bin/ranlib\n" "\n" "Languages:\n" "----------\n" " C: yes\n" " C Compiler: /data/data/com.mininix/files/usr/bin/cc 6.0.0\n" " CPPFLAGS: \n" " H5_CPPFLAGS: \n" " AM_CPPFLAGS: \n" " CFLAGS: \n" " H5_CFLAGS: \n" " AM_CFLAGS: \n" " Shared C Library: YES\n" " Static C Library: YES\n" "\n" " Fortran: OFF\n" " Fortran Compiler: \n" " Fortran Flags: \n" " H5 Fortran Flags: \n" " AM Fortran Flags: \n" " Shared Fortran Library: YES\n" " Static Fortran Library: YES\n" "\n" " C++: ON\n" " C++ Compiler: /data/data/com.mininix/files/usr/bin/c++ 6.0.0\n" " C++ Flags: \n" " H5 C++ Flags: \n" " AM C++ Flags: \n" " Shared C++ Library: YES\n" " Static C++ Library: YES\n" "\n" " JAVA: OFF\n" " JAVA Compiler: \n" "\n" "Features:\n" "---------\n" " Parallel HDF5: OFF\n" " High-level library: ON\n" " Threadsafety: OFF\n" " Default API mapping: v110\n" " With deprecated public symbols: ON\n" " I/O filters (external): \n" " MPE: \n" " Direct VFD: \n" " dmalloc: \n" " Packages w/ extra debug output: \n" " API Tracing: OFF\n" " Using memory checker: OFF\n" "Memory allocation sanity checks: OFF\n" " Metadata trace file: \n" " Function Stack Tracing: OFF\n" " Strict File Format Checks: OFF\n" " Optimization Instrumentation: \n" ;
the_stack_data/470564.c
/* Verify that unwinding can find SPE registers in signal frames. */ /* Origin: Joseph Myers <[email protected]> */ /* { dg-do run { target { powerpc*-*-linux* && powerpc_spe } } } */ /* { dg-options "-fexceptions -fnon-call-exceptions -O2" } */ #include <unwind.h> #include <stdlib.h> #include <signal.h> #include <string.h> int count; char *null; int found_reg; typedef int v2si __attribute__((__vector_size__(8))); v2si v1 = { 123, 234 }; v2si v2 = { 345, 456 }; static _Unwind_Reason_Code force_unwind_stop (int version, _Unwind_Action actions, _Unwind_Exception_Class exc_class, struct _Unwind_Exception *exc_obj, struct _Unwind_Context *context, void *stop_parameter) { unsigned int reg; if (actions & _UA_END_OF_STACK) abort (); if (_Unwind_GetGR (context, 1215) == 123) found_reg = 1; return _URC_NO_REASON; } static void force_unwind () { struct _Unwind_Exception *exc = malloc (sizeof (*exc)); memset (&exc->exception_class, 0, sizeof (exc->exception_class)); exc->exception_cleanup = 0; #ifndef __USING_SJLJ_EXCEPTIONS__ _Unwind_ForcedUnwind (exc, force_unwind_stop, 0); #else _Unwind_SjLj_ForcedUnwind (exc, force_unwind_stop, 0); #endif abort (); } static void counter (void *p __attribute__((unused))) { ++count; } static void handler (void *p __attribute__((unused))) { if (count != 2) abort (); if (!found_reg) abort (); exit (0); } static int __attribute__((noinline)) fn5 () { char dummy __attribute__((cleanup (counter))); force_unwind (); return 0; } static void fn4 (int sig) { char dummy __attribute__((cleanup (counter))); /* Clobber high part without compiler's knowledge so the only saved copy is from the signal frame. */ asm volatile ("evmergelo 15,15,15"); fn5 (); null = NULL; } static void fn3 () { abort (); } static int __attribute__((noinline)) fn2 () { register v2si r15 asm("r15"); r15 = v1; asm volatile ("" : "+r" (r15)); *null = 0; fn3 (); return 0; } static int __attribute__((noinline)) fn1 () { signal (SIGSEGV, fn4); signal (SIGBUS, fn4); fn2 (); return 0; } static int __attribute__((noinline)) fn0 () { char dummy __attribute__((cleanup (handler))); fn1 (); null = 0; return 0; } int main() { fn0 (); abort (); }
the_stack_data/140765406.c
/* -Woverlength-strings complains about string constants which are too long for the C standard's "minimum maximum" limits. It is off by default, but implied by -pedantic. */ /* { dg-options "-std=c89 -pedantic" } */ #define TEN "xxxxxxxxxx" #define HUN TEN TEN TEN TEN TEN TEN TEN TEN TEN TEN #define THO HUN HUN HUN HUN HUN HUN HUN HUN HUN HUN /* C89's minimum-maximum is 509. */ const char x510[] = HUN HUN HUN HUN HUN TEN; /* { dg-warning "greater than" } */ /* C99's minimum-maximum is 4095. */ const char x4096[] = THO THO THO THO /* 4000 */ TEN TEN TEN TEN TEN /* 4050 */ TEN TEN TEN TEN /* 4090 */ "123456"; /* { dg-warning "greater than" } */
the_stack_data/1048399.c
/** ****************************************************************************** * File Name : DAC.c * Date : 18/01/2015 10:00:30 * Description : This file provides code for the configuration * of the DAC instances. ****************************************************************************** * * COPYRIGHT(c) 2015 STMicroelectronics * * 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. * 3. Neither the name of STMicroelectronics nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * 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 HOLDER 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. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #ifdef USE_GEN #include "dac.h" #include "gpio.h" #include "tim.h" /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ DAC_HandleTypeDef hdac; DMA_HandleTypeDef hdma_dac1; DMA_HandleTypeDef hdma_dac2; /* DAC init function */ void MX_DAC_Init(void) { DAC_ChannelConfTypeDef sConfig; /**DAC Initialization */ hdac.Instance = DAC; HAL_DAC_Init(&hdac); /**DAC channel OUT1 config */ sConfig.DAC_Trigger = DAC_TRIGGER_T6_TRGO; sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE; HAL_DAC_ConfigChannel(&hdac, &sConfig, DAC_CHANNEL_1); /**DAC channel OUT2 config */ sConfig.DAC_Trigger = DAC_TRIGGER_T7_TRGO; sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE; HAL_DAC_ConfigChannel(&hdac, &sConfig, DAC_CHANNEL_2); } void HAL_DAC_MspInit(DAC_HandleTypeDef* hdac) { GPIO_InitTypeDef GPIO_InitStruct; if(hdac->Instance==DAC) { /* USER CODE BEGIN DAC_MspInit 0 */ /* USER CODE END DAC_MspInit 0 */ /* Peripheral clock enable */ __DAC_CLK_ENABLE(); /**DAC GPIO Configuration PA4 ------> DAC_OUT1 PA5 ------> DAC_OUT2 */ GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* USER CODE BEGIN DAC_MspInit 1 */ /* Set the parameters to be configured for Channel1*/ hdma_dac1.Instance = DMA1_Stream5; hdma_dac1.Init.Channel = DMA_CHANNEL_7; hdma_dac1.Init.Direction = DMA_MEMORY_TO_PERIPH; hdma_dac1.Init.PeriphInc = DMA_PINC_DISABLE; hdma_dac1.Init.MemInc = DMA_MINC_ENABLE; hdma_dac1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; hdma_dac1.Init.MemDataAlignment = DMA_PDATAALIGN_HALFWORD; hdma_dac1.Init.Mode = DMA_CIRCULAR; hdma_dac1.Init.Priority = DMA_PRIORITY_HIGH; hdma_dac1.Init.FIFOMode = DMA_FIFOMODE_DISABLE; hdma_dac1.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_HALFFULL; hdma_dac1.Init.MemBurst = DMA_MBURST_SINGLE; hdma_dac1.Init.PeriphBurst = DMA_PBURST_SINGLE; HAL_DMA_Init(&hdma_dac1); /* Associate the initialized DMA handle to the the DAC handle */ __HAL_LINKDMA(hdac, DMA_Handle1, hdma_dac1); /* Set the parameters to be configured for Channel2*/ hdma_dac2.Instance = DMA1_Stream6; hdma_dac2.Init.Channel = DMA_CHANNEL_7; hdma_dac2.Init.Direction = DMA_MEMORY_TO_PERIPH; hdma_dac2.Init.PeriphInc = DMA_PINC_DISABLE; hdma_dac2.Init.MemInc = DMA_MINC_ENABLE; hdma_dac2.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; hdma_dac2.Init.MemDataAlignment = DMA_PDATAALIGN_HALFWORD; hdma_dac2.Init.Mode = DMA_CIRCULAR; hdma_dac2.Init.Priority = DMA_PRIORITY_HIGH; hdma_dac2.Init.FIFOMode = DMA_FIFOMODE_DISABLE; hdma_dac2.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_HALFFULL; hdma_dac2.Init.MemBurst = DMA_MBURST_SINGLE; hdma_dac2.Init.PeriphBurst = DMA_PBURST_SINGLE; HAL_DMA_Init(&hdma_dac2); /* Associate the initialized DMA handle to the the DAC handle */ __HAL_LINKDMA(hdac, DMA_Handle2, hdma_dac2); /* USER CODE END DAC_MspInit 1 */ } } void HAL_DAC_MspDeInit(DAC_HandleTypeDef* hdac) { if(hdac->Instance==DAC) { /* USER CODE BEGIN DAC_MspDeInit 0 */ /* USER CODE END DAC_MspDeInit 0 */ /* Peripheral clock disable */ __DAC_CLK_DISABLE(); /**DAC GPIO Configuration PA4 ------> DAC_OUT1 PA5 ------> DAC_OUT2 */ HAL_GPIO_DeInit(GPIOA, GPIO_PIN_4|GPIO_PIN_5); /* USER CODE BEGIN DAC_MspDeInit 1 */ /* USER CODE END DAC_MspDeInit 1 */ } } /* USER CODE BEGIN 1 */ void DAC_DMA_Reconfig(uint8_t chan, uint32_t *buff, uint32_t len){ uint32_t dacChannel=0; switch(chan){ case 0: dacChannel=DAC_CHANNEL_1; break; case 1: dacChannel=DAC_CHANNEL_2; break; } HAL_DAC_Stop_DMA(&hdac,dacChannel); HAL_DAC_Start_DMA(&hdac, dacChannel, buff, len, DAC_ALIGN_12B_R); } /** * @brief Enable sampling * @param None * @retval None */ void GeneratingEnable (void){ TIMGenEnable(); } /** * @brief Disable sampling * @param None * @retval None */ void GeneratingDisable (void){ TIMGenDisable(); } void DACInit(){ MX_DAC_Init(); } /* USER CODE END 1 */ /** * @} */ /** * @} */ #endif //USE_GEN /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
the_stack_data/1261801.c
/********************************************************************************************* * * MIDI2TONES: Convert a MIDI file into a simple bytestream of notes * * This is a fork of MIDITONES as it stood on September 27, 2016 * Copyright (c) 2011,2013,2015,2016, Len Shustek * https://github.com/LenShustek/miditones * * The purpose of the fork was to add an alternate output format. * * MIDI2TONES converts a MIDI music file into a much simplified stream of commands, so that * the music can easily be played on a small microcontroller-based synthesizer that has * only simple tone generators. This is on GitHub at * https://github.com/MLXXXp/midi2tones * * This was written for the "Playtune" series of Arduino and Teensy microcontroller * synthesizers. See the separate documentation for the various Playtune players at * https://github.com/LenShustek/arduino-playtune * https://github.com/LenShustek/ATtiny-playtune * https://github.com/LenShustek/Playtune_poll * https://github.com/LenShustek/Playtune_samp * and also the ArduboyPlaytune library derived from arduino-playtune * https://github.com/Arduboy/ArduboyPlaytune * * MIDI2TONES may also prove useful for other simple music synthesizers. * * Volume ("velocity") and instrument information in the MIDI file can either be * discarded or kept. All the tracks are processed and merged into a single time-ordered * stream of "note on", "note off", "change instrument" and "delay" commands. * * An alternate output format can be specified, which consists of a single monotonic * stream of frequency/duration pairs of 16 bit values. The specified frequency can * also include a flag to indicate that the note is to be played at a higher volume, * if the velocity of the MIDI note is above a certain value. * This format is suitable for use with the ArduboyTones library, which is on GitHub at * https://github.com/Arduboy/ArduboyTones * * The output can be either a C-language source code fragment that initializes an * array with the command bytestream, or a binary file with the bytestream itself. * * MIDI2TONES is written in standard ANSI C and is meant to be executed from the * command line. There is no GUI interface. * * The MIDI file format is complicated, and this has not been tested on all of its * variations. In particular we have tested only format type "1", which seems * to be what most of them are. Let me know if you find MIDI files that it * won't digest and I'll see if I can fix it. * * There is a companion program in the same repository called Miditones_scroll that * can convert the Playtune bytestream generated by MIDI2TONES into a piano-player * like listing for debugging or annotation. See the documentation in the * beginning of its source code. * * * ***** The MIDI2TONES command line ***** * * To convert a MIDI file called "chopin.mid" into a command bytestream, execute * * midi2tones chopin * * It will create a file in the same directory called "chopin.c" which contains * the C-language statement to intiialize an array called "score" with the bytestream. * * * The general form for command line execution is this: * * midi2tones <options> <basefilename> * * Options must be specified individually, each with its own "-" lead-in, and separated * with spaces. A forward slash "/" can be used instead of a dash "-" for option lead-ins. * * The <basefilename> is the base name, without an extension, for the input and * output files. It can contain directory path information, or not. * * The input file is <basefilename>.mid The output filename(s) * are the base file name with .c, .bin, and/or .log extensions. * * * The following commonly-used command-line options can be specified: * * -on Generate output format "n". * Two formats are available: * 1: The Playtune format (which is the default if this option isn't given). * 2: The frequency/duration pair format, as used by ArduboyTones. * * -v Add velocity (volume) information to the output bytestream. * * -vn For the alternate format, "n" specifies the minimum velocity value that will * produce a high volume tone. Without this option all tones will be * normal volume. * * -i Add instrument change commands to the output bytestream. * * -pt Translate notes in the MIDI percussion track to note numbers 128..255 * and assign them to a tone generator as usual. * * -d Generate a self-describing file header that says which optional bytestream * fields are present. This is highly recommended if you are using later * Playtune players that can check the header to know what data to expect. * * -b Generate a binary file with the name <basefilename>.bin, instead of a * C-language source file with the name <basefilename>.c. * * -tn Generate the bytestream so that at most "n" tone generators are used. * The default is 6 tone generators, and the maximum is 16. The program * will report how many notes had to be discarded because there weren't * enough tone generators. * * * The following are lesser-used command-line options: * * -p Only parse the MIDI file, and don't generate an output file. * Tracks are processed sequentially instead of being merged into chronological order. * This is mostly useful for debugging MIDI file parsing problems. * * -lp Log input file parsing information to the <basefilename>.log file. * * -lg Log output bytestream generation information to the <basefilename>.log file. * * -nx Put about "x" items on each line of the C file output. * * -sn Use bytestream generation strategy "n". * Two strategies are currently implemented: * 1: Favor track 1 notes instead of all tracks equally. * 2: Try to keep each track to its own tone generator. * * -cn Only process the channel numbers whose bits are on in the number "n". * For example, -c3 means "only process channels 0 and 1". In addition to decimal, * "n" can be also specified in hex using a 0x prefix or octal with a 0 prefix. * For the alternate output format, only the lowest bit will be used to specify * the single channel to be processed, and without this option channel 0 will * be used. * * -kn Change the musical key of the output by n chromatic notes. * -k-12 goes one octave down, -k12 goes one octave up, etc. * * -pi Ignore notes in the MIDI percussion track 9 (also called 10 by some). * * -dp Generate IDE-dependent C code to define PROGMEM. * * -fx For the alternate output format, instead of using defined note names, * output actual frequency values in decimal format depending on "x": * -fa: For high volume notes use format "<freq>+TONE_HIGH_VOLUME". * -fb: For high volume notes just add 0x8000 to the frequency value. * * -r Terminate the output file with a "restart" command instead of a "stop" command. * * -h Give command-line help. * * * ***** The score bytestream ***** * * The generated bytestream is a series of commands that turn notes on and off, * maybe change instruments, and begin delays until the next note change. * Here are the details, with numbers shown in hexadecimal. * * If the high-order bit of the byte is 1, then it is one of the following commands: * * 9t nn [vv] * Start playing note nn on tone generator t, replacing any previous note. * Generators are numbered starting with 0. The note numbers are the MIDI * numbers for the chromatic scale, with decimal 69 being Middle A (440 Hz). * If the -v option was given, a second byte is added to indicate note volume. * * 8t Stop playing the note on tone generator t. * * Ct ii Change tone generator t to play instrument ii from now on. This will only * be generated if the -i option was given. * * F0 End of score; stop playing. * * E0 End of score; start playing again from the beginning. Will be generated if * the -r option was given. * * If the high-order bit of the byte is 0, it is a command to delay for a while until * the next note change. The other 7 bits and the 8 bits of the following byte are * interpreted as a 15-bit big-endian integer that is the number of milliseconds to * wait before processing the next command. For example, * * 07 D0 * * would cause a delay of 0x07d0 = 2000 decimal millisconds, or 2 seconds. Any tones * that were playing before the delay command will continue to play. * * If the -d option is specified, the bytestream begins with a little header that tells * what optional information will be in the data. This makes the file more self-describing, * and allows music players to adapt to different kinds of files. The later Playtune * players do that. The header looks like this: * * 'Pt' Two ascii characters that signal the presence of the header * nn The length (in one byte) of the entire header, 6..255 * ff1 A byte of flag bits, three of which are currently defined: * 80 velocity information is present * 40 instrument change information is present * 20 translated percussion notes are present * ff2 Another byte of flags, currently undefined * tt The number (in one byte) of tone generators actually used in this music. * * Any subsequent header bytes covered by the count, if present, are currently undefined * and should be ignored by players. * * ***** The alternate frequency/duration pair output format ***** * * The generated stream is a series of frequency/duration value pairs. The frequency * is in Hz and the duration is in milliseconds. Each value is 16 bits. For a binary * file the values are stored high byte first. The ArduboyTones player supports * frequencies from 16 Hz to 32767 Hz but MIDI2TONES converts MIDI note numbers in the * range from note 12 (16.352 Hz rounded to 16 Hz) to note 127 (12543.9 Hz rounded * to 12544 Hz). * * Periods of silence are represented by a frequency/duration pair with a frequency * value of 0. * * Since the output is monotonic, only one MIDI channel is processed. The lowest bit * set in the -cn option's mask will indicate the channel to be used. If the -cn option * isn't given, channel 0 will be used. * * Tones can be specified to play at either normal or high volume. High volume is * indicated by setting the high bit of the frequency value (i.e. adding 0x8000 to the * desired frequency). A note will be set to high volume if the -vn option is used and * the MIDI velocity of the note is equal to or greater than the option value. * * For the C output format, frequencies will be output as note names, as defined in the * ArduboyTones library's ArduboyTonesPitches.h file. If the -f option is given, * the actual frequency, in decimal, will be used instead. Durations will be output * in decimal. * * Output files are terminated with a single 16 bit value of 0x8000 to indicate * end of score - stop playing. A file can instead be terminated with 0x8001 to indicate * end of score - start playing again from the beginning, which is specified using the * -r option. * * Len Shustek, 4 Feb 2011 and later. * Frequency/duration pair output format and other changes: * Scott Allen, 27 Sept 2016 and later. *********************************************************************************************/ /********************************************************************************************* * The MIT License (MIT) * Original work Copyright (c) 2011,2013,2015,2016, Len Shustek * Modified work Copyright (c) 2016, Scott Allen * * Permission is hereby granted, 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. *********************************************************************************************/ /* * Change log * 19 January 2011, L.Shustek, V1.0 * -Initial release. * 26 February 2011, L. Shustek, V1.1 * -Expand the documentation generated in the output file. * -End the binary output file with an "end of score" command. * -Fix bug: Some "stop note" commands were generated too early. * 04 March 2011, L. Shustek, V1.2 * -Minor error message rewording. * 13 June 2011, L. Shustek, V1.3 * -Add -s2 strategy to try to keep each track on its own tone generator * for when there are separate speakers. This obviously works only when * each track is monophonic. (Suggested by Michal Pustejovsky) * 20 November 2011, L. Shustek, V1.4 * -Add -cn option to mask which channels (tracks) to process * -Add -kn option to change key * Both of these are in support of music-playing on my Tesla Coil. * 05 December 2011, L. Shustek, V1.5 * -Fix command line parsing error for option -s1 * -Display the commandline in the C file output * -Change to decimal instead of hex for note numbers in the C file output * 06 August 2013, L. Shustek, V1.6 * -Changed to allow compilation and execution in 64-bit environments * by using C99 standard intN_t and uintN_t types for MIDI structures, * and formatting specifications like "PRId32" instead of "ld". * 04 April 2015, L. Shustek, V1.7 * -Made friendlier to other compilers: import source of strlcpy and strlcat, * fixed various type mismatches that the LCC compiler didn't fret about. * Generate "const" for data initialization for compatibility with Arduino IDE v1.6.x. * 23 January 2016, D. Blackketter, V1.8 * -Fix warnings and errors building on Mac OS X via "gcc miditones.c" * 25 January 2016, D. Blackketter, Paul Stoffregen, V1.9 * -Merge in velocity output option from Arduino/Teensy Audio Library * 26 June 2016, L. Shustek, V1.10 * -Fix overflow problem in calculating long delays. (Thanks go to Tiago Rocha.) * In the process I discover and work around an LCC 32-bit compiler bug. * 14 August 2016: L. Shustek, V1.11 * -Fix our interpretation of MIDI "running status": it applies only to MIDI events * (8x through Ex), not, as we thought, also to Sysex (Fx) or Meta (FF) events. * -Improve parsing of text events for the log. * -Change log file note and patch numbers, etc., to decimal. * -Document a summary of the MIDI file format so I don't have to keep looking it up. * -Add -pi and -pt options to ignore or translate the MIDI percussion track 9. * -Remove string.h for more portability; add strlength(). * -Add -i option for recording instrument types in the bytestream. * -Add -d option for generating a file description header. * -Add -dp option to make generating the PROGMEM definition optional * -Add -n option to specify number of items per output line * -Do better error checking on options * -Reformat option help * 26 September 2016, Scott Allen, V1.12 * - Fix spelling and minor formatting errors * - Fix -p option parsing and handling, which broke when -pi and -pt were added * - Fix handling of the -nx option to count more accurately * - Give a proper error message for missing base name * - Include the header and terminator in the score byte count * * **** MIDITONES forked and renamed MIDI2TONES **** * * 27 September 2016, Scott Allen, V1.0.0 * -Add alternate frequency/duration pair output format and options to support it * -Add -r option to terminate output with "restart" instead of "stop" * -Allow hex and octal entry, in addition to decimal, for -cn option * -Prevent unnecessary "note off" commands from being generated by delaying * them until we see if a "note on" is generated before the next wait. * Ported from MIDITONES V1.14 */ #define VERSION "1.0.0" /*-------------------------------------------------------------------------------------------- A CONCISE SUMMARY OF MIDI FILE FORMAT L. Shustek, 16 July 2016. Gleaned from http://www.music.mcgill.ca/~ich/classes/mumt306/StandardMIDIfileformat.html Notation: <xxx> is 1-4 bytes of 7-bit data, concatenated into one 7- to 28-bit number. The high bit of the last byte is 0. lower case letters are hex digits. If preceeded by 0, only low 7 bits are used. "xx" are ascii text characters {xxx}... means indefinite repeat of xxx A MIDI file is: header_chunk {track_chunk}... header_chunk "MThd" 00000006 ffff nnnn dddd track_chunk "MTrk" llllllll {<deltatime> track_event}... "running status" track_event 0x to 7x: assume a missing 8n to En event code which is the same as the last MIDI-event track_event MIDI-event track_event 8n 0kk 0vv note off, channel n, note kk, velocity vv 9n 0kk 0vv note on, channel n, note kk, velocity vv An 0kk 0vv key pressure, channel n, note kk, pressure vv Bn 0cc 0vv control value change, channel n, controller cc, new value vv Cn 0pp program patch (instrument) change, channel n, new program pp Dn 0vv channel pressure, channel n, pressure vv En 0ll 0mm pitch wheel change, value llmm Note that channel 9 (called 10 by some programs) is used for percussion, particularly notes 35 to 81. Sysex event track_event F0 0ii {0dd}... F7 system-dependent data for manufacture ii. See www.gweep.net/~prefect/eng/reference/protocol/midispec.html F2 0ll 0mm song position pointer F3 0ss song select F6 tune request F7 end of system-dependent data F8 timing clock sync FA start playing FB continue playing FC stop playing FE active sensing (hearbeat) Meta event track_event FF 00 02 ssss specify sequence number FF 01 <len> "xx"... arbitrary text FF 02 <len> "xx"... copyright notice FF 03 <len> "xx"... sequence or track name FF 04 <len> "xx"... instrument name FF 05 <len> "xx"... lyric to be sung FF 06 <len> "xx"... name of marked point in the score FF 07 <len> "xx"... description of cue point in the score FF 20 01 0c default channel for subsequent events without a channel is c FF 2F 00 end of track FF 51 03 tttttt set tempo in microseconds per quarter-note FF 54 05 hhmmssfrff set SMPTE time to start the track FF 58 04 nnddccbb set time signature FF 59 02 sfmi set key signature FF 7F <len> data sequencer-specific data --------------------------------------------------------------------------------------------*/ #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <stdbool.h> #include <time.h> #include <inttypes.h> /*********** MIDI file header formats *****************/ struct midi_header { int8_t MThd[4]; uint32_t header_size; uint16_t format_type; uint16_t number_of_tracks; uint16_t time_division; }; struct track_header { int8_t MTrk[4]; uint32_t track_size; }; /*********** Global variables ******************/ #define MAX_TONEGENS 16 /* max tone generators: tones we can play simultaneously */ #define DEFAULT_TONEGENS 6 /* default number of tone generators */ #define MAX_TRACKS 24 /* max number of MIDI tracks we will process */ #define PERCUSSION_TRACK 9 /* the track MIDI uses for percussion sounds */ /* for alternate output format: */ #define TONE_HIGH_VOLUME 0x8000 /* add to frequency for high volume */ #define TONES_END 0x8000 /* end marker for stop playing */ #define TONES_REPEAT 0x8001 /* end marker for restart playing */ bool loggen, logparse, parseonly, strategy1, strategy2, binaryoutput, define_progmem, velocityoutput, instrumentoutput, percussion_ignore, percussion_translate, do_header, alt_out, gen_restart, freq_style_a, freq_style_b, option_n; FILE *infile, *outfile, *logfile; uint8_t *buffer, *hdrptr; unsigned long buflen; int num_tracks; int tracks_done = 0; int outfile_maxitems = 26; int outfile_itemcount = 0; int num_tonegens = DEFAULT_TONEGENS; int num_tonegens_used = 0; int instrument_changes = 0; int note_on_commands = 0; unsigned channel_mask = 0xffff; // bit mask of channels to process int keyshift = 0; // optional chromatic note shift for output file long int outfile_bytecount = 0; unsigned int ticks_per_beat = 240; unsigned long timenow = 0; unsigned long tempo; /* current tempo in usec/qnote */ int velocity_threshold = 128; /* alt out format: minimum velocity for high volume */ int pending_note; /* alt out format: note number awaiting output */ int pending_velocity; /* alt out format: velocity of note awaiting output */ int alt_out_channel; /* alt out format: MIDI channel used */ struct tonegen_status { /* current status of a tone generator */ bool playing; /* is it playing? */ bool stopnote_pending; /* do we need to stop this generator before the next wait? */ int track; /* if so, which track is the note from? */ int note; /* what note is playing? */ int instrument; /* what instrument? */ } tonegen[MAX_TONEGENS] = { { 0} }; struct track_status { /* current processing point of a MIDI track */ uint8_t *trkptr; /* ptr to the next note change */ uint8_t *trkend; /* ptr past the end of the track */ unsigned long time; /* what time we're at in the score */ unsigned long tempo; /* the tempo last set, in usec per qnote */ unsigned int preferred_tonegen; /* for strategy2, try to use this generator */ unsigned char cmd; /* CMD_xxxx next to do */ unsigned char note; /* for which note */ unsigned char chan; /* from which channel it was */ unsigned char velocity; /* the current volume */ unsigned char last_event; /* the last event, for MIDI's "running status" */ bool tonegens[MAX_TONEGENS]; /* which tone generators our notes are playing on */ } track[MAX_TRACKS] = { { 0} }; int midi_chan_instrument[16] = { 0 }; /* which instrument is currently being played on each channel */ /* output bytestream commands, which are also stored in track_status.cmd */ #define CMD_PLAYNOTE 0x90 /* play a note: low nibble is generator #, note is next byte */ #define CMD_STOPNOTE 0x80 /* stop a note: low nibble is generator # */ #define CMD_INSTRUMENT 0xc0 /* change instrument; low nibble is generator #, instrument is next byte */ #define CMD_RESTART 0xe0 /* restart the score from the beginning */ #define CMD_STOP 0xf0 /* stop playing */ /* if CMD < 0x80, then the other 7 bits and the next byte are a 15-bit number of msec to delay */ /* these other commands stored in the track_status.com */ #define CMD_TEMPO 0xFE /* tempo in usec per quarter note ("beat") */ #define CMD_TRACKDONE 0xFF /* no more data left in this track */ struct file_hdr_t { /* what the optional file header looks like */ char id1; // 'P' char id2; // 't' unsigned char hdr_length; // length of whole file header unsigned char f1; // flag byte 1 unsigned char f2; // flag byte 2 unsigned char num_tgens; // how many tone generators are used by this score } file_header = { 'P', 't', sizeof (struct file_hdr_t), 0, 0, MAX_TONEGENS}; #define HDR_F1_VOLUME_PRESENT 0x80 #define HDR_F1_INSTRUMENTS_PRESENT 0x40 #define HDR_F1_PERCUSSION_PRESENT 0x20 long int file_header_num_tgens_position; const char note_name[][3] = { "C", "CS", "D", "DS", "E", "F", "FS", "G", "GS", "A", "AS", "B" }; /* MIDI note frequencies (notes below number 12 not supported) */ const uint16_t note_freq[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0 - 11 */ 16, 17, 18, 19, 21, 22, 23, 25, 26, 28, 29, 31, /* 12 - 23 */ 33, 35, 37, 39, 41, 44, 46, 49, 52, 55, 58, 62, /* 24 - 35 */ 65, 69, 73, 78, 82, 87, 93, 98, 104, 110, 117, 123, /* 36 - 47 */ 131, 139, 147, 156, 165, 175, 185, 196, 208, 220, 233, 247, /* 48 - 59 */ 262, 277, 294, 311, 330, 349, 370, 392, 415, 440, 466, 494, /* 60 - 71 */ 523, 554, 587, 622, 659, 698, 740, 784, 831, 880, 932, 988, /* 72 - 83 */ 1047, 1109, 1175, 1245, 1319, 1397, 1480, 1568, 1661, 1760, 1865, 1976, /* 84 - 95 */ 2093, 2218, 2349, 2489, 2637, 2794, 2960, 3136, 3322, 3520, 3729, 3951, /* 96 - 107 */ 4186, 4435, 4699, 4978, 5274, 5588, 5920, 6272, 6645, 7040, 7459, 7902, /* 108 - 119 */ 8372, 8870, 9397, 9956,10548,11175,11840,12544 /* 120 - 127 */ }; /************** command-line processing *******************/ void SayUsage (char *programName) { static char *usage[] = { "Convert MIDI files to an Arduino PLAYTUNE bytestream,", "or a frequency/duration pairs stream suitable for ArduboyTones", "", "Use: midi2tones <options> <basefilename>", " input file will be <basefilename>.mid", " output file will be <basefilename>.bin or .c", " log file will be <basefilename>.log", "", "Commonly-used options:", " -o1 generate Playtune output format (the default)", " -o2 generate the frequency/duration pair output format", " -v include velocity data", " -vn for alternate format: n is the minimum velocity for high volume notes", " -i include instrument change commands", " -pt translate notes in the percussion track to notes 129 to 255", " -d include a self-describing file header", " -b generate binary file output instead of C source text", " -tn use at most n tone generators (default is 6, max is 16)", "", " The best options for later Playtune music players are: -v -i -pt -d", "", "Lesser-used command-line options:", " -p parse only, don't generate bytestream", " -lp log input parsing", " -lg log output generation", " -nx put about x items on each line of the C file output", " -s1 strategy 1: favor track 1", " -s2 strategy 2: try to assign tracks to specific tone generators", " -cn mask for which tracks to process, e.g. -c3 for only 0 and 1", " -kn key shift in chromatic notes, positive or negative", " -pi ignore notes in the percussion track (9)", " -fa for alternate format: high volume notes as \"<freq>+TONE_HIGH_VOLUME\"", " -fb for alternate format: high volume notes as a single decimal value", " -r terminate output file with \"restart\" instead of \"stop\" command", " -dp define PROGMEM in output C code", NULL }; int i = 0; while (usage[i] != NULL) fprintf (stderr, "%s\n", usage[i++]); } int HandleOptions (int argc, char *argv[]) { /* returns the index of the first argument that is not an option; i.e. does not start with a dash or a slash*/ int i, nch, firstnonoption = 0; /* --- The following skeleton comes from C:\lcc\lib\wizard\textmode.tpl. */ for (i = 1; i < argc; i++) { if (argv[i][0] == '/' || argv[i][0] == '-') { switch (toupper (argv[i][1])) { case 'H': case '?': SayUsage (argv[0]); exit (1); case 'O': if (argv[i][2] == '1') alt_out = false; else if (argv[i][2] == '2') { alt_out = true; printf ("Generating frequency/duration pair output format.\n"); } else goto opterror; if (argv[i][3] != '\0') goto opterror; break; case 'L': if (toupper (argv[i][2]) == 'G') loggen = true; else if (toupper (argv[i][2]) == 'P') logparse = true; else goto opterror; if (argv[i][3] != '\0') goto opterror; break; case 'P': if (argv[i][2] == '\0') { parseonly = true; break; } else if (toupper (argv[i][2]) == 'I') percussion_ignore = true; else if (toupper (argv[i][2]) == 'T') percussion_translate = true; else goto opterror; if (argv[i][3] != '\0') goto opterror; break; case 'B': binaryoutput = true; if (argv[i][2] != '\0') goto opterror; break; case 'V': velocityoutput = true; if (argv[i][2] == '\0') break; if (sscanf (&argv[i][2], "%d%n", &velocity_threshold, &nch) != 1 || velocity_threshold < 0 || velocity_threshold > 127) goto opterror; printf ("Using velocity >= %d for high volume.\n", velocity_threshold); if (argv[i][2 + nch] != '\0') goto opterror; break; case 'I': instrumentoutput = true; if (argv[i][2] != '\0') goto opterror; break; case 'S': if (argv[i][2] == '1') strategy1 = true; else if (argv[i][2] == '2') strategy2 = true; else goto opterror; if (argv[i][3] != '\0') goto opterror; break; case 'T': if (sscanf (&argv[i][2], "%d%n", &num_tonegens, &nch) != 1 || num_tonegens < 1 || num_tonegens > MAX_TONEGENS) goto opterror; printf ("Using %d tone generators.\n", num_tonegens); if (argv[i][2 + nch] != '\0') goto opterror; break; case 'N': if (sscanf (&argv[i][2], "%d%n", &outfile_maxitems, &nch) != 1 || outfile_maxitems < 1) goto opterror; if (argv[i][2 + nch] != '\0') goto opterror; option_n = true; break; case 'C': if (sscanf (&argv[i][2], "%i%n", &channel_mask, &nch) != 1 || channel_mask == 0 || channel_mask > 0xffff) goto opterror; printf ("Channel (track) mask is %04X.\n", channel_mask); if (argv[i][2 + nch] != '\0') goto opterror; break; case 'K': if (sscanf (&argv[i][2], "%d%n", &keyshift, &nch) != 1 || keyshift < -100 || keyshift > 100) goto opterror; printf ("Using keyshift %d.\n", keyshift); if (argv[i][2 + nch] != '\0') goto opterror; break; case 'D': if (argv[i][2] == '\0') { do_header = true; break; } if (toupper (argv[i][2]) == 'P') define_progmem = true; else goto opterror; if (argv[i][3] != '\0') goto opterror; break; case 'F': if (toupper (argv[i][2]) == 'A') freq_style_a = true; else if (toupper (argv[i][2]) == 'B') freq_style_b = true; else goto opterror; if (argv[i][3] != '\0') goto opterror; break; case 'R': gen_restart = true; if (argv[i][2] != '\0') goto opterror; break; /* add more option switches here */ opterror: default: fprintf (stderr, "\n*** unknown option: %s\n\n", argv[i]); SayUsage (argv[0]); exit (4); } } else { firstnonoption = i; break; } } return firstnonoption; } void print_command_line (int argc, char *argv[]) { int i; fprintf (outfile, "// command line: "); for (i = 0; i < argc; i++) fprintf (outfile, "%s ", argv[i]); fprintf (outfile, "\n"); } /**************** utility routines **********************/ /* portable string length */ int strlength (const char *str) { int i; for (i = 0; str[i] != '\0'; ++i); return i; } /* safe string copy */ size_t miditones_strlcpy (char *dst, const char *src, size_t siz) { char *d = dst; const char *s = src; size_t n = siz; /* Copy as many bytes as will fit */ if (n != 0) { while (--n != 0) { if ((*d++ = *s++) == '\0') break; } } /* Not enough room in dst, add NUL and traverse rest of src */ if (n == 0) { if (siz != 0) *d = '\0'; /* NUL-terminate dst */ while (*s++); } return (s - src - 1); /* count does not include NUL */ } /* safe string concatenation */ size_t miditones_strlcat (char *dst, const char *src, size_t siz) { char *d = dst; const char *s = src; size_t n = siz; size_t dlen; /* Find the end of dst and adjust bytes left but don't go past end */ while (n-- != 0 && *d != '\0') d++; dlen = d - dst; n = siz - dlen; if (n == 0) return (dlen + strlength (s)); while (*s != '\0') { if (n != 1) { *d++ = *s; n--; } s++; } *d = '\0'; return (dlen + (s - src)); /* count does not include NUL */ } /* match a constant character sequence */ int charcmp (const char *buf, const char *match) { int len, i; len = strlength (match); for (i = 0; i < len; ++i) if (buf[i] != match[i]) return 0; return 1; } /* announce a fatal MIDI file format error */ void midi_error (char *msg, unsigned char *bufptr) { unsigned char *ptr; fprintf (stderr, "---> MIDI file error at position %04X (%d): %s\n", (uint16_t) (bufptr - buffer), (uint16_t) (bufptr - buffer), msg); /* print some bytes surrounding the error */ ptr = bufptr - 16; if (ptr < buffer) ptr = buffer; for (; ptr <= bufptr + 16 && ptr < buffer + buflen; ++ptr) fprintf (stderr, ptr == bufptr ? " [%02X] " : "%02X ", *ptr); fprintf (stderr, "\n"); exit (8); } /* check that we have a specified number of bytes left in the buffer */ void chk_bufdata (unsigned char *ptr, unsigned long int len) { if ((unsigned) (ptr + len - buffer) > buflen) midi_error ("data missing", ptr); } /* fetch big-endian numbers */ uint16_t rev_short (uint16_t val) { return ((val & 0xff) << 8) | ((val >> 8) & 0xff); } uint32_t rev_long (uint32_t val) { return (((rev_short ((uint16_t) val) & 0xffff) << 16) | (rev_short ((uint16_t) (val >> 16)) & 0xffff)); } /* write a big-endian 16 bit number to the output file */ void output_word (uint16_t val) { putc ((unsigned char) (val >> 8), outfile); putc ((unsigned char) (val & 0xff), outfile); outfile_bytecount += 2; } /* account for new items in the non-binary output file and generate a newline every so often. */ void outfile_items (int n) { if (!alt_out) outfile_bytecount += n; else outfile_bytecount += (n * 2); outfile_itemcount += n; if (!binaryoutput && outfile_itemcount >= outfile_maxitems) { fprintf (outfile, "\n"); outfile_itemcount = 0; } } /************** process the MIDI file header *****************/ void process_header (void) { struct midi_header *hdr; unsigned int time_division; chk_bufdata (hdrptr, sizeof (struct midi_header)); hdr = (struct midi_header *) hdrptr; if (!charcmp ((char *) hdr->MThd, "MThd")) midi_error ("Missing 'MThd'", hdrptr); num_tracks = rev_short (hdr->number_of_tracks); time_division = rev_short (hdr->time_division); if (time_division < 0x8000) ticks_per_beat = time_division; else ticks_per_beat = ((time_division >> 8) & 0x7f) /* SMTE frames/sec */ *(time_division & 0xff); /* ticks/SMTE frame */ if (logparse) { fprintf (logfile, "Header size %" PRId32 "\n", rev_long (hdr->header_size)); fprintf (logfile, "Format type %d\n", rev_short (hdr->format_type)); fprintf (logfile, "Number of tracks %d\n", num_tracks); fprintf (logfile, "Time division %04X\n", time_division); fprintf (logfile, "Ticks/beat = %d\n", ticks_per_beat); } hdrptr += rev_long (hdr->header_size) + 8; /* point past header to track header, presumably. */ return; } /**************** Process a MIDI track header *******************/ void start_track (int tracknum) { struct track_header *hdr; unsigned long tracklen; chk_bufdata (hdrptr, sizeof (struct track_header)); hdr = (struct track_header *) hdrptr; if (!charcmp ((char *) (hdr->MTrk), "MTrk")) midi_error ("Missing 'MTrk'", hdrptr); tracklen = rev_long (hdr->track_size); if (logparse) fprintf (logfile, "\nTrack %d length %ld\n", tracknum, tracklen); hdrptr += sizeof (struct track_header); /* point past header */ chk_bufdata (hdrptr, tracklen); track[tracknum].trkptr = hdrptr; hdrptr += tracklen; /* point to the start of the next track */ track[tracknum].trkend = hdrptr; /* the point past the end of the track */ } /* Get a MIDI-style variable-length integer */ unsigned long get_varlen (uint8_t ** ptr) { /* Get a 1-4 byte variable-length value and adjust the pointer past it. These are a succession of 7-bit values with a MSB bit of zero marking the end */ unsigned long val; int i, byte; val = 0; for (i = 0; i < 4; ++i) { byte = *(*ptr)++; val = (val << 7) | (byte & 0x7f); if (!(byte & 0x80)) return val; } return val; } /*************** Process the MIDI track data ***************************/ /* Skip in the track for the next "note on", "note off" or "set tempo" command, then record that information in the track status block and return. */ void find_note (int tracknum) { unsigned long int delta_time; int event, chan; int i; int note, velocity, controller, pressure, pitchbend, instrument; int meta_cmd, meta_length; unsigned long int sysex_length; struct track_status *t; char *tag; /* process events */ t = &track[tracknum]; /* our track status structure */ while (t->trkptr < t->trkend) { delta_time = get_varlen (&t->trkptr); if (logparse) { fprintf (logfile, "trk %d ", tracknum); if (delta_time) { fprintf (logfile, "delta time %4ld, ", delta_time); } else { fprintf (logfile, " "); } } t->time += delta_time; if (*t->trkptr < 0x80) event = t->last_event; /* using "running status": same event as before */ else { /* otherwise get new "status" (event type) */ event = *t->trkptr++; } if (event == 0xff) { /* meta-event */ meta_cmd = *t->trkptr++; meta_length = *t->trkptr++; switch (meta_cmd) { case 0x00: if (logparse) fprintf (logfile, "sequence number %d\n", rev_short (*(unsigned short *) t->trkptr)); break; case 0x01: tag = "description"; goto show_text; case 0x02: tag = "copyright"; goto show_text; case 0x03: tag = "track name"; if (tracknum == 0 && !parseonly && !binaryoutput) { /* Incredibly, MIDI has no standard for recording the name of the piece! Track 0's "trackname" is often used for that so we output it to the C file as documentation. */ fprintf (outfile, "// "); for (i = 0; i < meta_length; ++i) { int ch = t->trkptr[i]; fprintf (outfile, "%c", isprint (ch) ? ch : '?'); } fprintf (outfile, "\n"); } goto show_text; case 0x04: tag = "instrument name"; goto show_text; case 0x05: tag = "lyric"; goto show_text; case 0x06: tag = "marked point"; goto show_text; case 0x07: tag = "cue point"; show_text: if (logparse) { fprintf (logfile, "meta cmd %02X, length %d, %s: \"", meta_cmd, meta_length, tag); for (i = 0; i < meta_length; ++i) { int ch = t->trkptr[i]; fprintf (logfile, "%c", isprint (ch) ? ch : '?'); } fprintf (logfile, "\"\n"); } break; case 0x20: if (logparse) fprintf (logfile, "channel prefix %d\n", *t->trkptr); break; case 0x2f: if (logparse) fprintf (logfile, "end of track\n"); break; case 0x51: /* tempo: 3 byte big-endian integer! */ t->cmd = CMD_TEMPO; t->tempo = rev_long (*(unsigned long *) (t->trkptr - 1)) & 0xffffffL; if (logparse) fprintf (logfile, "set tempo %ld usec/qnote\n", t->tempo); t->trkptr += meta_length; return; case 0x54: if (logparse) fprintf (logfile, "SMPTE offset %08" PRIx32 "\n", rev_long (*(unsigned long *) t->trkptr)); break; case 0x58: if (logparse) fprintf (logfile, "time signature %08" PRIx32 "\n", rev_long (*(unsigned long *) t->trkptr)); break; case 0x59: if (logparse) fprintf (logfile, "key signature %04X\n", rev_short (*(unsigned short *) t->trkptr)); break; case 0x7f: tag = "sequencer data"; goto show_hex; default: /* unknown meta command */ tag = "???"; show_hex: if (logparse) { fprintf (logfile, "meta cmd %02X, length %d, %s: ", meta_cmd, meta_length, tag); for (i = 0; i < meta_length; ++i) fprintf (logfile, "%02X ", t->trkptr[i]); fprintf (logfile, "\n"); } break; } t->trkptr += meta_length; } else if (event < 0x80) midi_error ("Unknown MIDI event type", t->trkptr); else { if (event < 0xf0) t->last_event = event; // remember "running status" if not meta or sysex event chan = event & 0xf; t->chan = chan; switch (event >> 4) { case 0x8: t->note = *t->trkptr++; velocity = *t->trkptr++; note_off: if (logparse) fprintf (logfile, "note %d off, chan %d, velocity %d\n", t->note, chan, velocity); if ((1 << chan) & channel_mask) { /* if we're processing this channel */ t->cmd = CMD_STOPNOTE; return; /* stop processing and return */ } break; // else keep looking case 0x9: t->note = *t->trkptr++; velocity = *t->trkptr++; if (velocity == 0) /* some scores use note-on with zero velocity for off! */ goto note_off; t->velocity = velocity; if (logparse) fprintf (logfile, "note %d on, chan %d, velocity %d\n", t->note, chan, velocity); if ((1 << chan) & channel_mask) { /* if we're processing this channel */ t->cmd = CMD_PLAYNOTE; return; /* stop processing and return */ } break; // else keep looking case 0xa: note = *t->trkptr++; velocity = *t->trkptr++; if (logparse) fprintf (logfile, "after-touch %d, %d\n", note, velocity); break; case 0xb: controller = *t->trkptr++; velocity = *t->trkptr++; if (logparse) fprintf (logfile, "control change %d, %d\n", controller, velocity); break; case 0xc: instrument = *t->trkptr++; midi_chan_instrument[chan] = instrument; // record new instrument for this channel if (logparse) fprintf (logfile, "program patch %d\n", instrument); break; case 0xd: pressure = *t->trkptr++; if (logparse) fprintf (logfile, "channel after-touch %d\n", pressure); break; case 0xe: pitchbend = *t->trkptr++ | (*t->trkptr++ << 7); if (logparse) fprintf (logfile, "pitch wheel change %d\n", pitchbend); break; case 0xf: sysex_length = get_varlen (&t->trkptr); if (logparse) fprintf (logfile, "SysEx event %d, %ld bytes\n", event, sysex_length); t->trkptr += sysex_length; break; default: midi_error ("Unknown MIDI command", t->trkptr); } } } t->cmd = CMD_TRACKDONE; /* no more notes to process */ ++tracks_done; } /* generate "stop note" commands for any channels that have them pending */ void gen_stopnotes(void) { struct tonegen_status *tg; for (int tgnum = 0; tgnum < num_tonegens; ++tgnum) { tg = &tonegen[tgnum]; if (tg->stopnote_pending) { if (binaryoutput) { putc (CMD_STOPNOTE | tgnum, outfile); outfile_bytecount += 1; } else { fprintf (outfile, " 0x%02X,", CMD_STOPNOTE | tgnum); outfile_items (1); } tg->stopnote_pending = false; } } } /********************* main ****************************/ int main (int argc, char *argv[]) { int argno; char *filebasename; #define MAXPATH 120 char filename[MAXPATH]; int tracknum; int earliest_tracknum; unsigned long earliest_time; int notes_skipped = 0; char *text; printf ("MIDI2TONES V%s\n(C) 2011-2016 Len Shustek\n(C) 2016 Scott Allen\n", VERSION); if (argc == 1) { /* no arguments */ SayUsage (argv[0]); return 1; } /* process options */ argno = HandleOptions (argc, argv); if (argno == 0) { fprintf (stderr, "\n*** No basefilename given\n\n"); SayUsage (argv[0]); exit (4); } filebasename = argv[argno]; /* if alternate output format, overide options with required values */ if (alt_out) { num_tonegens = 1; do_header = false; instrumentoutput = false; percussion_translate = false; velocityoutput = true; if (!option_n) outfile_maxitems = 16; /* use only lowest channel from mask */ for (int i = 0; i < 16; i++) { if (channel_mask >> i & 1) { channel_mask = 1 << i; alt_out_channel = i; printf ("Using only MIDI channel %d\n", i); break; } } } /* Open the log file */ if (logparse || loggen) { miditones_strlcpy (filename, filebasename, MAXPATH); miditones_strlcat (filename, ".log", MAXPATH); logfile = fopen (filename, "w"); if (!logfile) { fprintf (stderr, "Unable to open log file %s\n", filename); return 1; } fprintf (logfile, "MIDI2TONES V%s log file\n", VERSION); } /* Open the input file */ miditones_strlcpy (filename, filebasename, MAXPATH); miditones_strlcat (filename, ".mid", MAXPATH); infile = fopen (filename, "rb"); if (!infile) { fprintf (stderr, "Unable to open input file %s\n", filename); return 1; } /* Read the whole input file into memory */ fseek (infile, 0, SEEK_END); /* find file size */ buflen = ftell (infile); fseek (infile, 0, SEEK_SET); buffer = (unsigned char *) malloc (buflen + 1); if (!buffer) { fprintf (stderr, "Unable to allocate %ld bytes for the file\n", buflen); return 1; } fread (buffer, buflen, 1, infile); fclose (infile); if (logparse) fprintf (logfile, "Processing %s, %ld bytes\n", filename, buflen); /* Create the output file */ if (!parseonly) { miditones_strlcpy (filename, filebasename, MAXPATH); if (binaryoutput) { miditones_strlcat (filename, ".bin", MAXPATH); outfile = fopen (filename, "wb"); } else { miditones_strlcat (filename, ".c", MAXPATH); outfile = fopen (filename, "w"); } if (!outfile) { fprintf (stderr, "Unable to open output file %s\n", filename); return 1; } file_header.f1 = (velocityoutput ? HDR_F1_VOLUME_PRESENT : 0) | (instrumentoutput ? HDR_F1_INSTRUMENTS_PRESENT : 0) | (percussion_translate ? HDR_F1_PERCUSSION_PRESENT : 0); file_header.num_tgens = num_tonegens; if (!binaryoutput) { /* create header of C file that initializes score data */ if (!alt_out) text = "Playtune bytestream"; else text = "ArduboyTones stream"; time_t rawtime; time (&rawtime); fprintf (outfile, "// %s for file \"%s.mid\" ", text, filebasename); fprintf (outfile, "created by MIDI2TONES V%s on %s", VERSION, asctime (localtime (&rawtime))); print_command_line (argc, argv); if (!alt_out) { if (channel_mask != 0xffff) fprintf (outfile, "// Only the masked channels were processed: %04X\n", channel_mask); } else { fprintf (outfile, "// From channel %d\n", alt_out_channel); } if (keyshift != 0) fprintf (outfile, "// Keyshift was %d chromatic notes\n", keyshift); if (define_progmem) { fprintf (outfile, "#ifdef __AVR__\n"); fprintf (outfile, "#include <avr/pgmspace.h>\n"); fprintf (outfile, "#else\n"); fprintf (outfile, "#define PROGMEM\n"); fprintf (outfile, "#endif\n"); } if (!alt_out) fprintf (outfile, "const byte score[] PROGMEM = {\n"); else fprintf (outfile, "const uint16_t score[] PROGMEM = {\n"); if (do_header) { // write the C initialization for the file header fprintf (outfile, "'P','t', 6, 0x%02X, 0x%02X, ", file_header.f1, file_header.f2); fflush (outfile); file_header_num_tgens_position = ftell (outfile); // remember where the number of tone generators is fprintf (outfile, "%2d, // (Playtune file header)\n", file_header.num_tgens); outfile_bytecount += 6; } } else if (do_header) { // write the binary file header for (int i = 0; i < sizeof (file_header); ++i) putc (((unsigned char *) &file_header)[i], outfile); file_header_num_tgens_position = (char *) &file_header.num_tgens - (char *) &file_header; outfile_bytecount += sizeof (file_header); } } /* process the MIDI file header */ hdrptr = buffer; /* pointer to file and track headers */ process_header (); printf (" Processing %d tracks.\n", num_tracks); if (num_tracks > MAX_TRACKS) midi_error ("Too many tracks", buffer); /* initialize processing of all the tracks */ for (tracknum = 0; tracknum < num_tracks; ++tracknum) { start_track (tracknum); /* process the track header */ find_note (tracknum); /* position to the first note on/off */ /* if we are in "parse only" mode, do the whole track, so we do them one at a time instead of time-synchronized. */ if (parseonly) while (track[tracknum].cmd != CMD_TRACKDONE) find_note (tracknum); } /* Continue processing all tracks, in an order based on the simulated time. This is not unlike multiway merging used for tape sorting algoritms in the 50's! */ tracknum = 0; if (!parseonly) { do { /* while there are still track notes to process */ struct track_status *trk; struct tonegen_status *tg; int tgnum; int count_tracks; unsigned long delta_time, delta_msec; /* Find the track with the earliest event time, and output a delay command if time has advanced. A potential improvement: If there are multiple tracks with the same time, first do the ones with STOPNOTE as the next command, if any. That would help avoid running out of tone generators. In practice, though, most MIDI files do all the STOPNOTEs first anyway, so it won't have much effect. */ earliest_time = 0x7fffffff; /* Usually we start with the track after the one we did last time (tracknum), so that if we run out of tone generators, we have been fair to all the tracks. The alternate "strategy1" says we always start with track 0, which means that we favor early tracks over later ones when there aren't enough tone generators. */ count_tracks = num_tracks; if (strategy1) tracknum = num_tracks; /* beyond the end, so we start with track 0 */ do { if (++tracknum >= num_tracks) tracknum = 0; trk = &track[tracknum]; if (trk->cmd != CMD_TRACKDONE && trk->time < earliest_time) { earliest_time = trk->time; earliest_tracknum = tracknum; } } while (--count_tracks); tracknum = earliest_tracknum; /* the track we picked */ trk = &track[tracknum]; if (loggen) fprintf (logfile, "Earliest time is trk %d, time %ld\n", tracknum, earliest_time); if (earliest_time < timenow) midi_error ("INTERNAL: time went backwards", trk->trkptr); /* If time has advanced, output a "delay" command or frequency/duration pair */ delta_time = earliest_time - timenow; if (delta_time) { if (!alt_out) gen_stopnotes(); /* first check if any tone generators have "stop note" commands pending */ /* Convert ticks to milliseconds based on the current tempo */ unsigned long long temp; temp = ((unsigned long long) delta_time * tempo) / ticks_per_beat; delta_msec = temp / 1000; // get around LCC compiler bug if (loggen) fprintf (logfile, "->Delay %ld msec (%ld ticks)\n", delta_msec, delta_time); if (!alt_out) { if (delta_msec > 0x7fff) midi_error ("INTERNAL: time delta too big", trk->trkptr); /* output a 15-bit delay in big-endian format */ if (binaryoutput) { output_word (delta_msec); } else { fprintf (outfile, " %ld,%ld,", delta_msec >> 8, delta_msec & 0xff); outfile_items (2); } } else { uint16_t freq; bool high_vol; if (delta_msec > 0xffff) midi_error ("INTERNAL: time delta too big", trk->trkptr); /* output a frequency/duration pair */ freq = note_freq[pending_note]; high_vol = (pending_velocity >= velocity_threshold) && (freq != 0); if (binaryoutput) { if (high_vol) freq += TONE_HIGH_VOLUME; output_word (freq); output_word (delta_msec); } else { if (freq_style_a) { fprintf (outfile, " %d", freq); if (high_vol) fprintf (outfile, "+TONE_HIGH_VOLUME"); } else if (freq_style_b) { if (high_vol) freq += TONE_HIGH_VOLUME; fprintf (outfile, " %d", freq); } else { if (freq != 0) { fprintf (outfile, " NOTE_%s%d", note_name[pending_note % 12], pending_note / 12); if (high_vol) putc ('H', outfile); } else { fprintf (outfile, " NOTE_REST"); } } fprintf (outfile, ",%ld,", delta_msec); outfile_items (2); } } } timenow = earliest_time; /* If this track event is "set tempo", just change the global tempo. That affects how we generate "delay" commands. */ if (trk->cmd == CMD_TEMPO) { tempo = trk->tempo; if (loggen) fprintf (logfile, "Tempo changed to %ld usec/qnote\n", tempo); find_note (tracknum); } /* If this track event is "stop note", process it and all subsequent "stop notes" for this track that are happening at the same time. Doing so frees up as many tone generators as possible. */ else if (trk->cmd == CMD_STOPNOTE) do { // stop a note if (!percussion_ignore || trk->chan != PERCUSSION_TRACK) /* if we didn't ignore it as percussion */ for (tgnum = 0; tgnum < num_tonegens; ++tgnum) { /* find which generator is playing it */ tg = &tonegen[tgnum]; if (tg->playing && tg->track == tracknum && tg->note == trk->note) { if (loggen) fprintf (logfile, "->Stop note %d, generator %d, track %d\n", tg->note, tgnum, tracknum); tg->stopnote_pending = true; /* must stop the current note if another doesn't start first */ tg->playing = false; trk->tonegens[tgnum] = false; if (alt_out) pending_note = pending_velocity = 0; } } find_note (tracknum); // use up the note } while (trk->cmd == CMD_STOPNOTE && trk->time == timenow); /* If this track event is "start note", process only it. Don't do more than one, so we allow other tracks their chance at grabbing tone generators. */ else if (trk->cmd == CMD_PLAYNOTE) { if (!percussion_ignore || trk->chan != PERCUSSION_TRACK) { /* ignore percussion track notes if asked to */ bool foundgen = false; /* maybe try to use the same tone generator that this track used last time */ if (strategy2) { tg = &tonegen[trk->preferred_tonegen]; if (!tg->playing) { tgnum = trk->preferred_tonegen; foundgen = true; } } /* if not, then try for a free tone generator that had been playing the same instrument we need */ if (!foundgen) for (tgnum = 0; tgnum < num_tonegens; ++tgnum) { tg = &tonegen[tgnum]; if (!tg->playing && tg->instrument == midi_chan_instrument[trk->chan]) { foundgen = true; break; } } /* if not, then try for any free tone generator */ if (!foundgen) for (tgnum = 0; tgnum < num_tonegens; ++tgnum) { tg = &tonegen[tgnum]; if (!tg->playing) { foundgen = true; break; } } if (foundgen) { int shifted_note; if (tgnum + 1 > num_tonegens_used) num_tonegens_used = tgnum + 1; tg->playing = true; tg->track = tracknum; tg->note = trk->note; tg->stopnote_pending = false; trk->tonegens[tgnum] = true; trk->preferred_tonegen = tgnum; ++note_on_commands; if (tg->instrument != midi_chan_instrument[trk->chan]) { /* new instrument for this generator */ tg->instrument = midi_chan_instrument[trk->chan]; ++instrument_changes; if (loggen) fprintf (logfile, "gen %d changed to instrument %d\n", tgnum, tg->instrument); if (instrumentoutput) { /* output a "change instrument" command */ if (binaryoutput) { putc (CMD_INSTRUMENT | tgnum, outfile); putc (tg->instrument, outfile); } else { fprintf (outfile, " 0x%02X,%d,", CMD_INSTRUMENT | tgnum, tg->instrument); outfile_items (2); } } } if (loggen) fprintf (logfile, "->Start note %d, velocity %d, generator %d, instrument %d, track %d\n", trk->note, trk->velocity, tgnum, tg->instrument, tracknum); if (percussion_translate && trk->chan == PERCUSSION_TRACK) { /* if requested, */ shifted_note = trk->note + 128; // shift percussion notes up to 128..255 } else { /* shift notes as requested */ shifted_note = trk->note + keyshift; } if (!alt_out) { if (shifted_note < 0) shifted_note = 0; if (shifted_note > 127) shifted_note = 127; if (binaryoutput) { putc (CMD_PLAYNOTE | tgnum, outfile); putc (shifted_note, outfile); outfile_bytecount += 2; if (velocityoutput) { putc (trk->velocity, outfile); outfile_bytecount++; } } else { if (!velocityoutput) { fprintf (outfile, " 0x%02X,%d,", CMD_PLAYNOTE | tgnum, shifted_note); outfile_items (2); } else { fprintf (outfile, " 0x%02X,%d,%d,", CMD_PLAYNOTE | tgnum, shifted_note, trk->velocity); outfile_items (3); } } } else { if ((shifted_note < 12) || (shifted_note > 127)) { pending_note = pending_velocity = 0; } else { pending_note = shifted_note; pending_velocity = trk->velocity; } } } else { if (loggen) fprintf (logfile, "----> No free generator, skipping note %d, track %d\n", trk->note, tracknum); ++notes_skipped; } } find_note (tracknum); // use up the note } } /* !parseonly do */ while (tracks_done < num_tracks); if (!alt_out) gen_stopnotes(); /* flush out any pending "stop note" commands */ // generate the end-of-score command and some commentary if (binaryoutput) { if (!alt_out) { putc (gen_restart ? CMD_RESTART : CMD_STOP, outfile); outfile_bytecount++; } else { output_word (gen_restart ? TONES_REPEAT : TONES_END); } } else { if (outfile_itemcount != 0) putc ('\n', outfile); if (!alt_out) { fprintf (outfile, " 0x%02x", gen_restart ? CMD_RESTART : CMD_STOP); outfile_bytecount++; } else { if (freq_style_b) fprintf (outfile, " 0x%04x", gen_restart ? TONES_REPEAT : TONES_END); else fprintf (outfile, " %s", gen_restart ? "TONES_REPEAT" : "TONES_END"); outfile_bytecount += 2; } fprintf (outfile, "\n};\n// This score contains %ld bytes", outfile_bytecount); if (!alt_out) fprintf (outfile, ", and %d tone generator%s used.\n",num_tonegens_used, num_tonegens_used == 1 ? " is" : "s are"); else fprintf (outfile, ".\n"); if (notes_skipped) fprintf (outfile, "// %d notes had to be skipped.\n", notes_skipped); } if (!alt_out) printf (" %s %d tone generators were used.\n", num_tonegens_used < num_tonegens ? "Only" : "All", num_tonegens_used); if (notes_skipped) printf (" %d notes were skipped because there %s.\n", notes_skipped, alt_out ? "is only 1 tone generator" : "weren't enough tone generators"); printf (" %ld bytes of score data were generated.\n", outfile_bytecount); if (loggen) fprintf (logfile, "%d note-on commands, %d instrument changes.\n", note_on_commands, instrument_changes); if (do_header) { // rewrite the file header with the actual number of tone generators used if (fseek (outfile, file_header_num_tgens_position, SEEK_SET) != 0) fprintf (stderr, "Can't seek to number of tone generators in the header\n"); else { if (binaryoutput) putc (num_tonegens_used, outfile); else fprintf (outfile, "%2d", num_tonegens_used); } } fclose (outfile); } /* if (!parseonly) */ if (loggen || logparse) fclose (logfile); printf (" Done.\n"); return 0; }
the_stack_data/78888.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_memmove.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: kehuang <[email protected]> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/10/01 10:51:56 by kehuang #+# #+# */ /* Updated: 2019/10/01 10:51:56 by kehuang ### ########.fr */ /* */ /* ************************************************************************** */ #include <stdlib.h> void *ft_memmove(void *dst, const void *src, size_t len) { size_t i; char *dst_cpy; const char *src_cpy; i = 0; dst_cpy = (char *)dst; src_cpy = (const char *)src; if (dst_cpy < src_cpy) { while (i < len) { dst_cpy[i] = src_cpy[i]; i++; } } else { while (len > 0) { dst_cpy[len - 1] = src_cpy[len - 1]; len--; } } return (dst); }
the_stack_data/242331225.c
#include <stdio.h> int target_func(unsigned char *buf, int size) { printf("buffer:%p, size:%p\n", buf, size); switch (buf[0]) { case 1: if (buf[1] == '\x44') { puts("a"); } break; case 0xff: if (buf[2] == '\xff') { if (buf[1] == '\x44') { puts("b"); } } break; default: break; } return 1; } char data[1024]; int main() { target_func(data, 1024); }
the_stack_data/11142.c
#ifdef MC_USE_OPENGL #include "Engine/Graphics/API.h" #include "ogl_defines.h" #include "glad/glad.h" void OpenGLMessageCallback( unsigned source, unsigned type, unsigned id, unsigned severity, int length, const char* message, const void* userParam) { switch (severity) { case GL_DEBUG_SEVERITY_HIGH: MC_LOG(message); return; case GL_DEBUG_SEVERITY_MEDIUM: MC_LOG(message); return; case GL_DEBUG_SEVERITY_LOW: MC_LOG(message); return; case GL_DEBUG_SEVERITY_NOTIFICATION: MC_LOG(message); return; } MC_ASSERT(false, "Unknown severity level!"); } void graphics_init() { #if defined(MC_DEBUG) && defined(MC_OPENGL_4_5) glEnable(GL_DEBUG_OUTPUT); glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); glDebugMessageCallback(OpenGLMessageCallback, NULL); glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_NOTIFICATION, 0, NULL, GL_FALSE); #endif glEnable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } void graphics_set_viewport(u32 x, u32 y, u32 width, u32 height) { glViewport(x, y, width, height); } void graphics_set_clear_color(f32 r, f32 g, f32 b, f32 a) { glClearColor(r, g, b, a); } void graphics_set_blending_mode(McBlendingMode blending) { switch(blending) { case MC_BLENDING_ADDITIVE: glBlendFunc(GL_ONE, GL_ONE); break; case MC_BLENDING_SUBTRACTIVE: glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); break; case MC_BLENDING_REGULAR: glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); break; } MC_ASSERT(false, "BLENDING MODE NOT SUPPORTED"); } void graphics_toggle_depth_test(b8 toggle) { toggle ? glEnable(GL_DEPTH_TEST) : glDisable(GL_DEPTH_TEST); } void graphics_toggle_backface_culling(b8 toggle) { toggle ? glEnable(GL_CULL_FACE) : glDisable(GL_CULL_FACE); glFrontFace(GL_CCW); glCullFace(GL_BACK); } void graphics_toggle_blending(b8 toggle) { toggle ? glEnable(GL_BLEND) : glDisable(GL_BLEND); } void graphics_clear() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } void graphics_draw_indexed(VertexArray* array) { u32 count = vertex_array_get_index_buffer(array)->count; glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_INT, NULL); glBindTexture(GL_TEXTURE_2D, 0); } void graphics_draw_indexed_count(VertexArray* array, u32 index_count) { u32 count = index_count ? index_count : vertex_array_get_index_buffer(array)->count; glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_INT, NULL); glBindTexture(GL_TEXTURE_2D, 0); } #endif
the_stack_data/97013549.c
/* abort( void ) This file is part of the Public Domain C Library (PDCLib). Permission is granted to use, modify, and / or redistribute at will. */ #include <stdlib.h> #include <signal.h> void abort( void ) { raise( SIGABRT ); exit( EXIT_FAILURE ); }
the_stack_data/36604.c
/** * This file has no copyright assigned and is placed in the Public Domain. * This file is part of the mingw-w64 runtime package. * No warranty is given; refer to the file DISCLAIMER.PD within this package. */ #include <math.h> typedef union ui_f { float f; unsigned int ui; } ui_f; float copysignf(float aX, float aY) { ui_f x,y; x.f=aX; y.f=aY; x.ui= (x.ui & 0x7fffffff) | (y.ui & 0x80000000); return x.f; }
the_stack_data/32949482.c
// Kacper Jastrzebski - 260607 #include <stdio.h> // Functions prototypes: int strccmp(char *str1, char *str2, char ch); int main() { char test_str1[] = "Hello World!"; char test_str2[] = "Hello Wroclaw!"; printf("LAB08_TASK02\n\nExamined strings: '%s' and '%s'\n", test_str1, test_str2); int check = strccmp(test_str1, test_str2, 'W'); char *relation = check < 0 ? "precedes" : check > 0 ? "follows" : "equals"; printf("strccmp(test_str1, test_str2, 'W') : %d -> test_str1 %s test_str2 until delimeter 'W'\n", check, relation); check = strccmp(test_str1, test_str2, '\0'); relation = check < 0 ? "precedes" : check > 0 ? "follows" : "equals"; printf("strccmp(test_str1, test_str2, '\\0') : %d -> test_str1 %s test_str2 until delimeter '\\0'\n", check, relation); check = strccmp(test_str1, test_str2, 'M'); relation = check < 0 ? "precedes" : check > 0 ? "follows" : "equals"; printf("strccmp(test_str1, test_str2, 'M') : %d -> test_str1 %s test_str2 until delimeter 'M'\n", check, relation); check = strccmp(test_str2, test_str1, 'c'); relation = check < 0 ? "precedes" : check > 0 ? "follows" : "equals"; printf("strccmp(test_str2, test_str1, 'c') : %d -> test_str2 %s test_str1 until delimeter 'c'\n", check, relation); return 0; } int strccmp(char *str1, char *str2, char ch) { int pos = 0; while(str1[pos] == str2[pos] && str1[pos] != 0 && str1[pos] != ch) pos++; if(str1[pos] != str2[pos]) return str1[pos]-str2[pos]; return 0; }
the_stack_data/107637.c
/* { dg-lto-options {{ -O -flto -save-temps}} } */ /* { dg-lto-do link } */ int main (void) { return 0; }
the_stack_data/95449179.c
#include <stdio.h> /** * Main program * * @return: Exit code **/ int main(void) { float price; /* Read prices from file */ while (scanf("%f", &price) != EOF) printf("%7.3f\n", price); return 0; }
the_stack_data/120171.c
// COMP1521 19T2 ... lab 1 // cat3: Copy input to output // Mukul Raj Sharma // 04/06/2019 // z5220980 #include <stdio.h> #include <stdlib.h> static void copy (FILE *, FILE *); int main (int argc, char *argv[]) { copy (stdin, stdout); return EXIT_SUCCESS; } // Copy contents of input to output, line by line using fgets/fputs // Assumes both files open in appropriate mode static void copy (FILE *input, FILE *output) { char inp[BUFSIZ]; while(fgets(inp, BUFSIZ, input)) { fputs(inp, output); } }
the_stack_data/153267540.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <assert.h> #define PTR_SIZE 100 #define PTR2_SIZE 10 #define PTR3_SIZE 10 #define OUT_OF_BOUNDS_EXCESS 1 int main() { unsigned int *ptr = (unsigned int*)malloc(PTR_SIZE*sizeof(int)); unsigned int *ptr2 = (unsigned int*)malloc(PTR2_SIZE*sizeof(int)); unsigned int* start_ptr = ptr; unsigned int* start_ptr2 = ptr2; unsigned int *start_ptr3 = (unsigned int*)malloc(PTR_SIZE*sizeof(unsigned int)), *start_ptr4 = start_ptr2; #if 1 *start_ptr = 1; *start_ptr2 = 1; *ptr = 3; *ptr2 = 9; #endif for(unsigned int* new_ptr = start_ptr; new_ptr < start_ptr + PTR_SIZE; new_ptr++) { *new_ptr = 5; printf("%u\n", *new_ptr); } unsigned int* whileptr = NULL; do { unsigned int* doptr = start_ptr; for(unsigned int* forptr2 = (unsigned int*)malloc(PTR_SIZE*sizeof(unsigned int)), *doptr2 = forptr2; doptr2 < (forptr2 + PTR_SIZE) ; doptr2++) { } }while(whileptr != NULL); unsigned int* tempptr = start_ptr; if(whileptr == NULL) { start_ptr += PTR_SIZE - 1; *start_ptr = 10; } start_ptr = tempptr; printf("Final print\n"); for(unsigned int* new_ptr = start_ptr; new_ptr < start_ptr + PTR_SIZE; new_ptr++) { printf("%u\n", *new_ptr); } printf("Final print -end\n"); return 0; }
the_stack_data/82951036.c
int __cost; //int lg_n_helper(int n) { // int i; // int r = 0; // int j; // //__VERIFIER_assume(n > 0); // __VERIFIER_assume(n > 0); // for(i = 1; i != n; i *= 2) { // r ++; // } // return r; //} //int n_lg_n_helper(int n) { // int i; // int r = 0; // for(i = 0; i != n; i++) { // r += lg_n_helper(n); // } // return r; //} int recursive(int n) { __VERIFIER_assume(n >= 2); if (n == 2) { return 2; } return recursive(n/2) + recursive(n/2) + n; } void main(int n) { __VERIFIER_assume(n > 2); __cost = recursive(n); //int bound = lg_n_helper(n); //if (__VERIFIER_nondet_int()) { // __VERIFIER_assert(__cost <= bound); //} }
the_stack_data/1070593.c
/*********************************************************************************** Author: Lucas Pacheco. Description: Code from "The Audio Programming Book", chapter 1, Listing1.9.2 . Date: 21/07/2020. ************************************************************************************/ /* sinetext2.c */ #include <stdio.h> #include <stdlib.h> #include <math.h> /* conditional compilation - is M_PI defined? */ #ifndef M_PI #define M_PI (3.141592654) #endif // !M_PI#define M_PI (3.141592654) /* define our program argument list */ enum {ARG_NAME, ARG_NSAMPS, ARG_FREQ, ARG_SR, ARG_NARGS}; int main(int argc, char **argv) { int i, nsamps; double samp, freq, srate; double twopi = 2.0 * M_PI; double angleincr; if (argc != ARG_NARGS) { fprintf(stderr, "Usage: sinetext2 nsamps freq srate\n"); return 1; } nsamps = atoi(argv[ARG_NSAMPS]); freq = atof(argv[ARG_FREQ]); srate = atof(argv[ARG_SR]); angleincr = twopi * freq / srate; for (i = 0; i < nsamps; i++) { samp = sin(angleincr * i); if (0 > fprintf(stdout, "%.10lf\n", samp)) { fprintf(stderr, "error: unable to print on stdout stream\n"); return 1; } } fprintf(stderr, "done\n"); return 0; }
the_stack_data/173579113.c
/* * Copyright (C) 2010 The Android Open Source Project * All rights reserved. * * 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 OWNER 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. */ #include <pthread.h> #include <errno.h> #include <string.h> #include <stdarg.h> #include <stdio.h> #include <stdlib.h> /* Posix states that EDEADLK should be returned in case a deadlock condition * is detected with a PTHREAD_MUTEX_ERRORCHECK lock() or trylock(), but * GLibc returns EBUSY instead. */ #ifdef HOST # define ERRNO_PTHREAD_EDEADLK EBUSY #else # define ERRNO_PTHREAD_EDEADLK EDEADLK #endif static void __attribute__((noreturn)) panic(const char* func, const char* format, ...) { va_list args; fprintf(stderr, "%s: ", func); va_start(args, format); vfprintf(stderr, format, args); va_end(args); fprintf(stderr, "\n"); exit(1); } #define PANIC(...) panic(__FUNCTION__,__VA_ARGS__) static void __attribute__((noreturn)) error(int errcode, const char* func, const char* format, ...) { va_list args; fprintf(stderr, "%s: ", func); va_start(args, format); vfprintf(stderr, format, args); va_end(args); fprintf(stderr, " error=%d: %s\n", errcode, strerror(errcode)); exit(1); } /* return current time in seconds as floating point value */ static double time_now(void) { struct timespec ts[1]; clock_gettime(CLOCK_MONOTONIC, ts); return (double)ts->tv_sec + ts->tv_nsec/1e9; } static void time_sleep(double delay) { struct timespec ts; int ret; ts.tv_sec = (time_t)delay; ts.tv_nsec = (long)((delay - ts.tv_sec)*1e9); do { ret = nanosleep(&ts, &ts); } while (ret < 0 && errno == EINTR); } #define ERROR(errcode,...) error((errcode),__FUNCTION__,__VA_ARGS__) #define TZERO(cond) \ { int _ret = (cond); if (_ret != 0) ERROR(_ret,"%d:%s", __LINE__, #cond); } #define TTRUE(cond) \ { if (!(cond)) PANIC("%d:%s", __LINE__, #cond); } #define TFALSE(cond) \ { if (!!(cond)) PANIC("%d:%s", __LINE__, #cond); } #define TEXPECT_INT(cond,val) \ { int _ret = (cond); if (_ret != (val)) PANIC("%d:%s returned %d (%d expected)", __LINE__, #cond, _ret, (val)); } /* perform a simple init/lock/unlock/destroy test on a mutex of given attributes */ static void do_test_mutex_1(pthread_mutexattr_t *attr) { int ret; pthread_mutex_t lock[1]; TZERO(pthread_mutex_init(lock, attr)); TZERO(pthread_mutex_lock(lock)); TZERO(pthread_mutex_unlock(lock)); TZERO(pthread_mutex_destroy(lock)); } static void set_mutexattr_type(pthread_mutexattr_t *attr, int type) { int newtype; TZERO(pthread_mutexattr_settype(attr, type)); newtype = ~type; TZERO(pthread_mutexattr_gettype(attr, &newtype)); TEXPECT_INT(newtype,type); } /* simple init/lock/unlock/destroy on all mutex types */ static void do_test_1(void) { int ret, type; pthread_mutexattr_t attr[1]; do_test_mutex_1(NULL); /* non-shared version */ TZERO(pthread_mutexattr_init(attr)); set_mutexattr_type(attr, PTHREAD_MUTEX_NORMAL); do_test_mutex_1(attr); set_mutexattr_type(attr, PTHREAD_MUTEX_RECURSIVE); do_test_mutex_1(attr); set_mutexattr_type(attr, PTHREAD_MUTEX_ERRORCHECK); do_test_mutex_1(attr); TZERO(pthread_mutexattr_destroy(attr)); /* shared version */ TZERO(pthread_mutexattr_init(attr)); TZERO(pthread_mutexattr_setpshared(attr, PTHREAD_PROCESS_SHARED)); set_mutexattr_type(attr, PTHREAD_MUTEX_NORMAL); do_test_mutex_1(attr); set_mutexattr_type(attr, PTHREAD_MUTEX_RECURSIVE); do_test_mutex_1(attr); set_mutexattr_type(attr, PTHREAD_MUTEX_ERRORCHECK); do_test_mutex_1(attr); TZERO(pthread_mutexattr_destroy(attr)); } /* perform init/trylock/unlock/destroy then init/lock/trylock/destroy */ static void do_test_mutex_2(pthread_mutexattr_t *attr) { pthread_mutex_t lock[1]; TZERO(pthread_mutex_init(lock, attr)); TZERO(pthread_mutex_trylock(lock)); TZERO(pthread_mutex_unlock(lock)); TZERO(pthread_mutex_destroy(lock)); TZERO(pthread_mutex_init(lock, attr)); TZERO(pthread_mutex_trylock(lock)); TEXPECT_INT(pthread_mutex_trylock(lock),EBUSY); TZERO(pthread_mutex_unlock(lock)); TZERO(pthread_mutex_destroy(lock)); } static void do_test_mutex_2_rec(pthread_mutexattr_t *attr) { pthread_mutex_t lock[1]; TZERO(pthread_mutex_init(lock, attr)); TZERO(pthread_mutex_trylock(lock)); TZERO(pthread_mutex_unlock(lock)); TZERO(pthread_mutex_destroy(lock)); TZERO(pthread_mutex_init(lock, attr)); TZERO(pthread_mutex_trylock(lock)); TZERO(pthread_mutex_trylock(lock)); TZERO(pthread_mutex_unlock(lock)); TZERO(pthread_mutex_unlock(lock)); TZERO(pthread_mutex_destroy(lock)); } static void do_test_mutex_2_chk(pthread_mutexattr_t *attr) { pthread_mutex_t lock[1]; TZERO(pthread_mutex_init(lock, attr)); TZERO(pthread_mutex_trylock(lock)); TZERO(pthread_mutex_unlock(lock)); TZERO(pthread_mutex_destroy(lock)); TZERO(pthread_mutex_init(lock, attr)); TZERO(pthread_mutex_trylock(lock)); TEXPECT_INT(pthread_mutex_trylock(lock),ERRNO_PTHREAD_EDEADLK); TZERO(pthread_mutex_unlock(lock)); TZERO(pthread_mutex_destroy(lock)); } static void do_test_2(void) { pthread_mutexattr_t attr[1]; do_test_mutex_2(NULL); /* non-shared version */ TZERO(pthread_mutexattr_init(attr)); set_mutexattr_type(attr, PTHREAD_MUTEX_NORMAL); do_test_mutex_2(attr); set_mutexattr_type(attr, PTHREAD_MUTEX_RECURSIVE); do_test_mutex_2_rec(attr); set_mutexattr_type(attr, PTHREAD_MUTEX_ERRORCHECK); do_test_mutex_2_chk(attr); TZERO(pthread_mutexattr_destroy(attr)); /* shared version */ TZERO(pthread_mutexattr_init(attr)); TZERO(pthread_mutexattr_setpshared(attr, PTHREAD_PROCESS_SHARED)); set_mutexattr_type(attr, PTHREAD_MUTEX_NORMAL); do_test_mutex_2(attr); set_mutexattr_type(attr, PTHREAD_MUTEX_RECURSIVE); do_test_mutex_2_rec(attr); set_mutexattr_type(attr, PTHREAD_MUTEX_ERRORCHECK); do_test_mutex_2_chk(attr); TZERO(pthread_mutexattr_destroy(attr)); } /* This is more complex example to test contention of mutexes. * Essentially, what happens is this: * * - main thread creates a mutex and locks it * - it then creates thread 1 and thread 2 * * - it then record the current time, sleep for a specific 'waitDelay' * then unlock the mutex. * * - thread 1 locks() the mutex. It shall be stopped for a least 'waitDelay' * seconds. It then unlocks the mutex. * * - thread 2 trylocks() the mutex. In case of failure (EBUSY), it waits * for a small amount of time (see 'spinDelay') and tries again, until * it succeeds. It then unlocks the mutex. * * The goal of this test is to verify that thread 1 has been stopped * for a sufficiently long time, and that thread 2 has been spinning for * the same minimum period. There is no guarantee as to which thread is * going to acquire the mutex first. */ typedef struct { pthread_mutex_t mutex[1]; double t0; double waitDelay; double spinDelay; } Test3State; static void* do_mutex_test_3_t1(void* arg) { Test3State *s = arg; double t1; TZERO(pthread_mutex_lock(s->mutex)); t1 = time_now(); //DEBUG ONLY: printf("t1-s->t0=%g waitDelay=%g\n", t1-s->t0, s->waitDelay); TTRUE((t1-s->t0) >= s->waitDelay); TZERO(pthread_mutex_unlock(s->mutex)); return NULL; } static void* do_mutex_test_3_t2(void* arg) { Test3State *s = arg; double t1; for (;;) { int ret = pthread_mutex_trylock(s->mutex); if (ret == 0) break; if (ret == EBUSY) { time_sleep(s->spinDelay); continue; } } t1 = time_now(); TTRUE((t1-s->t0) >= s->waitDelay); TZERO(pthread_mutex_unlock(s->mutex)); return NULL; } static void do_test_mutex_3(pthread_mutexattr_t *attr, double delay) { Test3State s[1]; pthread_t th1, th2; void* dummy; TZERO(pthread_mutex_init(s->mutex, attr)); s->waitDelay = delay; s->spinDelay = delay/20.; TZERO(pthread_mutex_lock(s->mutex)); pthread_create(&th1, NULL, do_mutex_test_3_t1, s); pthread_create(&th2, NULL, do_mutex_test_3_t2, s); s->t0 = time_now(); time_sleep(delay); TZERO(pthread_mutex_unlock(s->mutex)); TZERO(pthread_join(th1, &dummy)); TZERO(pthread_join(th2, &dummy)); } static void do_test_3(double delay) { pthread_mutexattr_t attr[1]; do_test_mutex_3(NULL, delay); /* non-shared version */ TZERO(pthread_mutexattr_init(attr)); set_mutexattr_type(attr, PTHREAD_MUTEX_NORMAL); do_test_mutex_3(attr, delay); set_mutexattr_type(attr, PTHREAD_MUTEX_RECURSIVE); do_test_mutex_3(attr, delay); set_mutexattr_type(attr, PTHREAD_MUTEX_ERRORCHECK); do_test_mutex_3(attr, delay); TZERO(pthread_mutexattr_destroy(attr)); /* shared version */ TZERO(pthread_mutexattr_init(attr)); TZERO(pthread_mutexattr_setpshared(attr, PTHREAD_PROCESS_SHARED)); set_mutexattr_type(attr, PTHREAD_MUTEX_NORMAL); do_test_mutex_3(attr, delay); set_mutexattr_type(attr, PTHREAD_MUTEX_RECURSIVE); do_test_mutex_3(attr, delay); set_mutexattr_type(attr, PTHREAD_MUTEX_ERRORCHECK); do_test_mutex_3(attr, delay); TZERO(pthread_mutexattr_destroy(attr)); } int main(void) { do_test_1(); do_test_2(); do_test_3(0.1); return 0; }
the_stack_data/9513836.c
/* * $Id$ * * Copyright (C) 2003 Pascal Brisset, Antoine Drouin * * This file is part of paparazzi. * * paparazzi 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. * * paparazzi 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 paparazzi; see the file COPYING. If not, write to * the Free Software Foundation, 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * */ /** \file main.c * \brief Regroup main functions * */ /* --- stuff pulled in from other files ---- sanjit */ // timer.h mostly #define TCCR1A 0x00 /* sanjit guess from other files */ #define TCCR1B 0x01 /* sanjit guess from other files */ #define TCCR2 0x05 /* sanjit guess from other files */ #define TCNT1 0x1 /* sanjit BIG guess */ #define TCNT1L 0x1 /* sanjit BIG guess */ #define TIFR 0x1 /* sanjit BIG guess */ #define TOV2 0x1 /* sanjit BIG guess */ /*--------------------------------------------- sanjit */ /* #include "link_autopilot.h" //sanjit #include "timer.h" #include "adc.h" #include "pid.h" #include "gps.h" #include "infrared.h" // sanjit #include "downlink.h" #include "nav.h" #include "autopilot.h" #include "estimator.h" #include "if_calib.h" */ /**** similar stuff as for cctask below ------------- */ #define PPRZ_MODE_MANUAL 0 #define PPRZ_MODE_AUTO1 1 #define PPRZ_MODE_AUTO2 2 #define PPRZ_MODE_HOME 3 #define PPRZ_MODE_NB 4 #define TRIM_PPRZ(pprz) (pprz < MIN_PPRZ ? MIN_PPRZ : \ (pprz > MAX_PPRZ ? MAX_PPRZ : \ pprz)) #define TRIM_UPPRZ(pprz) (pprz < 0 ? 0 : \ (pprz > MAX_PPRZ ? MAX_PPRZ : \ pprz)) /* from autopilot.h ends */ /* from include/std.h */ #define FALSE 0 #define TRUE (!FALSE) /* include/std.h */ #define NAV_PITCH 0 /* from var/....h */ /* added by sanjit */ typedef unsigned char uint8_t; typedef short int16_t; typedef unsigned short uint16_t; typedef unsigned char bool_t; /* sanjit add ends */ /* from sw/var/include/airframe.h */ #define ROLL_PGAIN 10000. #define PITCH_OF_ROLL 0.0 #define PITCH_PGAIN 15000. #define MAX_ROLL 0.35 #define MAX_PITCH 0.35 #define MIN_PITCH -0.35 #define CLIMB_PITCH_PGAIN -0.1 #define CLIMB_PITCH_IGAIN 0.025 #define CLIMB_PGAIN -0.03 #define CLIMB_IGAIN 0.1 #define CLIMB_MAX 1. #define CLIMB_LEVEL_GAZ 0.31 #define CLIMB_PITCH_OF_VZ_PGAIN 0.05 #define CLIMB_GAZ_OF_CLIMB 0.2 /* airframe.h */ #define VERTICAL_MODE_MANUAL 0 #define VERTICAL_MODE_AUTO_GAZ 1 #define VERTICAL_MODE_AUTO_CLIMB 2 #define VERTICAL_MODE_AUTO_ALT 3 #define VERTICAL_MODE_NB 4 #define MAX_CLIMB_SUM_ERR 100 #define MAX_PITCH_CLIMB_SUM_ERR 100 /*---- from fly_by_wire/link_autopilot.h */ /* * System clock in MHz. */ #define CLOCK 16 /* !!!!!!!!!!!!!!!!!!! Value used in gen_airframe.ml !!!!!!!!!!!!!!!!! */ #define MAX_PPRZ (600 * CLOCK) #define MIN_PPRZ -MAX_PPRZ /* --- fly_by_wire/link_autopilot.h */ /* from main.c */ // defined below uint8_t pprz_mode; // defined below uint8_t vertical_mode = VERTICAL_MODE_MANUAL; static bool_t low_battery = FALSE; /* end of stuff from main.c */ #define ALTITUDE_PGAIN -0.025 #define LATERAL_MODE_MANUAL 0 uint16_t nav_desired_gaz; uint16_t estimator_flight_time; bool_t launch = FALSE; float nav_pitch = NAV_PITCH; float estimator_z_dot; bool_t auto_pitch = FALSE; /* below vars from pid.c (mostly) */ float desired_roll = 0.; float desired_pitch = 0.; int16_t desired_gaz, desired_aileron, desired_elevator; float roll_pgain = ROLL_PGAIN; float pitch_pgain = PITCH_PGAIN; float pitch_of_roll = PITCH_OF_ROLL; float pitch_of_vz_pgain = CLIMB_PITCH_OF_VZ_PGAIN; float pitch_of_vz = 0.; const float climb_pgain = CLIMB_PGAIN; const float climb_igain = CLIMB_IGAIN; // defined below float desired_climb = 0., pre_climb = 0.; static const float level_gaz = CLIMB_LEVEL_GAZ; float climb_sum_err = 0; float climb_pitch_pgain = CLIMB_PITCH_PGAIN; float climb_pitch_igain = CLIMB_PITCH_IGAIN; float climb_pitch_sum_err = 0.; float max_pitch = MAX_PITCH; float min_pitch = MIN_PITCH; /**** similar stuff as for cctask above ------------- */ // // // FIXME estimator_flight_time should not be manipuled here anymore // /** Define minimal speed for takeoff in m/s */ #define MIN_SPEED_FOR_TAKEOFF 5. uint8_t pprz_mode = PPRZ_MODE_MANUAL; uint8_t vertical_mode = VERTICAL_MODE_MANUAL; uint8_t lateral_mode = LATERAL_MODE_MANUAL; float desired_climb = 0., pre_climb = 0.; float altitude_pgain = ALTITUDE_PGAIN; float estimator_z = 0.0, desired_altitude = 0.0; // init by sanjit /*====================================================================*/ void altitude_control_task(void) { if (pprz_mode == PPRZ_MODE_AUTO2 || pprz_mode == PPRZ_MODE_HOME) { if (vertical_mode == VERTICAL_MODE_AUTO_ALT) { /* inlined below altitude_pid_run(); */ float err = estimator_z - desired_altitude; desired_climb = pre_climb + altitude_pgain * err; if (desired_climb < -CLIMB_MAX) desired_climb = -CLIMB_MAX; if (desired_climb > CLIMB_MAX) desired_climb = CLIMB_MAX; } } } int main() { pprz_mode = 2; vertical_mode = 2; // diff from 3 altitude_control_task(); #ifdef PRET asm(".word 0x22222222"); #endif }
the_stack_data/29748.c
/* 12. Faça uma função que recebe, por parâmetro, a altura (alt) e o sexo de uma pessoa e retorna o seu peso ideal. Para homens, calcular o peso ideal usando a fórmula peso ideal = 72.7 x alt - 58 e, para mulheres, peso ideal = 62.1 x alt - 44.7. */ #include <stdio.h> float pesoIdeal(float altura, char sexo){ float pesoIdeal; if(sexo == 'M' || sexo == 'm'){ pesoIdeal=(62.1 * altura) - 44.7; printf("\nO peso ideal é: %.1f",pesoIdeal); }else if(sexo == 'H' || sexo == 'h'){ pesoIdeal=(72.7 * altura )- 58; printf("\nO peso ideal é: %.1f",pesoIdeal); }else{ printf("Digite um sexo válido\n"); } } int main(int argc, char const *argv[]) { float alt; char sex; printf("Digite seu sexo: "); scanf("%c", &sex); printf("Digite sua altura: "); scanf("%f", &alt); return pesoIdeal(alt, sex); }
the_stack_data/153268556.c
# 1 "/home/giulianob/gcc_git_gnu/gcc/libiberty/getpwd.c" # 1 "/home/giulianob/gcc_git_gnu/build_temp/libiberty//" # 1 "<built-in>" # 1 "<command-line>" # 1 "/usr/include/stdc-predef.h" 1 3 4 # 1 "<command-line>" 2 # 1 "/home/giulianob/gcc_git_gnu/gcc/libiberty/getpwd.c" # 16 "/home/giulianob/gcc_git_gnu/gcc/libiberty/getpwd.c" # 1 "./config.h" 1 # 17 "/home/giulianob/gcc_git_gnu/gcc/libiberty/getpwd.c" 2 # 1 "/usr/include/x86_64-linux-gnu/sys/types.h" 1 3 4 # 25 "/usr/include/x86_64-linux-gnu/sys/types.h" 3 4 # 1 "/usr/include/features.h" 1 3 4 # 461 "/usr/include/features.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/sys/cdefs.h" 1 3 4 # 452 "/usr/include/x86_64-linux-gnu/sys/cdefs.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/wordsize.h" 1 3 4 # 453 "/usr/include/x86_64-linux-gnu/sys/cdefs.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/long-double.h" 1 3 4 # 454 "/usr/include/x86_64-linux-gnu/sys/cdefs.h" 2 3 4 # 462 "/usr/include/features.h" 2 3 4 # 485 "/usr/include/features.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/gnu/stubs.h" 1 3 4 # 10 "/usr/include/x86_64-linux-gnu/gnu/stubs.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/gnu/stubs-64.h" 1 3 4 # 11 "/usr/include/x86_64-linux-gnu/gnu/stubs.h" 2 3 4 # 486 "/usr/include/features.h" 2 3 4 # 26 "/usr/include/x86_64-linux-gnu/sys/types.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/types.h" 1 3 4 # 27 "/usr/include/x86_64-linux-gnu/bits/types.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/wordsize.h" 1 3 4 # 28 "/usr/include/x86_64-linux-gnu/bits/types.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/timesize.h" 1 3 4 # 29 "/usr/include/x86_64-linux-gnu/bits/types.h" 2 3 4 # 31 "/usr/include/x86_64-linux-gnu/bits/types.h" 3 4 typedef unsigned char __u_char; typedef unsigned short int __u_short; typedef unsigned int __u_int; typedef unsigned long int __u_long; typedef signed char __int8_t; typedef unsigned char __uint8_t; typedef signed short int __int16_t; typedef unsigned short int __uint16_t; typedef signed int __int32_t; typedef unsigned int __uint32_t; typedef signed long int __int64_t; typedef unsigned long int __uint64_t; typedef __int8_t __int_least8_t; typedef __uint8_t __uint_least8_t; typedef __int16_t __int_least16_t; typedef __uint16_t __uint_least16_t; typedef __int32_t __int_least32_t; typedef __uint32_t __uint_least32_t; typedef __int64_t __int_least64_t; typedef __uint64_t __uint_least64_t; typedef long int __quad_t; typedef unsigned long int __u_quad_t; typedef long int __intmax_t; typedef unsigned long int __uintmax_t; # 141 "/usr/include/x86_64-linux-gnu/bits/types.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/typesizes.h" 1 3 4 # 142 "/usr/include/x86_64-linux-gnu/bits/types.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/time64.h" 1 3 4 # 143 "/usr/include/x86_64-linux-gnu/bits/types.h" 2 3 4 typedef unsigned long int __dev_t; typedef unsigned int __uid_t; typedef unsigned int __gid_t; typedef unsigned long int __ino_t; typedef unsigned long int __ino64_t; typedef unsigned int __mode_t; typedef unsigned long int __nlink_t; typedef long int __off_t; typedef long int __off64_t; typedef int __pid_t; typedef struct { int __val[2]; } __fsid_t; typedef long int __clock_t; typedef unsigned long int __rlim_t; typedef unsigned long int __rlim64_t; typedef unsigned int __id_t; typedef long int __time_t; typedef unsigned int __useconds_t; typedef long int __suseconds_t; typedef int __daddr_t; typedef int __key_t; typedef int __clockid_t; typedef void * __timer_t; typedef long int __blksize_t; typedef long int __blkcnt_t; typedef long int __blkcnt64_t; typedef unsigned long int __fsblkcnt_t; typedef unsigned long int __fsblkcnt64_t; typedef unsigned long int __fsfilcnt_t; typedef unsigned long int __fsfilcnt64_t; typedef long int __fsword_t; typedef long int __ssize_t; typedef long int __syscall_slong_t; typedef unsigned long int __syscall_ulong_t; typedef __off64_t __loff_t; typedef char *__caddr_t; typedef long int __intptr_t; typedef unsigned int __socklen_t; typedef int __sig_atomic_t; # 30 "/usr/include/x86_64-linux-gnu/sys/types.h" 2 3 4 typedef __u_char u_char; typedef __u_short u_short; typedef __u_int u_int; typedef __u_long u_long; typedef __quad_t quad_t; typedef __u_quad_t u_quad_t; typedef __fsid_t fsid_t; typedef __loff_t loff_t; typedef __ino_t ino_t; typedef __ino64_t ino64_t; typedef __dev_t dev_t; typedef __gid_t gid_t; typedef __mode_t mode_t; typedef __nlink_t nlink_t; typedef __uid_t uid_t; typedef __off_t off_t; typedef __off64_t off64_t; typedef __pid_t pid_t; typedef __id_t id_t; typedef __ssize_t ssize_t; typedef __daddr_t daddr_t; typedef __caddr_t caddr_t; typedef __key_t key_t; # 1 "/usr/include/x86_64-linux-gnu/bits/types/clock_t.h" 1 3 4 typedef __clock_t clock_t; # 127 "/usr/include/x86_64-linux-gnu/sys/types.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/types/clockid_t.h" 1 3 4 typedef __clockid_t clockid_t; # 129 "/usr/include/x86_64-linux-gnu/sys/types.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/types/time_t.h" 1 3 4 typedef __time_t time_t; # 130 "/usr/include/x86_64-linux-gnu/sys/types.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/types/timer_t.h" 1 3 4 typedef __timer_t timer_t; # 131 "/usr/include/x86_64-linux-gnu/sys/types.h" 2 3 4 typedef __useconds_t useconds_t; typedef __suseconds_t suseconds_t; # 1 "/usr/lib/gcc/x86_64-linux-gnu/10/include/stddef.h" 1 3 4 # 209 "/usr/lib/gcc/x86_64-linux-gnu/10/include/stddef.h" 3 4 typedef long unsigned int size_t; # 145 "/usr/include/x86_64-linux-gnu/sys/types.h" 2 3 4 typedef unsigned long int ulong; typedef unsigned short int ushort; typedef unsigned int uint; # 1 "/usr/include/x86_64-linux-gnu/bits/stdint-intn.h" 1 3 4 # 24 "/usr/include/x86_64-linux-gnu/bits/stdint-intn.h" 3 4 typedef __int8_t int8_t; typedef __int16_t int16_t; typedef __int32_t int32_t; typedef __int64_t int64_t; # 156 "/usr/include/x86_64-linux-gnu/sys/types.h" 2 3 4 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 __attribute__ ((__mode__ (__word__))); # 176 "/usr/include/x86_64-linux-gnu/sys/types.h" 3 4 # 1 "/usr/include/endian.h" 1 3 4 # 24 "/usr/include/endian.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/endian.h" 1 3 4 # 35 "/usr/include/x86_64-linux-gnu/bits/endian.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/endianness.h" 1 3 4 # 36 "/usr/include/x86_64-linux-gnu/bits/endian.h" 2 3 4 # 25 "/usr/include/endian.h" 2 3 4 # 35 "/usr/include/endian.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/byteswap.h" 1 3 4 # 33 "/usr/include/x86_64-linux-gnu/bits/byteswap.h" 3 4 static __inline __uint16_t __bswap_16 (__uint16_t __bsx) { return __builtin_bswap16 (__bsx); } static __inline __uint32_t __bswap_32 (__uint32_t __bsx) { return __builtin_bswap32 (__bsx); } # 69 "/usr/include/x86_64-linux-gnu/bits/byteswap.h" 3 4 __extension__ static __inline __uint64_t __bswap_64 (__uint64_t __bsx) { return __builtin_bswap64 (__bsx); } # 36 "/usr/include/endian.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/uintn-identity.h" 1 3 4 # 32 "/usr/include/x86_64-linux-gnu/bits/uintn-identity.h" 3 4 static __inline __uint16_t __uint16_identity (__uint16_t __x) { return __x; } static __inline __uint32_t __uint32_identity (__uint32_t __x) { return __x; } static __inline __uint64_t __uint64_identity (__uint64_t __x) { return __x; } # 37 "/usr/include/endian.h" 2 3 4 # 177 "/usr/include/x86_64-linux-gnu/sys/types.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/sys/select.h" 1 3 4 # 30 "/usr/include/x86_64-linux-gnu/sys/select.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/select.h" 1 3 4 # 22 "/usr/include/x86_64-linux-gnu/bits/select.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/wordsize.h" 1 3 4 # 23 "/usr/include/x86_64-linux-gnu/bits/select.h" 2 3 4 # 31 "/usr/include/x86_64-linux-gnu/sys/select.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/types/sigset_t.h" 1 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/types/__sigset_t.h" 1 3 4 typedef struct { unsigned long int __val[(1024 / (8 * sizeof (unsigned long int)))]; } __sigset_t; # 5 "/usr/include/x86_64-linux-gnu/bits/types/sigset_t.h" 2 3 4 typedef __sigset_t sigset_t; # 34 "/usr/include/x86_64-linux-gnu/sys/select.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/types/struct_timeval.h" 1 3 4 struct timeval { __time_t tv_sec; __suseconds_t tv_usec; }; # 38 "/usr/include/x86_64-linux-gnu/sys/select.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/types/struct_timespec.h" 1 3 4 # 10 "/usr/include/x86_64-linux-gnu/bits/types/struct_timespec.h" 3 4 struct timespec { __time_t tv_sec; __syscall_slong_t tv_nsec; # 26 "/usr/include/x86_64-linux-gnu/bits/types/struct_timespec.h" 3 4 }; # 40 "/usr/include/x86_64-linux-gnu/sys/select.h" 2 3 4 # 49 "/usr/include/x86_64-linux-gnu/sys/select.h" 3 4 typedef long int __fd_mask; # 59 "/usr/include/x86_64-linux-gnu/sys/select.h" 3 4 typedef struct { __fd_mask fds_bits[1024 / (8 * (int) sizeof (__fd_mask))]; } fd_set; typedef __fd_mask fd_mask; # 91 "/usr/include/x86_64-linux-gnu/sys/select.h" 3 4 # 101 "/usr/include/x86_64-linux-gnu/sys/select.h" 3 4 extern int select (int __nfds, fd_set *__restrict __readfds, fd_set *__restrict __writefds, fd_set *__restrict __exceptfds, struct timeval *__restrict __timeout); # 113 "/usr/include/x86_64-linux-gnu/sys/select.h" 3 4 extern int pselect (int __nfds, fd_set *__restrict __readfds, fd_set *__restrict __writefds, fd_set *__restrict __exceptfds, const struct timespec *__restrict __timeout, const __sigset_t *__restrict __sigmask); # 126 "/usr/include/x86_64-linux-gnu/sys/select.h" 3 4 # 180 "/usr/include/x86_64-linux-gnu/sys/types.h" 2 3 4 typedef __blksize_t blksize_t; typedef __blkcnt_t blkcnt_t; typedef __fsblkcnt_t fsblkcnt_t; typedef __fsfilcnt_t fsfilcnt_t; # 219 "/usr/include/x86_64-linux-gnu/sys/types.h" 3 4 typedef __blkcnt64_t blkcnt64_t; typedef __fsblkcnt64_t fsblkcnt64_t; typedef __fsfilcnt64_t fsfilcnt64_t; # 1 "/usr/include/x86_64-linux-gnu/bits/pthreadtypes.h" 1 3 4 # 23 "/usr/include/x86_64-linux-gnu/bits/pthreadtypes.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/thread-shared-types.h" 1 3 4 # 44 "/usr/include/x86_64-linux-gnu/bits/thread-shared-types.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/pthreadtypes-arch.h" 1 3 4 # 21 "/usr/include/x86_64-linux-gnu/bits/pthreadtypes-arch.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/wordsize.h" 1 3 4 # 22 "/usr/include/x86_64-linux-gnu/bits/pthreadtypes-arch.h" 2 3 4 # 45 "/usr/include/x86_64-linux-gnu/bits/thread-shared-types.h" 2 3 4 typedef struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __pthread_list_t; typedef struct __pthread_internal_slist { struct __pthread_internal_slist *__next; } __pthread_slist_t; # 74 "/usr/include/x86_64-linux-gnu/bits/thread-shared-types.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/struct_mutex.h" 1 3 4 # 22 "/usr/include/x86_64-linux-gnu/bits/struct_mutex.h" 3 4 struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; __pthread_list_t __list; # 53 "/usr/include/x86_64-linux-gnu/bits/struct_mutex.h" 3 4 }; # 75 "/usr/include/x86_64-linux-gnu/bits/thread-shared-types.h" 2 3 4 # 87 "/usr/include/x86_64-linux-gnu/bits/thread-shared-types.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/struct_rwlock.h" 1 3 4 # 23 "/usr/include/x86_64-linux-gnu/bits/struct_rwlock.h" 3 4 struct __pthread_rwlock_arch_t { unsigned int __readers; unsigned int __writers; unsigned int __wrphase_futex; unsigned int __writers_futex; unsigned int __pad3; unsigned int __pad4; int __cur_writer; int __shared; signed char __rwelision; unsigned char __pad1[7]; unsigned long int __pad2; unsigned int __flags; # 55 "/usr/include/x86_64-linux-gnu/bits/struct_rwlock.h" 3 4 }; # 88 "/usr/include/x86_64-linux-gnu/bits/thread-shared-types.h" 2 3 4 struct __pthread_cond_s { __extension__ union { __extension__ unsigned long long int __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; __extension__ union { __extension__ unsigned long long int __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2] ; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }; # 24 "/usr/include/x86_64-linux-gnu/bits/pthreadtypes.h" 2 3 4 typedef unsigned long int pthread_t; typedef union { char __size[4]; int __align; } pthread_mutexattr_t; typedef union { char __size[4]; int __align; } pthread_condattr_t; typedef unsigned int pthread_key_t; typedef int pthread_once_t; union pthread_attr_t { char __size[56]; long int __align; }; typedef union pthread_attr_t pthread_attr_t; typedef union { struct __pthread_mutex_s __data; char __size[40]; long int __align; } pthread_mutex_t; typedef union { struct __pthread_cond_s __data; char __size[48]; __extension__ long long int __align; } pthread_cond_t; typedef union { struct __pthread_rwlock_arch_t __data; char __size[56]; long int __align; } pthread_rwlock_t; typedef union { char __size[8]; long int __align; } pthread_rwlockattr_t; typedef volatile int pthread_spinlock_t; typedef union { char __size[32]; long int __align; } pthread_barrier_t; typedef union { char __size[4]; int __align; } pthread_barrierattr_t; # 228 "/usr/include/x86_64-linux-gnu/sys/types.h" 2 3 4 # 20 "/home/giulianob/gcc_git_gnu/gcc/libiberty/getpwd.c" 2 # 1 "/usr/include/errno.h" 1 3 4 # 28 "/usr/include/errno.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/errno.h" 1 3 4 # 26 "/usr/include/x86_64-linux-gnu/bits/errno.h" 3 4 # 1 "/usr/include/linux/errno.h" 1 3 4 # 1 "/usr/include/x86_64-linux-gnu/asm/errno.h" 1 3 4 # 1 "/usr/include/asm-generic/errno.h" 1 3 4 # 1 "/usr/include/asm-generic/errno-base.h" 1 3 4 # 6 "/usr/include/asm-generic/errno.h" 2 3 4 # 2 "/usr/include/x86_64-linux-gnu/asm/errno.h" 2 3 4 # 2 "/usr/include/linux/errno.h" 2 3 4 # 27 "/usr/include/x86_64-linux-gnu/bits/errno.h" 2 3 4 # 29 "/usr/include/errno.h" 2 3 4 extern int *__errno_location (void) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__const__)); extern char *program_invocation_name; extern char *program_invocation_short_name; # 1 "/usr/include/x86_64-linux-gnu/bits/types/error_t.h" 1 3 4 # 22 "/usr/include/x86_64-linux-gnu/bits/types/error_t.h" 3 4 typedef int error_t; # 49 "/usr/include/errno.h" 2 3 4 # 22 "/home/giulianob/gcc_git_gnu/gcc/libiberty/getpwd.c" 2 # 1 "/usr/include/stdlib.h" 1 3 4 # 25 "/usr/include/stdlib.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/libc-header-start.h" 1 3 4 # 26 "/usr/include/stdlib.h" 2 3 4 # 1 "/usr/lib/gcc/x86_64-linux-gnu/10/include/stddef.h" 1 3 4 # 321 "/usr/lib/gcc/x86_64-linux-gnu/10/include/stddef.h" 3 4 typedef int wchar_t; # 32 "/usr/include/stdlib.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/waitflags.h" 1 3 4 # 52 "/usr/include/x86_64-linux-gnu/bits/waitflags.h" 3 4 typedef enum { P_ALL, P_PID, P_PGID } idtype_t; # 40 "/usr/include/stdlib.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/waitstatus.h" 1 3 4 # 41 "/usr/include/stdlib.h" 2 3 4 # 55 "/usr/include/stdlib.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/floatn.h" 1 3 4 # 120 "/usr/include/x86_64-linux-gnu/bits/floatn.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/floatn-common.h" 1 3 4 # 24 "/usr/include/x86_64-linux-gnu/bits/floatn-common.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/long-double.h" 1 3 4 # 25 "/usr/include/x86_64-linux-gnu/bits/floatn-common.h" 2 3 4 # 121 "/usr/include/x86_64-linux-gnu/bits/floatn.h" 2 3 4 # 56 "/usr/include/stdlib.h" 2 3 4 typedef struct { int quot; int rem; } div_t; typedef struct { long int quot; long int rem; } ldiv_t; __extension__ typedef struct { long long int quot; long long int rem; } lldiv_t; # 97 "/usr/include/stdlib.h" 3 4 extern size_t __ctype_get_mb_cur_max (void) __attribute__ ((__nothrow__ , __leaf__)) ; extern double atof (const char *__nptr) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))) ; extern int atoi (const char *__nptr) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))) ; extern long int atol (const char *__nptr) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))) ; __extension__ extern long long int atoll (const char *__nptr) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))) ; extern double strtod (const char *__restrict __nptr, char **__restrict __endptr) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); extern float strtof (const char *__restrict __nptr, char **__restrict __endptr) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); extern long double strtold (const char *__restrict __nptr, char **__restrict __endptr) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); # 140 "/usr/include/stdlib.h" 3 4 extern _Float32 strtof32 (const char *__restrict __nptr, char **__restrict __endptr) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); extern _Float64 strtof64 (const char *__restrict __nptr, char **__restrict __endptr) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); extern _Float128 strtof128 (const char *__restrict __nptr, char **__restrict __endptr) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); extern _Float32x strtof32x (const char *__restrict __nptr, char **__restrict __endptr) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); extern _Float64x strtof64x (const char *__restrict __nptr, char **__restrict __endptr) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); # 176 "/usr/include/stdlib.h" 3 4 extern long int strtol (const char *__restrict __nptr, char **__restrict __endptr, int __base) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); extern unsigned long int strtoul (const char *__restrict __nptr, char **__restrict __endptr, int __base) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); __extension__ extern long long int strtoq (const char *__restrict __nptr, char **__restrict __endptr, int __base) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); __extension__ extern unsigned long long int strtouq (const char *__restrict __nptr, char **__restrict __endptr, int __base) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); __extension__ extern long long int strtoll (const char *__restrict __nptr, char **__restrict __endptr, int __base) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); __extension__ extern unsigned long long int strtoull (const char *__restrict __nptr, char **__restrict __endptr, int __base) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); extern int strfromd (char *__dest, size_t __size, const char *__format, double __f) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (3))); extern int strfromf (char *__dest, size_t __size, const char *__format, float __f) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (3))); extern int strfroml (char *__dest, size_t __size, const char *__format, long double __f) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (3))); # 232 "/usr/include/stdlib.h" 3 4 extern int strfromf32 (char *__dest, size_t __size, const char * __format, _Float32 __f) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (3))); extern int strfromf64 (char *__dest, size_t __size, const char * __format, _Float64 __f) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (3))); extern int strfromf128 (char *__dest, size_t __size, const char * __format, _Float128 __f) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (3))); extern int strfromf32x (char *__dest, size_t __size, const char * __format, _Float32x __f) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (3))); extern int strfromf64x (char *__dest, size_t __size, const char * __format, _Float64x __f) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (3))); # 272 "/usr/include/stdlib.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/types/locale_t.h" 1 3 4 # 22 "/usr/include/x86_64-linux-gnu/bits/types/locale_t.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/types/__locale_t.h" 1 3 4 # 28 "/usr/include/x86_64-linux-gnu/bits/types/__locale_t.h" 3 4 struct __locale_struct { struct __locale_data *__locales[13]; const unsigned short int *__ctype_b; const int *__ctype_tolower; const int *__ctype_toupper; const char *__names[13]; }; typedef struct __locale_struct *__locale_t; # 23 "/usr/include/x86_64-linux-gnu/bits/types/locale_t.h" 2 3 4 typedef __locale_t locale_t; # 273 "/usr/include/stdlib.h" 2 3 4 extern long int strtol_l (const char *__restrict __nptr, char **__restrict __endptr, int __base, locale_t __loc) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 4))); extern unsigned long int strtoul_l (const char *__restrict __nptr, char **__restrict __endptr, int __base, locale_t __loc) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 4))); __extension__ extern long long int strtoll_l (const char *__restrict __nptr, char **__restrict __endptr, int __base, locale_t __loc) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 4))); __extension__ extern unsigned long long int strtoull_l (const char *__restrict __nptr, char **__restrict __endptr, int __base, locale_t __loc) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 4))); extern double strtod_l (const char *__restrict __nptr, char **__restrict __endptr, locale_t __loc) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 3))); extern float strtof_l (const char *__restrict __nptr, char **__restrict __endptr, locale_t __loc) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 3))); extern long double strtold_l (const char *__restrict __nptr, char **__restrict __endptr, locale_t __loc) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 3))); # 316 "/usr/include/stdlib.h" 3 4 extern _Float32 strtof32_l (const char *__restrict __nptr, char **__restrict __endptr, locale_t __loc) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 3))); extern _Float64 strtof64_l (const char *__restrict __nptr, char **__restrict __endptr, locale_t __loc) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 3))); extern _Float128 strtof128_l (const char *__restrict __nptr, char **__restrict __endptr, locale_t __loc) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 3))); extern _Float32x strtof32x_l (const char *__restrict __nptr, char **__restrict __endptr, locale_t __loc) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 3))); extern _Float64x strtof64x_l (const char *__restrict __nptr, char **__restrict __endptr, locale_t __loc) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 3))); # 360 "/usr/include/stdlib.h" 3 4 extern __inline __attribute__ ((__gnu_inline__)) int __attribute__ ((__nothrow__ , __leaf__)) atoi (const char *__nptr) { return (int) strtol (__nptr, (char **) ((void *)0), 10); } extern __inline __attribute__ ((__gnu_inline__)) long int __attribute__ ((__nothrow__ , __leaf__)) atol (const char *__nptr) { return strtol (__nptr, (char **) ((void *)0), 10); } __extension__ extern __inline __attribute__ ((__gnu_inline__)) long long int __attribute__ ((__nothrow__ , __leaf__)) atoll (const char *__nptr) { return strtoll (__nptr, (char **) ((void *)0), 10); } # 385 "/usr/include/stdlib.h" 3 4 extern char *l64a (long int __n) __attribute__ ((__nothrow__ , __leaf__)) ; extern long int a64l (const char *__s) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))) ; # 401 "/usr/include/stdlib.h" 3 4 extern long int random (void) __attribute__ ((__nothrow__ , __leaf__)); extern void srandom (unsigned int __seed) __attribute__ ((__nothrow__ , __leaf__)); extern char *initstate (unsigned int __seed, char *__statebuf, size_t __statelen) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2))); extern char *setstate (char *__statebuf) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); struct random_data { int32_t *fptr; int32_t *rptr; int32_t *state; int rand_type; int rand_deg; int rand_sep; int32_t *end_ptr; }; extern int random_r (struct random_data *__restrict __buf, int32_t *__restrict __result) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); extern int srandom_r (unsigned int __seed, struct random_data *__buf) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2))); extern int initstate_r (unsigned int __seed, char *__restrict __statebuf, size_t __statelen, struct random_data *__restrict __buf) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2, 4))); extern int setstate_r (char *__restrict __statebuf, struct random_data *__restrict __buf) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); extern int rand (void) __attribute__ ((__nothrow__ , __leaf__)); extern void srand (unsigned int __seed) __attribute__ ((__nothrow__ , __leaf__)); extern int rand_r (unsigned int *__seed) __attribute__ ((__nothrow__ , __leaf__)); extern double drand48 (void) __attribute__ ((__nothrow__ , __leaf__)); extern double erand48 (unsigned short int __xsubi[3]) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); extern long int lrand48 (void) __attribute__ ((__nothrow__ , __leaf__)); extern long int nrand48 (unsigned short int __xsubi[3]) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); extern long int mrand48 (void) __attribute__ ((__nothrow__ , __leaf__)); extern long int jrand48 (unsigned short int __xsubi[3]) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); extern void srand48 (long int __seedval) __attribute__ ((__nothrow__ , __leaf__)); extern unsigned short int *seed48 (unsigned short int __seed16v[3]) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); extern void lcong48 (unsigned short int __param[7]) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); struct drand48_data { unsigned short int __x[3]; unsigned short int __old_x[3]; unsigned short int __c; unsigned short int __init; __extension__ unsigned long long int __a; }; extern int drand48_r (struct drand48_data *__restrict __buffer, double *__restrict __result) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); extern int erand48_r (unsigned short int __xsubi[3], struct drand48_data *__restrict __buffer, double *__restrict __result) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); extern int lrand48_r (struct drand48_data *__restrict __buffer, long int *__restrict __result) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); extern int nrand48_r (unsigned short int __xsubi[3], struct drand48_data *__restrict __buffer, long int *__restrict __result) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); extern int mrand48_r (struct drand48_data *__restrict __buffer, long int *__restrict __result) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); extern int jrand48_r (unsigned short int __xsubi[3], struct drand48_data *__restrict __buffer, long int *__restrict __result) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); extern int srand48_r (long int __seedval, struct drand48_data *__buffer) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2))); extern int seed48_r (unsigned short int __seed16v[3], struct drand48_data *__buffer) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); extern int lcong48_r (unsigned short int __param[7], struct drand48_data *__buffer) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); extern void *malloc (size_t __size) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__malloc__)) __attribute__ ((__alloc_size__ (1))) ; extern void *calloc (size_t __nmemb, size_t __size) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__malloc__)) __attribute__ ((__alloc_size__ (1, 2))) ; extern void *realloc (void *__ptr, size_t __size) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__warn_unused_result__)) __attribute__ ((__alloc_size__ (2))); extern void *reallocarray (void *__ptr, size_t __nmemb, size_t __size) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__warn_unused_result__)) __attribute__ ((__alloc_size__ (2, 3))); extern void free (void *__ptr) __attribute__ ((__nothrow__ , __leaf__)); # 1 "/usr/include/alloca.h" 1 3 4 # 24 "/usr/include/alloca.h" 3 4 # 1 "/usr/lib/gcc/x86_64-linux-gnu/10/include/stddef.h" 1 3 4 # 25 "/usr/include/alloca.h" 2 3 4 extern void *alloca (size_t __size) __attribute__ ((__nothrow__ , __leaf__)); # 569 "/usr/include/stdlib.h" 2 3 4 extern void *valloc (size_t __size) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__malloc__)) __attribute__ ((__alloc_size__ (1))) ; extern int posix_memalign (void **__memptr, size_t __alignment, size_t __size) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))) ; extern void *aligned_alloc (size_t __alignment, size_t __size) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__malloc__)) __attribute__ ((__alloc_size__ (2))) ; extern void abort (void) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__noreturn__)); extern int atexit (void (*__func) (void)) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); extern int at_quick_exit (void (*__func) (void)) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); extern int on_exit (void (*__func) (int __status, void *__arg), void *__arg) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); extern void exit (int __status) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__noreturn__)); extern void quick_exit (int __status) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__noreturn__)); extern void _Exit (int __status) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__noreturn__)); extern char *getenv (const char *__name) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))) ; extern char *secure_getenv (const char *__name) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))) ; extern int putenv (char *__string) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); extern int setenv (const char *__name, const char *__value, int __replace) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2))); extern int unsetenv (const char *__name) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); extern int clearenv (void) __attribute__ ((__nothrow__ , __leaf__)); # 675 "/usr/include/stdlib.h" 3 4 extern char *mktemp (char *__template) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); # 688 "/usr/include/stdlib.h" 3 4 extern int mkstemp (char *__template) __attribute__ ((__nonnull__ (1))) ; # 698 "/usr/include/stdlib.h" 3 4 extern int mkstemp64 (char *__template) __attribute__ ((__nonnull__ (1))) ; # 710 "/usr/include/stdlib.h" 3 4 extern int mkstemps (char *__template, int __suffixlen) __attribute__ ((__nonnull__ (1))) ; # 720 "/usr/include/stdlib.h" 3 4 extern int mkstemps64 (char *__template, int __suffixlen) __attribute__ ((__nonnull__ (1))) ; # 731 "/usr/include/stdlib.h" 3 4 extern char *mkdtemp (char *__template) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))) ; # 742 "/usr/include/stdlib.h" 3 4 extern int mkostemp (char *__template, int __flags) __attribute__ ((__nonnull__ (1))) ; # 752 "/usr/include/stdlib.h" 3 4 extern int mkostemp64 (char *__template, int __flags) __attribute__ ((__nonnull__ (1))) ; # 762 "/usr/include/stdlib.h" 3 4 extern int mkostemps (char *__template, int __suffixlen, int __flags) __attribute__ ((__nonnull__ (1))) ; # 774 "/usr/include/stdlib.h" 3 4 extern int mkostemps64 (char *__template, int __suffixlen, int __flags) __attribute__ ((__nonnull__ (1))) ; # 784 "/usr/include/stdlib.h" 3 4 extern int system (const char *__command) ; extern char *canonicalize_file_name (const char *__name) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))) ; # 800 "/usr/include/stdlib.h" 3 4 extern char *realpath (const char *__restrict __name, char *__restrict __resolved) __attribute__ ((__nothrow__ , __leaf__)) ; typedef int (*__compar_fn_t) (const void *, const void *); typedef __compar_fn_t comparison_fn_t; typedef int (*__compar_d_fn_t) (const void *, const void *, void *); extern void *bsearch (const void *__key, const void *__base, size_t __nmemb, size_t __size, __compar_fn_t __compar) __attribute__ ((__nonnull__ (1, 2, 5))) ; # 1 "/usr/include/x86_64-linux-gnu/bits/stdlib-bsearch.h" 1 3 4 # 19 "/usr/include/x86_64-linux-gnu/bits/stdlib-bsearch.h" 3 4 extern __inline __attribute__ ((__gnu_inline__)) void * bsearch (const void *__key, const void *__base, size_t __nmemb, size_t __size, __compar_fn_t __compar) { size_t __l, __u, __idx; const void *__p; int __comparison; __l = 0; __u = __nmemb; while (__l < __u) { __idx = (__l + __u) / 2; __p = (void *) (((const char *) __base) + (__idx * __size)); __comparison = (*__compar) (__key, __p); if (__comparison < 0) __u = __idx; else if (__comparison > 0) __l = __idx + 1; else return (void *) __p; } return ((void *)0); } # 826 "/usr/include/stdlib.h" 2 3 4 extern void qsort (void *__base, size_t __nmemb, size_t __size, __compar_fn_t __compar) __attribute__ ((__nonnull__ (1, 4))); extern void qsort_r (void *__base, size_t __nmemb, size_t __size, __compar_d_fn_t __compar, void *__arg) __attribute__ ((__nonnull__ (1, 4))); extern int abs (int __x) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__const__)) ; extern long int labs (long int __x) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__const__)) ; __extension__ extern long long int llabs (long long int __x) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__const__)) ; extern div_t div (int __numer, int __denom) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__const__)) ; extern ldiv_t ldiv (long int __numer, long int __denom) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__const__)) ; __extension__ extern lldiv_t lldiv (long long int __numer, long long int __denom) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__const__)) ; # 872 "/usr/include/stdlib.h" 3 4 extern char *ecvt (double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (3, 4))) ; extern char *fcvt (double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (3, 4))) ; extern char *gcvt (double __value, int __ndigit, char *__buf) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (3))) ; extern char *qecvt (long double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (3, 4))) ; extern char *qfcvt (long double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (3, 4))) ; extern char *qgcvt (long double __value, int __ndigit, char *__buf) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (3))) ; extern int ecvt_r (double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign, char *__restrict __buf, size_t __len) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (3, 4, 5))); extern int fcvt_r (double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign, char *__restrict __buf, size_t __len) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (3, 4, 5))); extern int qecvt_r (long double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign, char *__restrict __buf, size_t __len) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (3, 4, 5))); extern int qfcvt_r (long double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign, char *__restrict __buf, size_t __len) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (3, 4, 5))); extern int mblen (const char *__s, size_t __n) __attribute__ ((__nothrow__ , __leaf__)); extern int mbtowc (wchar_t *__restrict __pwc, const char *__restrict __s, size_t __n) __attribute__ ((__nothrow__ , __leaf__)); extern int wctomb (char *__s, wchar_t __wchar) __attribute__ ((__nothrow__ , __leaf__)); extern size_t mbstowcs (wchar_t *__restrict __pwcs, const char *__restrict __s, size_t __n) __attribute__ ((__nothrow__ , __leaf__)); extern size_t wcstombs (char *__restrict __s, const wchar_t *__restrict __pwcs, size_t __n) __attribute__ ((__nothrow__ , __leaf__)); extern int rpmatch (const char *__response) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))) ; # 957 "/usr/include/stdlib.h" 3 4 extern int getsubopt (char **__restrict __optionp, char *const *__restrict __tokens, char **__restrict __valuep) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2, 3))) ; extern int posix_openpt (int __oflag) ; extern int grantpt (int __fd) __attribute__ ((__nothrow__ , __leaf__)); extern int unlockpt (int __fd) __attribute__ ((__nothrow__ , __leaf__)); extern char *ptsname (int __fd) __attribute__ ((__nothrow__ , __leaf__)) ; extern int ptsname_r (int __fd, char *__buf, size_t __buflen) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2))); extern int getpt (void); extern int getloadavg (double __loadavg[], int __nelem) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); # 1013 "/usr/include/stdlib.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/stdlib-float.h" 1 3 4 # 24 "/usr/include/x86_64-linux-gnu/bits/stdlib-float.h" 3 4 extern __inline __attribute__ ((__gnu_inline__)) double __attribute__ ((__nothrow__ , __leaf__)) atof (const char *__nptr) { return strtod (__nptr, (char **) ((void *)0)); } # 1014 "/usr/include/stdlib.h" 2 3 4 # 1023 "/usr/include/stdlib.h" 3 4 # 28 "/home/giulianob/gcc_git_gnu/gcc/libiberty/getpwd.c" 2 # 1 "/usr/include/unistd.h" 1 3 4 # 27 "/usr/include/unistd.h" 3 4 # 202 "/usr/include/unistd.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/posix_opt.h" 1 3 4 # 203 "/usr/include/unistd.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/environments.h" 1 3 4 # 22 "/usr/include/x86_64-linux-gnu/bits/environments.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/wordsize.h" 1 3 4 # 23 "/usr/include/x86_64-linux-gnu/bits/environments.h" 2 3 4 # 207 "/usr/include/unistd.h" 2 3 4 # 226 "/usr/include/unistd.h" 3 4 # 1 "/usr/lib/gcc/x86_64-linux-gnu/10/include/stddef.h" 1 3 4 # 227 "/usr/include/unistd.h" 2 3 4 # 267 "/usr/include/unistd.h" 3 4 typedef __intptr_t intptr_t; typedef __socklen_t socklen_t; # 287 "/usr/include/unistd.h" 3 4 extern int access (const char *__name, int __type) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); extern int euidaccess (const char *__name, int __type) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); extern int eaccess (const char *__name, int __type) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); extern int faccessat (int __fd, const char *__file, int __type, int __flag) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2))) ; # 334 "/usr/include/unistd.h" 3 4 extern __off_t lseek (int __fd, __off_t __offset, int __whence) __attribute__ ((__nothrow__ , __leaf__)); # 345 "/usr/include/unistd.h" 3 4 extern __off64_t lseek64 (int __fd, __off64_t __offset, int __whence) __attribute__ ((__nothrow__ , __leaf__)); extern int close (int __fd); extern ssize_t read (int __fd, void *__buf, size_t __nbytes) ; extern ssize_t write (int __fd, const void *__buf, size_t __n) ; # 376 "/usr/include/unistd.h" 3 4 extern ssize_t pread (int __fd, void *__buf, size_t __nbytes, __off_t __offset) ; extern ssize_t pwrite (int __fd, const void *__buf, size_t __n, __off_t __offset) ; # 404 "/usr/include/unistd.h" 3 4 extern ssize_t pread64 (int __fd, void *__buf, size_t __nbytes, __off64_t __offset) ; extern ssize_t pwrite64 (int __fd, const void *__buf, size_t __n, __off64_t __offset) ; extern int pipe (int __pipedes[2]) __attribute__ ((__nothrow__ , __leaf__)) ; extern int pipe2 (int __pipedes[2], int __flags) __attribute__ ((__nothrow__ , __leaf__)) ; # 432 "/usr/include/unistd.h" 3 4 extern unsigned int alarm (unsigned int __seconds) __attribute__ ((__nothrow__ , __leaf__)); # 444 "/usr/include/unistd.h" 3 4 extern unsigned int sleep (unsigned int __seconds); extern __useconds_t ualarm (__useconds_t __value, __useconds_t __interval) __attribute__ ((__nothrow__ , __leaf__)); extern int usleep (__useconds_t __useconds); # 469 "/usr/include/unistd.h" 3 4 extern int pause (void); extern int chown (const char *__file, __uid_t __owner, __gid_t __group) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))) ; extern int fchown (int __fd, __uid_t __owner, __gid_t __group) __attribute__ ((__nothrow__ , __leaf__)) ; extern int lchown (const char *__file, __uid_t __owner, __gid_t __group) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))) ; extern int fchownat (int __fd, const char *__file, __uid_t __owner, __gid_t __group, int __flag) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2))) ; extern int chdir (const char *__path) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))) ; extern int fchdir (int __fd) __attribute__ ((__nothrow__ , __leaf__)) ; # 511 "/usr/include/unistd.h" 3 4 extern char *getcwd (char *__buf, size_t __size) __attribute__ ((__nothrow__ , __leaf__)) ; extern char *get_current_dir_name (void) __attribute__ ((__nothrow__ , __leaf__)); extern char *getwd (char *__buf) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))) __attribute__ ((__deprecated__)) ; extern int dup (int __fd) __attribute__ ((__nothrow__ , __leaf__)) ; extern int dup2 (int __fd, int __fd2) __attribute__ ((__nothrow__ , __leaf__)); extern int dup3 (int __fd, int __fd2, int __flags) __attribute__ ((__nothrow__ , __leaf__)); extern char **__environ; extern char **environ; extern int execve (const char *__path, char *const __argv[], char *const __envp[]) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); extern int fexecve (int __fd, char *const __argv[], char *const __envp[]) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2))); extern int execv (const char *__path, char *const __argv[]) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); extern int execle (const char *__path, const char *__arg, ...) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); extern int execl (const char *__path, const char *__arg, ...) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); extern int execvp (const char *__file, char *const __argv[]) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); extern int execlp (const char *__file, const char *__arg, ...) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); extern int execvpe (const char *__file, char *const __argv[], char *const __envp[]) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); extern int nice (int __inc) __attribute__ ((__nothrow__ , __leaf__)) ; extern void _exit (int __status) __attribute__ ((__noreturn__)); # 1 "/usr/include/x86_64-linux-gnu/bits/confname.h" 1 3 4 # 24 "/usr/include/x86_64-linux-gnu/bits/confname.h" 3 4 enum { _PC_LINK_MAX, _PC_MAX_CANON, _PC_MAX_INPUT, _PC_NAME_MAX, _PC_PATH_MAX, _PC_PIPE_BUF, _PC_CHOWN_RESTRICTED, _PC_NO_TRUNC, _PC_VDISABLE, _PC_SYNC_IO, _PC_ASYNC_IO, _PC_PRIO_IO, _PC_SOCK_MAXBUF, _PC_FILESIZEBITS, _PC_REC_INCR_XFER_SIZE, _PC_REC_MAX_XFER_SIZE, _PC_REC_MIN_XFER_SIZE, _PC_REC_XFER_ALIGN, _PC_ALLOC_SIZE_MIN, _PC_SYMLINK_MAX, _PC_2_SYMLINKS }; enum { _SC_ARG_MAX, _SC_CHILD_MAX, _SC_CLK_TCK, _SC_NGROUPS_MAX, _SC_OPEN_MAX, _SC_STREAM_MAX, _SC_TZNAME_MAX, _SC_JOB_CONTROL, _SC_SAVED_IDS, _SC_REALTIME_SIGNALS, _SC_PRIORITY_SCHEDULING, _SC_TIMERS, _SC_ASYNCHRONOUS_IO, _SC_PRIORITIZED_IO, _SC_SYNCHRONIZED_IO, _SC_FSYNC, _SC_MAPPED_FILES, _SC_MEMLOCK, _SC_MEMLOCK_RANGE, _SC_MEMORY_PROTECTION, _SC_MESSAGE_PASSING, _SC_SEMAPHORES, _SC_SHARED_MEMORY_OBJECTS, _SC_AIO_LISTIO_MAX, _SC_AIO_MAX, _SC_AIO_PRIO_DELTA_MAX, _SC_DELAYTIMER_MAX, _SC_MQ_OPEN_MAX, _SC_MQ_PRIO_MAX, _SC_VERSION, _SC_PAGESIZE, _SC_RTSIG_MAX, _SC_SEM_NSEMS_MAX, _SC_SEM_VALUE_MAX, _SC_SIGQUEUE_MAX, _SC_TIMER_MAX, _SC_BC_BASE_MAX, _SC_BC_DIM_MAX, _SC_BC_SCALE_MAX, _SC_BC_STRING_MAX, _SC_COLL_WEIGHTS_MAX, _SC_EQUIV_CLASS_MAX, _SC_EXPR_NEST_MAX, _SC_LINE_MAX, _SC_RE_DUP_MAX, _SC_CHARCLASS_NAME_MAX, _SC_2_VERSION, _SC_2_C_BIND, _SC_2_C_DEV, _SC_2_FORT_DEV, _SC_2_FORT_RUN, _SC_2_SW_DEV, _SC_2_LOCALEDEF, _SC_PII, _SC_PII_XTI, _SC_PII_SOCKET, _SC_PII_INTERNET, _SC_PII_OSI, _SC_POLL, _SC_SELECT, _SC_UIO_MAXIOV, _SC_IOV_MAX = _SC_UIO_MAXIOV, _SC_PII_INTERNET_STREAM, _SC_PII_INTERNET_DGRAM, _SC_PII_OSI_COTS, _SC_PII_OSI_CLTS, _SC_PII_OSI_M, _SC_T_IOV_MAX, _SC_THREADS, _SC_THREAD_SAFE_FUNCTIONS, _SC_GETGR_R_SIZE_MAX, _SC_GETPW_R_SIZE_MAX, _SC_LOGIN_NAME_MAX, _SC_TTY_NAME_MAX, _SC_THREAD_DESTRUCTOR_ITERATIONS, _SC_THREAD_KEYS_MAX, _SC_THREAD_STACK_MIN, _SC_THREAD_THREADS_MAX, _SC_THREAD_ATTR_STACKADDR, _SC_THREAD_ATTR_STACKSIZE, _SC_THREAD_PRIORITY_SCHEDULING, _SC_THREAD_PRIO_INHERIT, _SC_THREAD_PRIO_PROTECT, _SC_THREAD_PROCESS_SHARED, _SC_NPROCESSORS_CONF, _SC_NPROCESSORS_ONLN, _SC_PHYS_PAGES, _SC_AVPHYS_PAGES, _SC_ATEXIT_MAX, _SC_PASS_MAX, _SC_XOPEN_VERSION, _SC_XOPEN_XCU_VERSION, _SC_XOPEN_UNIX, _SC_XOPEN_CRYPT, _SC_XOPEN_ENH_I18N, _SC_XOPEN_SHM, _SC_2_CHAR_TERM, _SC_2_C_VERSION, _SC_2_UPE, _SC_XOPEN_XPG2, _SC_XOPEN_XPG3, _SC_XOPEN_XPG4, _SC_CHAR_BIT, _SC_CHAR_MAX, _SC_CHAR_MIN, _SC_INT_MAX, _SC_INT_MIN, _SC_LONG_BIT, _SC_WORD_BIT, _SC_MB_LEN_MAX, _SC_NZERO, _SC_SSIZE_MAX, _SC_SCHAR_MAX, _SC_SCHAR_MIN, _SC_SHRT_MAX, _SC_SHRT_MIN, _SC_UCHAR_MAX, _SC_UINT_MAX, _SC_ULONG_MAX, _SC_USHRT_MAX, _SC_NL_ARGMAX, _SC_NL_LANGMAX, _SC_NL_MSGMAX, _SC_NL_NMAX, _SC_NL_SETMAX, _SC_NL_TEXTMAX, _SC_XBS5_ILP32_OFF32, _SC_XBS5_ILP32_OFFBIG, _SC_XBS5_LP64_OFF64, _SC_XBS5_LPBIG_OFFBIG, _SC_XOPEN_LEGACY, _SC_XOPEN_REALTIME, _SC_XOPEN_REALTIME_THREADS, _SC_ADVISORY_INFO, _SC_BARRIERS, _SC_BASE, _SC_C_LANG_SUPPORT, _SC_C_LANG_SUPPORT_R, _SC_CLOCK_SELECTION, _SC_CPUTIME, _SC_THREAD_CPUTIME, _SC_DEVICE_IO, _SC_DEVICE_SPECIFIC, _SC_DEVICE_SPECIFIC_R, _SC_FD_MGMT, _SC_FIFO, _SC_PIPE, _SC_FILE_ATTRIBUTES, _SC_FILE_LOCKING, _SC_FILE_SYSTEM, _SC_MONOTONIC_CLOCK, _SC_MULTI_PROCESS, _SC_SINGLE_PROCESS, _SC_NETWORKING, _SC_READER_WRITER_LOCKS, _SC_SPIN_LOCKS, _SC_REGEXP, _SC_REGEX_VERSION, _SC_SHELL, _SC_SIGNALS, _SC_SPAWN, _SC_SPORADIC_SERVER, _SC_THREAD_SPORADIC_SERVER, _SC_SYSTEM_DATABASE, _SC_SYSTEM_DATABASE_R, _SC_TIMEOUTS, _SC_TYPED_MEMORY_OBJECTS, _SC_USER_GROUPS, _SC_USER_GROUPS_R, _SC_2_PBS, _SC_2_PBS_ACCOUNTING, _SC_2_PBS_LOCATE, _SC_2_PBS_MESSAGE, _SC_2_PBS_TRACK, _SC_SYMLOOP_MAX, _SC_STREAMS, _SC_2_PBS_CHECKPOINT, _SC_V6_ILP32_OFF32, _SC_V6_ILP32_OFFBIG, _SC_V6_LP64_OFF64, _SC_V6_LPBIG_OFFBIG, _SC_HOST_NAME_MAX, _SC_TRACE, _SC_TRACE_EVENT_FILTER, _SC_TRACE_INHERIT, _SC_TRACE_LOG, _SC_LEVEL1_ICACHE_SIZE, _SC_LEVEL1_ICACHE_ASSOC, _SC_LEVEL1_ICACHE_LINESIZE, _SC_LEVEL1_DCACHE_SIZE, _SC_LEVEL1_DCACHE_ASSOC, _SC_LEVEL1_DCACHE_LINESIZE, _SC_LEVEL2_CACHE_SIZE, _SC_LEVEL2_CACHE_ASSOC, _SC_LEVEL2_CACHE_LINESIZE, _SC_LEVEL3_CACHE_SIZE, _SC_LEVEL3_CACHE_ASSOC, _SC_LEVEL3_CACHE_LINESIZE, _SC_LEVEL4_CACHE_SIZE, _SC_LEVEL4_CACHE_ASSOC, _SC_LEVEL4_CACHE_LINESIZE, _SC_IPV6 = _SC_LEVEL1_ICACHE_SIZE + 50, _SC_RAW_SOCKETS, _SC_V7_ILP32_OFF32, _SC_V7_ILP32_OFFBIG, _SC_V7_LP64_OFF64, _SC_V7_LPBIG_OFFBIG, _SC_SS_REPL_MAX, _SC_TRACE_EVENT_NAME_MAX, _SC_TRACE_NAME_MAX, _SC_TRACE_SYS_MAX, _SC_TRACE_USER_EVENT_MAX, _SC_XOPEN_STREAMS, _SC_THREAD_ROBUST_PRIO_INHERIT, _SC_THREAD_ROBUST_PRIO_PROTECT }; enum { _CS_PATH, _CS_V6_WIDTH_RESTRICTED_ENVS, _CS_GNU_LIBC_VERSION, _CS_GNU_LIBPTHREAD_VERSION, _CS_V5_WIDTH_RESTRICTED_ENVS, _CS_V7_WIDTH_RESTRICTED_ENVS, _CS_LFS_CFLAGS = 1000, _CS_LFS_LDFLAGS, _CS_LFS_LIBS, _CS_LFS_LINTFLAGS, _CS_LFS64_CFLAGS, _CS_LFS64_LDFLAGS, _CS_LFS64_LIBS, _CS_LFS64_LINTFLAGS, _CS_XBS5_ILP32_OFF32_CFLAGS = 1100, _CS_XBS5_ILP32_OFF32_LDFLAGS, _CS_XBS5_ILP32_OFF32_LIBS, _CS_XBS5_ILP32_OFF32_LINTFLAGS, _CS_XBS5_ILP32_OFFBIG_CFLAGS, _CS_XBS5_ILP32_OFFBIG_LDFLAGS, _CS_XBS5_ILP32_OFFBIG_LIBS, _CS_XBS5_ILP32_OFFBIG_LINTFLAGS, _CS_XBS5_LP64_OFF64_CFLAGS, _CS_XBS5_LP64_OFF64_LDFLAGS, _CS_XBS5_LP64_OFF64_LIBS, _CS_XBS5_LP64_OFF64_LINTFLAGS, _CS_XBS5_LPBIG_OFFBIG_CFLAGS, _CS_XBS5_LPBIG_OFFBIG_LDFLAGS, _CS_XBS5_LPBIG_OFFBIG_LIBS, _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS, _CS_POSIX_V6_ILP32_OFF32_CFLAGS, _CS_POSIX_V6_ILP32_OFF32_LDFLAGS, _CS_POSIX_V6_ILP32_OFF32_LIBS, _CS_POSIX_V6_ILP32_OFF32_LINTFLAGS, _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS, _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS, _CS_POSIX_V6_ILP32_OFFBIG_LIBS, _CS_POSIX_V6_ILP32_OFFBIG_LINTFLAGS, _CS_POSIX_V6_LP64_OFF64_CFLAGS, _CS_POSIX_V6_LP64_OFF64_LDFLAGS, _CS_POSIX_V6_LP64_OFF64_LIBS, _CS_POSIX_V6_LP64_OFF64_LINTFLAGS, _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS, _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS, _CS_POSIX_V6_LPBIG_OFFBIG_LIBS, _CS_POSIX_V6_LPBIG_OFFBIG_LINTFLAGS, _CS_POSIX_V7_ILP32_OFF32_CFLAGS, _CS_POSIX_V7_ILP32_OFF32_LDFLAGS, _CS_POSIX_V7_ILP32_OFF32_LIBS, _CS_POSIX_V7_ILP32_OFF32_LINTFLAGS, _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS, _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS, _CS_POSIX_V7_ILP32_OFFBIG_LIBS, _CS_POSIX_V7_ILP32_OFFBIG_LINTFLAGS, _CS_POSIX_V7_LP64_OFF64_CFLAGS, _CS_POSIX_V7_LP64_OFF64_LDFLAGS, _CS_POSIX_V7_LP64_OFF64_LIBS, _CS_POSIX_V7_LP64_OFF64_LINTFLAGS, _CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS, _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS, _CS_POSIX_V7_LPBIG_OFFBIG_LIBS, _CS_POSIX_V7_LPBIG_OFFBIG_LINTFLAGS, _CS_V6_ENV, _CS_V7_ENV }; # 610 "/usr/include/unistd.h" 2 3 4 extern long int pathconf (const char *__path, int __name) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); extern long int fpathconf (int __fd, int __name) __attribute__ ((__nothrow__ , __leaf__)); extern long int sysconf (int __name) __attribute__ ((__nothrow__ , __leaf__)); extern size_t confstr (int __name, char *__buf, size_t __len) __attribute__ ((__nothrow__ , __leaf__)); extern __pid_t getpid (void) __attribute__ ((__nothrow__ , __leaf__)); extern __pid_t getppid (void) __attribute__ ((__nothrow__ , __leaf__)); extern __pid_t getpgrp (void) __attribute__ ((__nothrow__ , __leaf__)); extern __pid_t __getpgid (__pid_t __pid) __attribute__ ((__nothrow__ , __leaf__)); extern __pid_t getpgid (__pid_t __pid) __attribute__ ((__nothrow__ , __leaf__)); extern int setpgid (__pid_t __pid, __pid_t __pgid) __attribute__ ((__nothrow__ , __leaf__)); # 660 "/usr/include/unistd.h" 3 4 extern int setpgrp (void) __attribute__ ((__nothrow__ , __leaf__)); extern __pid_t setsid (void) __attribute__ ((__nothrow__ , __leaf__)); extern __pid_t getsid (__pid_t __pid) __attribute__ ((__nothrow__ , __leaf__)); extern __uid_t getuid (void) __attribute__ ((__nothrow__ , __leaf__)); extern __uid_t geteuid (void) __attribute__ ((__nothrow__ , __leaf__)); extern __gid_t getgid (void) __attribute__ ((__nothrow__ , __leaf__)); extern __gid_t getegid (void) __attribute__ ((__nothrow__ , __leaf__)); extern int getgroups (int __size, __gid_t __list[]) __attribute__ ((__nothrow__ , __leaf__)) ; extern int group_member (__gid_t __gid) __attribute__ ((__nothrow__ , __leaf__)); extern int setuid (__uid_t __uid) __attribute__ ((__nothrow__ , __leaf__)) ; extern int setreuid (__uid_t __ruid, __uid_t __euid) __attribute__ ((__nothrow__ , __leaf__)) ; extern int seteuid (__uid_t __uid) __attribute__ ((__nothrow__ , __leaf__)) ; extern int setgid (__gid_t __gid) __attribute__ ((__nothrow__ , __leaf__)) ; extern int setregid (__gid_t __rgid, __gid_t __egid) __attribute__ ((__nothrow__ , __leaf__)) ; extern int setegid (__gid_t __gid) __attribute__ ((__nothrow__ , __leaf__)) ; extern int getresuid (__uid_t *__ruid, __uid_t *__euid, __uid_t *__suid) __attribute__ ((__nothrow__ , __leaf__)); extern int getresgid (__gid_t *__rgid, __gid_t *__egid, __gid_t *__sgid) __attribute__ ((__nothrow__ , __leaf__)); extern int setresuid (__uid_t __ruid, __uid_t __euid, __uid_t __suid) __attribute__ ((__nothrow__ , __leaf__)) ; extern int setresgid (__gid_t __rgid, __gid_t __egid, __gid_t __sgid) __attribute__ ((__nothrow__ , __leaf__)) ; extern __pid_t fork (void) __attribute__ ((__nothrow__)); extern __pid_t vfork (void) __attribute__ ((__nothrow__ , __leaf__)); extern char *ttyname (int __fd) __attribute__ ((__nothrow__ , __leaf__)); extern int ttyname_r (int __fd, char *__buf, size_t __buflen) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2))) ; extern int isatty (int __fd) __attribute__ ((__nothrow__ , __leaf__)); extern int ttyslot (void) __attribute__ ((__nothrow__ , __leaf__)); extern int link (const char *__from, const char *__to) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))) ; extern int linkat (int __fromfd, const char *__from, int __tofd, const char *__to, int __flags) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2, 4))) ; extern int symlink (const char *__from, const char *__to) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))) ; extern ssize_t readlink (const char *__restrict __path, char *__restrict __buf, size_t __len) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))) ; extern int symlinkat (const char *__from, int __tofd, const char *__to) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 3))) ; extern ssize_t readlinkat (int __fd, const char *__restrict __path, char *__restrict __buf, size_t __len) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2, 3))) ; extern int unlink (const char *__name) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); extern int unlinkat (int __fd, const char *__name, int __flag) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2))); extern int rmdir (const char *__path) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); extern __pid_t tcgetpgrp (int __fd) __attribute__ ((__nothrow__ , __leaf__)); extern int tcsetpgrp (int __fd, __pid_t __pgrp_id) __attribute__ ((__nothrow__ , __leaf__)); extern char *getlogin (void); extern int getlogin_r (char *__name, size_t __name_len) __attribute__ ((__nonnull__ (1))); extern int setlogin (const char *__name) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); # 1 "/usr/include/x86_64-linux-gnu/bits/getopt_posix.h" 1 3 4 # 27 "/usr/include/x86_64-linux-gnu/bits/getopt_posix.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/getopt_core.h" 1 3 4 # 28 "/usr/include/x86_64-linux-gnu/bits/getopt_core.h" 3 4 extern char *optarg; # 50 "/usr/include/x86_64-linux-gnu/bits/getopt_core.h" 3 4 extern int optind; extern int opterr; extern int optopt; # 91 "/usr/include/x86_64-linux-gnu/bits/getopt_core.h" 3 4 extern int getopt (int ___argc, char *const *___argv, const char *__shortopts) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2, 3))); # 28 "/usr/include/x86_64-linux-gnu/bits/getopt_posix.h" 2 3 4 # 49 "/usr/include/x86_64-linux-gnu/bits/getopt_posix.h" 3 4 # 870 "/usr/include/unistd.h" 2 3 4 extern int gethostname (char *__name, size_t __len) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); extern int sethostname (const char *__name, size_t __len) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))) ; extern int sethostid (long int __id) __attribute__ ((__nothrow__ , __leaf__)) ; extern int getdomainname (char *__name, size_t __len) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))) ; extern int setdomainname (const char *__name, size_t __len) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))) ; extern int vhangup (void) __attribute__ ((__nothrow__ , __leaf__)); extern int revoke (const char *__file) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))) ; extern int profil (unsigned short int *__sample_buffer, size_t __size, size_t __offset, unsigned int __scale) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); extern int acct (const char *__name) __attribute__ ((__nothrow__ , __leaf__)); extern char *getusershell (void) __attribute__ ((__nothrow__ , __leaf__)); extern void endusershell (void) __attribute__ ((__nothrow__ , __leaf__)); extern void setusershell (void) __attribute__ ((__nothrow__ , __leaf__)); extern int daemon (int __nochdir, int __noclose) __attribute__ ((__nothrow__ , __leaf__)) ; extern int chroot (const char *__path) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))) ; extern char *getpass (const char *__prompt) __attribute__ ((__nonnull__ (1))); extern int fsync (int __fd); extern int syncfs (int __fd) __attribute__ ((__nothrow__ , __leaf__)); extern long int gethostid (void); extern void sync (void) __attribute__ ((__nothrow__ , __leaf__)); extern int getpagesize (void) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__const__)); extern int getdtablesize (void) __attribute__ ((__nothrow__ , __leaf__)); # 991 "/usr/include/unistd.h" 3 4 extern int truncate (const char *__file, __off_t __length) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))) ; # 1003 "/usr/include/unistd.h" 3 4 extern int truncate64 (const char *__file, __off64_t __length) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))) ; # 1014 "/usr/include/unistd.h" 3 4 extern int ftruncate (int __fd, __off_t __length) __attribute__ ((__nothrow__ , __leaf__)) ; # 1024 "/usr/include/unistd.h" 3 4 extern int ftruncate64 (int __fd, __off64_t __length) __attribute__ ((__nothrow__ , __leaf__)) ; # 1035 "/usr/include/unistd.h" 3 4 extern int brk (void *__addr) __attribute__ ((__nothrow__ , __leaf__)) ; extern void *sbrk (intptr_t __delta) __attribute__ ((__nothrow__ , __leaf__)); # 1056 "/usr/include/unistd.h" 3 4 extern long int syscall (long int __sysno, ...) __attribute__ ((__nothrow__ , __leaf__)); # 1079 "/usr/include/unistd.h" 3 4 extern int lockf (int __fd, int __cmd, __off_t __len) ; # 1089 "/usr/include/unistd.h" 3 4 extern int lockf64 (int __fd, int __cmd, __off64_t __len) ; # 1107 "/usr/include/unistd.h" 3 4 ssize_t copy_file_range (int __infd, __off64_t *__pinoff, int __outfd, __off64_t *__poutoff, size_t __length, unsigned int __flags); extern int fdatasync (int __fildes); # 1124 "/usr/include/unistd.h" 3 4 extern char *crypt (const char *__key, const char *__salt) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); extern void swab (const void *__restrict __from, void *__restrict __to, ssize_t __n) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); # 1161 "/usr/include/unistd.h" 3 4 int getentropy (void *__buffer, size_t __length) ; # 1170 "/usr/include/unistd.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/unistd_ext.h" 1 3 4 # 34 "/usr/include/x86_64-linux-gnu/bits/unistd_ext.h" 3 4 extern __pid_t gettid (void) __attribute__ ((__nothrow__ , __leaf__)); # 1171 "/usr/include/unistd.h" 2 3 4 # 31 "/home/giulianob/gcc_git_gnu/gcc/libiberty/getpwd.c" 2 # 1 "/usr/include/x86_64-linux-gnu/sys/param.h" 1 3 4 # 23 "/usr/include/x86_64-linux-gnu/sys/param.h" 3 4 # 1 "/usr/lib/gcc/x86_64-linux-gnu/10/include/stddef.h" 1 3 4 # 24 "/usr/include/x86_64-linux-gnu/sys/param.h" 2 3 4 # 1 "/usr/lib/gcc/x86_64-linux-gnu/10/include/limits.h" 1 3 4 # 34 "/usr/lib/gcc/x86_64-linux-gnu/10/include/limits.h" 3 4 # 1 "/usr/lib/gcc/x86_64-linux-gnu/10/include/syslimits.h" 1 3 4 # 1 "/usr/lib/gcc/x86_64-linux-gnu/10/include/limits.h" 1 3 4 # 195 "/usr/lib/gcc/x86_64-linux-gnu/10/include/limits.h" 3 4 # 1 "/usr/include/limits.h" 1 3 4 # 26 "/usr/include/limits.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/libc-header-start.h" 1 3 4 # 27 "/usr/include/limits.h" 2 3 4 # 183 "/usr/include/limits.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/posix1_lim.h" 1 3 4 # 27 "/usr/include/x86_64-linux-gnu/bits/posix1_lim.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/wordsize.h" 1 3 4 # 28 "/usr/include/x86_64-linux-gnu/bits/posix1_lim.h" 2 3 4 # 161 "/usr/include/x86_64-linux-gnu/bits/posix1_lim.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/local_lim.h" 1 3 4 # 38 "/usr/include/x86_64-linux-gnu/bits/local_lim.h" 3 4 # 1 "/usr/include/linux/limits.h" 1 3 4 # 39 "/usr/include/x86_64-linux-gnu/bits/local_lim.h" 2 3 4 # 162 "/usr/include/x86_64-linux-gnu/bits/posix1_lim.h" 2 3 4 # 184 "/usr/include/limits.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/posix2_lim.h" 1 3 4 # 188 "/usr/include/limits.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/xopen_lim.h" 1 3 4 # 64 "/usr/include/x86_64-linux-gnu/bits/xopen_lim.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/uio_lim.h" 1 3 4 # 65 "/usr/include/x86_64-linux-gnu/bits/xopen_lim.h" 2 3 4 # 192 "/usr/include/limits.h" 2 3 4 # 196 "/usr/lib/gcc/x86_64-linux-gnu/10/include/limits.h" 2 3 4 # 8 "/usr/lib/gcc/x86_64-linux-gnu/10/include/syslimits.h" 2 3 4 # 35 "/usr/lib/gcc/x86_64-linux-gnu/10/include/limits.h" 2 3 4 # 27 "/usr/include/x86_64-linux-gnu/sys/param.h" 2 3 4 # 1 "/usr/include/signal.h" 1 3 4 # 27 "/usr/include/signal.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/signum.h" 1 3 4 # 26 "/usr/include/x86_64-linux-gnu/bits/signum.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/signum-generic.h" 1 3 4 # 27 "/usr/include/x86_64-linux-gnu/bits/signum.h" 2 3 4 # 31 "/usr/include/signal.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/types/sig_atomic_t.h" 1 3 4 typedef __sig_atomic_t sig_atomic_t; # 33 "/usr/include/signal.h" 2 3 4 # 57 "/usr/include/signal.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/types/siginfo_t.h" 1 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/wordsize.h" 1 3 4 # 5 "/usr/include/x86_64-linux-gnu/bits/types/siginfo_t.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/types/__sigval_t.h" 1 3 4 # 24 "/usr/include/x86_64-linux-gnu/bits/types/__sigval_t.h" 3 4 union sigval { int sival_int; void *sival_ptr; }; typedef union sigval __sigval_t; # 7 "/usr/include/x86_64-linux-gnu/bits/types/siginfo_t.h" 2 3 4 # 16 "/usr/include/x86_64-linux-gnu/bits/types/siginfo_t.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/siginfo-arch.h" 1 3 4 # 17 "/usr/include/x86_64-linux-gnu/bits/types/siginfo_t.h" 2 3 4 # 36 "/usr/include/x86_64-linux-gnu/bits/types/siginfo_t.h" 3 4 typedef struct { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[((128 / sizeof (int)) - 4)]; struct { __pid_t si_pid; __uid_t si_uid; } _kill; struct { int si_tid; int si_overrun; __sigval_t si_sigval; } _timer; struct { __pid_t si_pid; __uid_t si_uid; __sigval_t si_sigval; } _rt; struct { __pid_t si_pid; __uid_t si_uid; int si_status; __clock_t si_utime; __clock_t si_stime; } _sigchld; struct { void *si_addr; short int si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; __uint32_t _pkey; } _bounds; } _sigfault; struct { long int si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } siginfo_t ; # 58 "/usr/include/signal.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/siginfo-consts.h" 1 3 4 # 35 "/usr/include/x86_64-linux-gnu/bits/siginfo-consts.h" 3 4 enum { SI_ASYNCNL = -60, SI_DETHREAD = -7, SI_TKILL, SI_SIGIO, SI_ASYNCIO, SI_MESGQ, SI_TIMER, SI_QUEUE, SI_USER, SI_KERNEL = 0x80 # 66 "/usr/include/x86_64-linux-gnu/bits/siginfo-consts.h" 3 4 }; enum { ILL_ILLOPC = 1, ILL_ILLOPN, ILL_ILLADR, ILL_ILLTRP, ILL_PRVOPC, ILL_PRVREG, ILL_COPROC, ILL_BADSTK, ILL_BADIADDR }; enum { FPE_INTDIV = 1, FPE_INTOVF, FPE_FLTDIV, FPE_FLTOVF, FPE_FLTUND, FPE_FLTRES, FPE_FLTINV, FPE_FLTSUB, FPE_FLTUNK = 14, FPE_CONDTRAP }; enum { SEGV_MAPERR = 1, SEGV_ACCERR, SEGV_BNDERR, SEGV_PKUERR, SEGV_ACCADI, SEGV_ADIDERR, SEGV_ADIPERR }; enum { BUS_ADRALN = 1, BUS_ADRERR, BUS_OBJERR, BUS_MCEERR_AR, BUS_MCEERR_AO }; enum { TRAP_BRKPT = 1, TRAP_TRACE, TRAP_BRANCH, TRAP_HWBKPT, TRAP_UNK }; enum { CLD_EXITED = 1, CLD_KILLED, CLD_DUMPED, CLD_TRAPPED, CLD_STOPPED, CLD_CONTINUED }; enum { POLL_IN = 1, POLL_OUT, POLL_MSG, POLL_ERR, POLL_PRI, POLL_HUP }; # 1 "/usr/include/x86_64-linux-gnu/bits/siginfo-consts-arch.h" 1 3 4 # 210 "/usr/include/x86_64-linux-gnu/bits/siginfo-consts.h" 2 3 4 # 59 "/usr/include/signal.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/types/sigval_t.h" 1 3 4 # 16 "/usr/include/x86_64-linux-gnu/bits/types/sigval_t.h" 3 4 typedef __sigval_t sigval_t; # 63 "/usr/include/signal.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/types/sigevent_t.h" 1 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/wordsize.h" 1 3 4 # 5 "/usr/include/x86_64-linux-gnu/bits/types/sigevent_t.h" 2 3 4 # 22 "/usr/include/x86_64-linux-gnu/bits/types/sigevent_t.h" 3 4 typedef struct sigevent { __sigval_t sigev_value; int sigev_signo; int sigev_notify; union { int _pad[((64 / sizeof (int)) - 4)]; __pid_t _tid; struct { void (*_function) (__sigval_t); pthread_attr_t *_attribute; } _sigev_thread; } _sigev_un; } sigevent_t; # 67 "/usr/include/signal.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/sigevent-consts.h" 1 3 4 # 27 "/usr/include/x86_64-linux-gnu/bits/sigevent-consts.h" 3 4 enum { SIGEV_SIGNAL = 0, SIGEV_NONE, SIGEV_THREAD, SIGEV_THREAD_ID = 4 }; # 68 "/usr/include/signal.h" 2 3 4 typedef void (*__sighandler_t) (int); extern __sighandler_t __sysv_signal (int __sig, __sighandler_t __handler) __attribute__ ((__nothrow__ , __leaf__)); extern __sighandler_t sysv_signal (int __sig, __sighandler_t __handler) __attribute__ ((__nothrow__ , __leaf__)); extern __sighandler_t signal (int __sig, __sighandler_t __handler) __attribute__ ((__nothrow__ , __leaf__)); # 112 "/usr/include/signal.h" 3 4 extern int kill (__pid_t __pid, int __sig) __attribute__ ((__nothrow__ , __leaf__)); extern int killpg (__pid_t __pgrp, int __sig) __attribute__ ((__nothrow__ , __leaf__)); extern int raise (int __sig) __attribute__ ((__nothrow__ , __leaf__)); extern __sighandler_t ssignal (int __sig, __sighandler_t __handler) __attribute__ ((__nothrow__ , __leaf__)); extern int gsignal (int __sig) __attribute__ ((__nothrow__ , __leaf__)); extern void psignal (int __sig, const char *__s); extern void psiginfo (const siginfo_t *__pinfo, const char *__s); # 151 "/usr/include/signal.h" 3 4 extern int sigpause (int __sig) __asm__ ("__xpg_sigpause"); # 170 "/usr/include/signal.h" 3 4 extern int sigblock (int __mask) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__deprecated__)); extern int sigsetmask (int __mask) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__deprecated__)); extern int siggetmask (void) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__deprecated__)); # 185 "/usr/include/signal.h" 3 4 typedef __sighandler_t sighandler_t; typedef __sighandler_t sig_t; extern int sigemptyset (sigset_t *__set) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); extern int sigfillset (sigset_t *__set) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); extern int sigaddset (sigset_t *__set, int __signo) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); extern int sigdelset (sigset_t *__set, int __signo) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); extern int sigismember (const sigset_t *__set, int __signo) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); extern int sigisemptyset (const sigset_t *__set) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); extern int sigandset (sigset_t *__set, const sigset_t *__left, const sigset_t *__right) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2, 3))); extern int sigorset (sigset_t *__set, const sigset_t *__left, const sigset_t *__right) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2, 3))); # 1 "/usr/include/x86_64-linux-gnu/bits/sigaction.h" 1 3 4 # 27 "/usr/include/x86_64-linux-gnu/bits/sigaction.h" 3 4 struct sigaction { union { __sighandler_t sa_handler; void (*sa_sigaction) (int, siginfo_t *, void *); } __sigaction_handler; __sigset_t sa_mask; int sa_flags; void (*sa_restorer) (void); }; # 227 "/usr/include/signal.h" 2 3 4 extern int sigprocmask (int __how, const sigset_t *__restrict __set, sigset_t *__restrict __oset) __attribute__ ((__nothrow__ , __leaf__)); extern int sigsuspend (const sigset_t *__set) __attribute__ ((__nonnull__ (1))); extern int sigaction (int __sig, const struct sigaction *__restrict __act, struct sigaction *__restrict __oact) __attribute__ ((__nothrow__ , __leaf__)); extern int sigpending (sigset_t *__set) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); extern int sigwait (const sigset_t *__restrict __set, int *__restrict __sig) __attribute__ ((__nonnull__ (1, 2))); extern int sigwaitinfo (const sigset_t *__restrict __set, siginfo_t *__restrict __info) __attribute__ ((__nonnull__ (1))); extern int sigtimedwait (const sigset_t *__restrict __set, siginfo_t *__restrict __info, const struct timespec *__restrict __timeout) __attribute__ ((__nonnull__ (1))); extern int sigqueue (__pid_t __pid, int __sig, const union sigval __val) __attribute__ ((__nothrow__ , __leaf__)); # 286 "/usr/include/signal.h" 3 4 extern const char *const _sys_siglist[(64 + 1)]; extern const char *const sys_siglist[(64 + 1)]; # 1 "/usr/include/x86_64-linux-gnu/bits/sigcontext.h" 1 3 4 # 31 "/usr/include/x86_64-linux-gnu/bits/sigcontext.h" 3 4 struct _fpx_sw_bytes { __uint32_t magic1; __uint32_t extended_size; __uint64_t xstate_bv; __uint32_t xstate_size; __uint32_t __glibc_reserved1[7]; }; struct _fpreg { unsigned short significand[4]; unsigned short exponent; }; struct _fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; }; struct _xmmreg { __uint32_t element[4]; }; # 123 "/usr/include/x86_64-linux-gnu/bits/sigcontext.h" 3 4 struct _fpstate { __uint16_t cwd; __uint16_t swd; __uint16_t ftw; __uint16_t fop; __uint64_t rip; __uint64_t rdp; __uint32_t mxcsr; __uint32_t mxcr_mask; struct _fpxreg _st[8]; struct _xmmreg _xmm[16]; __uint32_t __glibc_reserved1[24]; }; struct sigcontext { __uint64_t r8; __uint64_t r9; __uint64_t r10; __uint64_t r11; __uint64_t r12; __uint64_t r13; __uint64_t r14; __uint64_t r15; __uint64_t rdi; __uint64_t rsi; __uint64_t rbp; __uint64_t rbx; __uint64_t rdx; __uint64_t rax; __uint64_t rcx; __uint64_t rsp; __uint64_t rip; __uint64_t eflags; unsigned short cs; unsigned short gs; unsigned short fs; unsigned short __pad0; __uint64_t err; __uint64_t trapno; __uint64_t oldmask; __uint64_t cr2; __extension__ union { struct _fpstate * fpstate; __uint64_t __fpstate_word; }; __uint64_t __reserved1 [8]; }; struct _xsave_hdr { __uint64_t xstate_bv; __uint64_t __glibc_reserved1[2]; __uint64_t __glibc_reserved2[5]; }; struct _ymmh_state { __uint32_t ymmh_space[64]; }; struct _xstate { struct _fpstate fpstate; struct _xsave_hdr xstate_hdr; struct _ymmh_state ymmh; }; # 292 "/usr/include/signal.h" 2 3 4 extern int sigreturn (struct sigcontext *__scp) __attribute__ ((__nothrow__ , __leaf__)); # 1 "/usr/lib/gcc/x86_64-linux-gnu/10/include/stddef.h" 1 3 4 # 302 "/usr/include/signal.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/types/stack_t.h" 1 3 4 # 23 "/usr/include/x86_64-linux-gnu/bits/types/stack_t.h" 3 4 # 1 "/usr/lib/gcc/x86_64-linux-gnu/10/include/stddef.h" 1 3 4 # 24 "/usr/include/x86_64-linux-gnu/bits/types/stack_t.h" 2 3 4 typedef struct { void *ss_sp; int ss_flags; size_t ss_size; } stack_t; # 304 "/usr/include/signal.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/sys/ucontext.h" 1 3 4 # 37 "/usr/include/x86_64-linux-gnu/sys/ucontext.h" 3 4 __extension__ typedef long long int greg_t; # 46 "/usr/include/x86_64-linux-gnu/sys/ucontext.h" 3 4 typedef greg_t gregset_t[23]; enum { REG_R8 = 0, REG_R9, REG_R10, REG_R11, REG_R12, REG_R13, REG_R14, REG_R15, REG_RDI, REG_RSI, REG_RBP, REG_RBX, REG_RDX, REG_RAX, REG_RCX, REG_RSP, REG_RIP, REG_EFL, REG_CSGSFS, REG_ERR, REG_TRAPNO, REG_OLDMASK, REG_CR2 }; struct _libc_fpxreg { unsigned short int significand[4]; unsigned short int exponent; unsigned short int __glibc_reserved1[3]; }; struct _libc_xmmreg { __uint32_t element[4]; }; struct _libc_fpstate { __uint16_t cwd; __uint16_t swd; __uint16_t ftw; __uint16_t fop; __uint64_t rip; __uint64_t rdp; __uint32_t mxcsr; __uint32_t mxcr_mask; struct _libc_fpxreg _st[8]; struct _libc_xmmreg _xmm[16]; __uint32_t __glibc_reserved1[24]; }; typedef struct _libc_fpstate *fpregset_t; typedef struct { gregset_t gregs; fpregset_t fpregs; __extension__ unsigned long long __reserved1 [8]; } mcontext_t; typedef struct ucontext_t { unsigned long int uc_flags; struct ucontext_t *uc_link; stack_t uc_stack; mcontext_t uc_mcontext; sigset_t uc_sigmask; struct _libc_fpstate __fpregs_mem; __extension__ unsigned long long int __ssp[4]; } ucontext_t; # 307 "/usr/include/signal.h" 2 3 4 extern int siginterrupt (int __sig, int __interrupt) __attribute__ ((__nothrow__ , __leaf__)); # 1 "/usr/include/x86_64-linux-gnu/bits/sigstack.h" 1 3 4 # 317 "/usr/include/signal.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/ss_flags.h" 1 3 4 # 27 "/usr/include/x86_64-linux-gnu/bits/ss_flags.h" 3 4 enum { SS_ONSTACK = 1, SS_DISABLE }; # 318 "/usr/include/signal.h" 2 3 4 extern int sigaltstack (const stack_t *__restrict __ss, stack_t *__restrict __oss) __attribute__ ((__nothrow__ , __leaf__)); # 1 "/usr/include/x86_64-linux-gnu/bits/types/struct_sigstack.h" 1 3 4 # 23 "/usr/include/x86_64-linux-gnu/bits/types/struct_sigstack.h" 3 4 struct sigstack { void *ss_sp; int ss_onstack; }; # 328 "/usr/include/signal.h" 2 3 4 extern int sigstack (struct sigstack *__ss, struct sigstack *__oss) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__deprecated__)); extern int sighold (int __sig) __attribute__ ((__nothrow__ , __leaf__)); extern int sigrelse (int __sig) __attribute__ ((__nothrow__ , __leaf__)); extern int sigignore (int __sig) __attribute__ ((__nothrow__ , __leaf__)); extern __sighandler_t sigset (int __sig, __sighandler_t __disp) __attribute__ ((__nothrow__ , __leaf__)); # 1 "/usr/include/x86_64-linux-gnu/bits/sigthread.h" 1 3 4 # 31 "/usr/include/x86_64-linux-gnu/bits/sigthread.h" 3 4 extern int pthread_sigmask (int __how, const __sigset_t *__restrict __newmask, __sigset_t *__restrict __oldmask)__attribute__ ((__nothrow__ , __leaf__)); extern int pthread_kill (pthread_t __threadid, int __signo) __attribute__ ((__nothrow__ , __leaf__)); extern int pthread_sigqueue (pthread_t __threadid, int __signo, const union sigval __value) __attribute__ ((__nothrow__ , __leaf__)); # 360 "/usr/include/signal.h" 2 3 4 extern int __libc_current_sigrtmin (void) __attribute__ ((__nothrow__ , __leaf__)); extern int __libc_current_sigrtmax (void) __attribute__ ((__nothrow__ , __leaf__)); # 1 "/usr/include/x86_64-linux-gnu/bits/signal_ext.h" 1 3 4 # 29 "/usr/include/x86_64-linux-gnu/bits/signal_ext.h" 3 4 extern int tgkill (__pid_t __tgid, __pid_t __tid, int __signal); # 375 "/usr/include/signal.h" 2 3 4 # 29 "/usr/include/x86_64-linux-gnu/sys/param.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/param.h" 1 3 4 # 28 "/usr/include/x86_64-linux-gnu/bits/param.h" 3 4 # 1 "/usr/include/linux/param.h" 1 3 4 # 1 "/usr/include/x86_64-linux-gnu/asm/param.h" 1 3 4 # 1 "/usr/include/asm-generic/param.h" 1 3 4 # 2 "/usr/include/x86_64-linux-gnu/asm/param.h" 2 3 4 # 6 "/usr/include/linux/param.h" 2 3 4 # 29 "/usr/include/x86_64-linux-gnu/bits/param.h" 2 3 4 # 32 "/usr/include/x86_64-linux-gnu/sys/param.h" 2 3 4 # 34 "/home/giulianob/gcc_git_gnu/gcc/libiberty/getpwd.c" 2 # 1 "/usr/include/x86_64-linux-gnu/sys/stat.h" 1 3 4 # 99 "/usr/include/x86_64-linux-gnu/sys/stat.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/stat.h" 1 3 4 # 46 "/usr/include/x86_64-linux-gnu/bits/stat.h" 3 4 struct stat { __dev_t st_dev; __ino_t st_ino; __nlink_t st_nlink; __mode_t st_mode; __uid_t st_uid; __gid_t st_gid; int __pad0; __dev_t st_rdev; __off_t st_size; __blksize_t st_blksize; __blkcnt_t st_blocks; # 91 "/usr/include/x86_64-linux-gnu/bits/stat.h" 3 4 struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; # 106 "/usr/include/x86_64-linux-gnu/bits/stat.h" 3 4 __syscall_slong_t __glibc_reserved[3]; # 115 "/usr/include/x86_64-linux-gnu/bits/stat.h" 3 4 }; struct stat64 { __dev_t st_dev; __ino64_t st_ino; __nlink_t st_nlink; __mode_t st_mode; __uid_t st_uid; __gid_t st_gid; int __pad0; __dev_t st_rdev; __off_t st_size; __blksize_t st_blksize; __blkcnt64_t st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; # 164 "/usr/include/x86_64-linux-gnu/bits/stat.h" 3 4 __syscall_slong_t __glibc_reserved[3]; }; # 102 "/usr/include/x86_64-linux-gnu/sys/stat.h" 2 3 4 # 205 "/usr/include/x86_64-linux-gnu/sys/stat.h" 3 4 extern int stat (const char *__restrict __file, struct stat *__restrict __buf) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); extern int fstat (int __fd, struct stat *__buf) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2))); # 224 "/usr/include/x86_64-linux-gnu/sys/stat.h" 3 4 extern int stat64 (const char *__restrict __file, struct stat64 *__restrict __buf) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); extern int fstat64 (int __fd, struct stat64 *__buf) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2))); extern int fstatat (int __fd, const char *__restrict __file, struct stat *__restrict __buf, int __flag) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2, 3))); # 249 "/usr/include/x86_64-linux-gnu/sys/stat.h" 3 4 extern int fstatat64 (int __fd, const char *__restrict __file, struct stat64 *__restrict __buf, int __flag) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2, 3))); extern int lstat (const char *__restrict __file, struct stat *__restrict __buf) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); # 272 "/usr/include/x86_64-linux-gnu/sys/stat.h" 3 4 extern int lstat64 (const char *__restrict __file, struct stat64 *__restrict __buf) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); extern int chmod (const char *__file, __mode_t __mode) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); extern int lchmod (const char *__file, __mode_t __mode) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); extern int fchmod (int __fd, __mode_t __mode) __attribute__ ((__nothrow__ , __leaf__)); extern int fchmodat (int __fd, const char *__file, __mode_t __mode, int __flag) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2))) ; extern __mode_t umask (__mode_t __mask) __attribute__ ((__nothrow__ , __leaf__)); extern __mode_t getumask (void) __attribute__ ((__nothrow__ , __leaf__)); extern int mkdir (const char *__path, __mode_t __mode) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); extern int mkdirat (int __fd, const char *__path, __mode_t __mode) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2))); extern int mknod (const char *__path, __mode_t __mode, __dev_t __dev) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); extern int mknodat (int __fd, const char *__path, __mode_t __mode, __dev_t __dev) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2))); extern int mkfifo (const char *__path, __mode_t __mode) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); extern int mkfifoat (int __fd, const char *__path, __mode_t __mode) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2))); extern int utimensat (int __fd, const char *__path, const struct timespec __times[2], int __flags) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2))); extern int futimens (int __fd, const struct timespec __times[2]) __attribute__ ((__nothrow__ , __leaf__)); # 395 "/usr/include/x86_64-linux-gnu/sys/stat.h" 3 4 extern int __fxstat (int __ver, int __fildes, struct stat *__stat_buf) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (3))); extern int __xstat (int __ver, const char *__filename, struct stat *__stat_buf) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2, 3))); extern int __lxstat (int __ver, const char *__filename, struct stat *__stat_buf) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2, 3))); extern int __fxstatat (int __ver, int __fildes, const char *__filename, struct stat *__stat_buf, int __flag) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (3, 4))); # 428 "/usr/include/x86_64-linux-gnu/sys/stat.h" 3 4 extern int __fxstat64 (int __ver, int __fildes, struct stat64 *__stat_buf) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (3))); extern int __xstat64 (int __ver, const char *__filename, struct stat64 *__stat_buf) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2, 3))); extern int __lxstat64 (int __ver, const char *__filename, struct stat64 *__stat_buf) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2, 3))); extern int __fxstatat64 (int __ver, int __fildes, const char *__filename, struct stat64 *__stat_buf, int __flag) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (3, 4))); extern int __xmknod (int __ver, const char *__path, __mode_t __mode, __dev_t *__dev) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2, 4))); extern int __xmknodat (int __ver, int __fd, const char *__path, __mode_t __mode, __dev_t *__dev) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (3, 5))); # 1 "/usr/include/x86_64-linux-gnu/bits/statx.h" 1 3 4 # 31 "/usr/include/x86_64-linux-gnu/bits/statx.h" 3 4 # 1 "/usr/include/linux/stat.h" 1 3 4 # 1 "/usr/include/linux/types.h" 1 3 4 # 1 "/usr/include/x86_64-linux-gnu/asm/types.h" 1 3 4 # 1 "/usr/include/asm-generic/types.h" 1 3 4 # 1 "/usr/include/asm-generic/int-ll64.h" 1 3 4 # 12 "/usr/include/asm-generic/int-ll64.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/asm/bitsperlong.h" 1 3 4 # 11 "/usr/include/x86_64-linux-gnu/asm/bitsperlong.h" 3 4 # 1 "/usr/include/asm-generic/bitsperlong.h" 1 3 4 # 12 "/usr/include/x86_64-linux-gnu/asm/bitsperlong.h" 2 3 4 # 13 "/usr/include/asm-generic/int-ll64.h" 2 3 4 typedef __signed__ char __s8; typedef unsigned char __u8; typedef __signed__ short __s16; typedef unsigned short __u16; typedef __signed__ int __s32; typedef unsigned int __u32; __extension__ typedef __signed__ long long __s64; __extension__ typedef unsigned long long __u64; # 8 "/usr/include/asm-generic/types.h" 2 3 4 # 2 "/usr/include/x86_64-linux-gnu/asm/types.h" 2 3 4 # 6 "/usr/include/linux/types.h" 2 3 4 # 1 "/usr/include/linux/posix_types.h" 1 3 4 # 1 "/usr/include/linux/stddef.h" 1 3 4 # 6 "/usr/include/linux/posix_types.h" 2 3 4 # 25 "/usr/include/linux/posix_types.h" 3 4 typedef struct { unsigned long fds_bits[1024 / (8 * sizeof(long))]; } __kernel_fd_set; typedef void (*__kernel_sighandler_t)(int); typedef int __kernel_key_t; typedef int __kernel_mqd_t; # 1 "/usr/include/x86_64-linux-gnu/asm/posix_types.h" 1 3 4 # 1 "/usr/include/x86_64-linux-gnu/asm/posix_types_64.h" 1 3 4 # 11 "/usr/include/x86_64-linux-gnu/asm/posix_types_64.h" 3 4 typedef unsigned short __kernel_old_uid_t; typedef unsigned short __kernel_old_gid_t; typedef unsigned long __kernel_old_dev_t; # 1 "/usr/include/asm-generic/posix_types.h" 1 3 4 # 15 "/usr/include/asm-generic/posix_types.h" 3 4 typedef long __kernel_long_t; typedef unsigned long __kernel_ulong_t; typedef __kernel_ulong_t __kernel_ino_t; typedef unsigned int __kernel_mode_t; typedef int __kernel_pid_t; typedef int __kernel_ipc_pid_t; typedef unsigned int __kernel_uid_t; typedef unsigned int __kernel_gid_t; typedef __kernel_long_t __kernel_suseconds_t; typedef int __kernel_daddr_t; typedef unsigned int __kernel_uid32_t; typedef unsigned int __kernel_gid32_t; # 72 "/usr/include/asm-generic/posix_types.h" 3 4 typedef __kernel_ulong_t __kernel_size_t; typedef __kernel_long_t __kernel_ssize_t; typedef __kernel_long_t __kernel_ptrdiff_t; typedef struct { int val[2]; } __kernel_fsid_t; typedef __kernel_long_t __kernel_off_t; typedef long long __kernel_loff_t; typedef __kernel_long_t __kernel_old_time_t; typedef __kernel_long_t __kernel_time_t; typedef long long __kernel_time64_t; typedef __kernel_long_t __kernel_clock_t; typedef int __kernel_timer_t; typedef int __kernel_clockid_t; typedef char * __kernel_caddr_t; typedef unsigned short __kernel_uid16_t; typedef unsigned short __kernel_gid16_t; # 19 "/usr/include/x86_64-linux-gnu/asm/posix_types_64.h" 2 3 4 # 8 "/usr/include/x86_64-linux-gnu/asm/posix_types.h" 2 3 4 # 37 "/usr/include/linux/posix_types.h" 2 3 4 # 10 "/usr/include/linux/types.h" 2 3 4 # 24 "/usr/include/linux/types.h" 3 4 typedef __u16 __le16; typedef __u16 __be16; typedef __u32 __le32; typedef __u32 __be32; typedef __u64 __le64; typedef __u64 __be64; typedef __u16 __sum16; typedef __u32 __wsum; # 47 "/usr/include/linux/types.h" 3 4 typedef unsigned __poll_t; # 6 "/usr/include/linux/stat.h" 2 3 4 # 56 "/usr/include/linux/stat.h" 3 4 struct statx_timestamp { __s64 tv_sec; __u32 tv_nsec; __s32 __reserved; }; # 99 "/usr/include/linux/stat.h" 3 4 struct statx { __u32 stx_mask; __u32 stx_blksize; __u64 stx_attributes; __u32 stx_nlink; __u32 stx_uid; __u32 stx_gid; __u16 stx_mode; __u16 __spare0[1]; __u64 stx_ino; __u64 stx_size; __u64 stx_blocks; __u64 stx_attributes_mask; struct statx_timestamp stx_atime; struct statx_timestamp stx_btime; struct statx_timestamp stx_ctime; struct statx_timestamp stx_mtime; __u32 stx_rdev_major; __u32 stx_rdev_minor; __u32 stx_dev_major; __u32 stx_dev_minor; __u64 __spare2[14]; }; # 32 "/usr/include/x86_64-linux-gnu/bits/statx.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/statx-generic.h" 1 3 4 # 25 "/usr/include/x86_64-linux-gnu/bits/statx-generic.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/types/struct_statx_timestamp.h" 1 3 4 # 26 "/usr/include/x86_64-linux-gnu/bits/statx-generic.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/types/struct_statx.h" 1 3 4 # 27 "/usr/include/x86_64-linux-gnu/bits/statx-generic.h" 2 3 4 # 53 "/usr/include/x86_64-linux-gnu/bits/statx-generic.h" 3 4 int statx (int __dirfd, const char *__restrict __path, int __flags, unsigned int __mask, struct statx *__restrict __buf) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2, 5))); # 40 "/usr/include/x86_64-linux-gnu/bits/statx.h" 2 3 4 # 447 "/usr/include/x86_64-linux-gnu/sys/stat.h" 2 3 4 extern __inline __attribute__ ((__gnu_inline__)) int __attribute__ ((__nothrow__ , __leaf__)) stat (const char *__path, struct stat *__statbuf) { return __xstat (1, __path, __statbuf); } extern __inline __attribute__ ((__gnu_inline__)) int __attribute__ ((__nothrow__ , __leaf__)) lstat (const char *__path, struct stat *__statbuf) { return __lxstat (1, __path, __statbuf); } extern __inline __attribute__ ((__gnu_inline__)) int __attribute__ ((__nothrow__ , __leaf__)) fstat (int __fd, struct stat *__statbuf) { return __fxstat (1, __fd, __statbuf); } extern __inline __attribute__ ((__gnu_inline__)) int __attribute__ ((__nothrow__ , __leaf__)) fstatat (int __fd, const char *__filename, struct stat *__statbuf, int __flag) { return __fxstatat (1, __fd, __filename, __statbuf, __flag); } extern __inline __attribute__ ((__gnu_inline__)) int __attribute__ ((__nothrow__ , __leaf__)) mknod (const char *__path, __mode_t __mode, __dev_t __dev) { return __xmknod (0, __path, __mode, &__dev); } extern __inline __attribute__ ((__gnu_inline__)) int __attribute__ ((__nothrow__ , __leaf__)) mknodat (int __fd, const char *__path, __mode_t __mode, __dev_t __dev) { return __xmknodat (0, __fd, __path, __mode, &__dev); } extern __inline __attribute__ ((__gnu_inline__)) int __attribute__ ((__nothrow__ , __leaf__)) stat64 (const char *__path, struct stat64 *__statbuf) { return __xstat64 (1, __path, __statbuf); } extern __inline __attribute__ ((__gnu_inline__)) int __attribute__ ((__nothrow__ , __leaf__)) lstat64 (const char *__path, struct stat64 *__statbuf) { return __lxstat64 (1, __path, __statbuf); } extern __inline __attribute__ ((__gnu_inline__)) int __attribute__ ((__nothrow__ , __leaf__)) fstat64 (int __fd, struct stat64 *__statbuf) { return __fxstat64 (1, __fd, __statbuf); } extern __inline __attribute__ ((__gnu_inline__)) int __attribute__ ((__nothrow__ , __leaf__)) fstatat64 (int __fd, const char *__filename, struct stat64 *__statbuf, int __flag) { return __fxstatat64 (1, __fd, __filename, __statbuf, __flag); } # 37 "/home/giulianob/gcc_git_gnu/gcc/libiberty/getpwd.c" 2 # 1 "/usr/lib/gcc/x86_64-linux-gnu/10/include/limits.h" 1 3 4 # 40 "/home/giulianob/gcc_git_gnu/gcc/libiberty/getpwd.c" 2 # 1 "/home/giulianob/gcc_git_gnu/gcc/libiberty/../include/libiberty.h" 1 # 42 "/home/giulianob/gcc_git_gnu/gcc/libiberty/../include/libiberty.h" # 1 "/home/giulianob/gcc_git_gnu/gcc/libiberty/../include/ansidecl.h" 1 # 43 "/home/giulianob/gcc_git_gnu/gcc/libiberty/../include/libiberty.h" 2 # 1 "/usr/lib/gcc/x86_64-linux-gnu/10/include/stddef.h" 1 3 4 # 143 "/usr/lib/gcc/x86_64-linux-gnu/10/include/stddef.h" 3 4 typedef long int ptrdiff_t; # 415 "/usr/lib/gcc/x86_64-linux-gnu/10/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)))); # 426 "/usr/lib/gcc/x86_64-linux-gnu/10/include/stddef.h" 3 4 } max_align_t; # 46 "/home/giulianob/gcc_git_gnu/gcc/libiberty/../include/libiberty.h" 2 # 1 "/usr/lib/gcc/x86_64-linux-gnu/10/include/stdarg.h" 1 3 4 # 40 "/usr/lib/gcc/x86_64-linux-gnu/10/include/stdarg.h" 3 4 typedef __builtin_va_list __gnuc_va_list; # 99 "/usr/lib/gcc/x86_64-linux-gnu/10/include/stdarg.h" 3 4 typedef __gnuc_va_list va_list; # 48 "/home/giulianob/gcc_git_gnu/gcc/libiberty/../include/libiberty.h" 2 # 1 "/usr/include/stdio.h" 1 3 4 # 27 "/usr/include/stdio.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/libc-header-start.h" 1 3 4 # 28 "/usr/include/stdio.h" 2 3 4 # 1 "/usr/lib/gcc/x86_64-linux-gnu/10/include/stddef.h" 1 3 4 # 34 "/usr/include/stdio.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/types/__fpos_t.h" 1 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/types/__mbstate_t.h" 1 3 4 # 13 "/usr/include/x86_64-linux-gnu/bits/types/__mbstate_t.h" 3 4 typedef struct { int __count; union { unsigned int __wch; char __wchb[4]; } __value; } __mbstate_t; # 6 "/usr/include/x86_64-linux-gnu/bits/types/__fpos_t.h" 2 3 4 typedef struct _G_fpos_t { __off_t __pos; __mbstate_t __state; } __fpos_t; # 40 "/usr/include/stdio.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/types/__fpos64_t.h" 1 3 4 # 10 "/usr/include/x86_64-linux-gnu/bits/types/__fpos64_t.h" 3 4 typedef struct _G_fpos64_t { __off64_t __pos; __mbstate_t __state; } __fpos64_t; # 41 "/usr/include/stdio.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/types/__FILE.h" 1 3 4 struct _IO_FILE; typedef struct _IO_FILE __FILE; # 42 "/usr/include/stdio.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/types/FILE.h" 1 3 4 struct _IO_FILE; typedef struct _IO_FILE FILE; # 43 "/usr/include/stdio.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/types/struct_FILE.h" 1 3 4 # 35 "/usr/include/x86_64-linux-gnu/bits/types/struct_FILE.h" 3 4 struct _IO_FILE; struct _IO_marker; struct _IO_codecvt; struct _IO_wide_data; typedef void _IO_lock_t; struct _IO_FILE { int _flags; char *_IO_read_ptr; char *_IO_read_end; char *_IO_read_base; char *_IO_write_base; char *_IO_write_ptr; char *_IO_write_end; char *_IO_buf_base; char *_IO_buf_end; char *_IO_save_base; char *_IO_backup_base; char *_IO_save_end; struct _IO_marker *_markers; struct _IO_FILE *_chain; int _fileno; int _flags2; __off_t _old_offset; unsigned short _cur_column; signed char _vtable_offset; char _shortbuf[1]; _IO_lock_t *_lock; __off64_t _offset; struct _IO_codecvt *_codecvt; struct _IO_wide_data *_wide_data; struct _IO_FILE *_freeres_list; void *_freeres_buf; size_t __pad5; int _mode; char _unused2[15 * sizeof (int) - 4 * sizeof (void *) - sizeof (size_t)]; }; # 44 "/usr/include/stdio.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/types/cookie_io_functions_t.h" 1 3 4 # 27 "/usr/include/x86_64-linux-gnu/bits/types/cookie_io_functions_t.h" 3 4 typedef __ssize_t cookie_read_function_t (void *__cookie, char *__buf, size_t __nbytes); typedef __ssize_t cookie_write_function_t (void *__cookie, const char *__buf, size_t __nbytes); typedef int cookie_seek_function_t (void *__cookie, __off64_t *__pos, int __w); typedef int cookie_close_function_t (void *__cookie); typedef struct _IO_cookie_io_functions_t { cookie_read_function_t *read; cookie_write_function_t *write; cookie_seek_function_t *seek; cookie_close_function_t *close; } cookie_io_functions_t; # 47 "/usr/include/stdio.h" 2 3 4 # 84 "/usr/include/stdio.h" 3 4 typedef __fpos_t fpos_t; typedef __fpos64_t fpos64_t; # 133 "/usr/include/stdio.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/stdio_lim.h" 1 3 4 # 134 "/usr/include/stdio.h" 2 3 4 extern FILE *stdin; extern FILE *stdout; extern FILE *stderr; extern int remove (const char *__filename) __attribute__ ((__nothrow__ , __leaf__)); extern int rename (const char *__old, const char *__new) __attribute__ ((__nothrow__ , __leaf__)); extern int renameat (int __oldfd, const char *__old, int __newfd, const char *__new) __attribute__ ((__nothrow__ , __leaf__)); # 164 "/usr/include/stdio.h" 3 4 extern int renameat2 (int __oldfd, const char *__old, int __newfd, const char *__new, unsigned int __flags) __attribute__ ((__nothrow__ , __leaf__)); extern FILE *tmpfile (void) ; # 183 "/usr/include/stdio.h" 3 4 extern FILE *tmpfile64 (void) ; extern char *tmpnam (char *__s) __attribute__ ((__nothrow__ , __leaf__)) ; extern char *tmpnam_r (char *__s) __attribute__ ((__nothrow__ , __leaf__)) ; # 204 "/usr/include/stdio.h" 3 4 extern char *tempnam (const char *__dir, const char *__pfx) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__malloc__)) ; extern int fclose (FILE *__stream); extern int fflush (FILE *__stream); # 227 "/usr/include/stdio.h" 3 4 extern int fflush_unlocked (FILE *__stream); # 237 "/usr/include/stdio.h" 3 4 extern int fcloseall (void); # 246 "/usr/include/stdio.h" 3 4 extern FILE *fopen (const char *__restrict __filename, const char *__restrict __modes) ; extern FILE *freopen (const char *__restrict __filename, const char *__restrict __modes, FILE *__restrict __stream) ; # 270 "/usr/include/stdio.h" 3 4 extern FILE *fopen64 (const char *__restrict __filename, const char *__restrict __modes) ; extern FILE *freopen64 (const char *__restrict __filename, const char *__restrict __modes, FILE *__restrict __stream) ; extern FILE *fdopen (int __fd, const char *__modes) __attribute__ ((__nothrow__ , __leaf__)) ; extern FILE *fopencookie (void *__restrict __magic_cookie, const char *__restrict __modes, cookie_io_functions_t __io_funcs) __attribute__ ((__nothrow__ , __leaf__)) ; extern FILE *fmemopen (void *__s, size_t __len, const char *__modes) __attribute__ ((__nothrow__ , __leaf__)) ; extern FILE *open_memstream (char **__bufloc, size_t *__sizeloc) __attribute__ ((__nothrow__ , __leaf__)) ; extern void setbuf (FILE *__restrict __stream, char *__restrict __buf) __attribute__ ((__nothrow__ , __leaf__)); extern int setvbuf (FILE *__restrict __stream, char *__restrict __buf, int __modes, size_t __n) __attribute__ ((__nothrow__ , __leaf__)); extern void setbuffer (FILE *__restrict __stream, char *__restrict __buf, size_t __size) __attribute__ ((__nothrow__ , __leaf__)); extern void setlinebuf (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)); extern int fprintf (FILE *__restrict __stream, const char *__restrict __format, ...); extern int printf (const char *__restrict __format, ...); extern int sprintf (char *__restrict __s, const char *__restrict __format, ...) __attribute__ ((__nothrow__)); extern int vfprintf (FILE *__restrict __s, const char *__restrict __format, __gnuc_va_list __arg); extern int vprintf (const char *__restrict __format, __gnuc_va_list __arg); extern int vsprintf (char *__restrict __s, const char *__restrict __format, __gnuc_va_list __arg) __attribute__ ((__nothrow__)); extern int snprintf (char *__restrict __s, size_t __maxlen, const char *__restrict __format, ...) __attribute__ ((__nothrow__)) __attribute__ ((__format__ (__printf__, 3, 4))); extern int vsnprintf (char *__restrict __s, size_t __maxlen, const char *__restrict __format, __gnuc_va_list __arg) __attribute__ ((__nothrow__)) __attribute__ ((__format__ (__printf__, 3, 0))); extern int vasprintf (char **__restrict __ptr, const char *__restrict __f, __gnuc_va_list __arg) __attribute__ ((__nothrow__)) __attribute__ ((__format__ (__printf__, 2, 0))) ; extern int __asprintf (char **__restrict __ptr, const char *__restrict __fmt, ...) __attribute__ ((__nothrow__)) __attribute__ ((__format__ (__printf__, 2, 3))) ; extern int asprintf (char **__restrict __ptr, const char *__restrict __fmt, ...) __attribute__ ((__nothrow__)) __attribute__ ((__format__ (__printf__, 2, 3))) ; extern int vdprintf (int __fd, const char *__restrict __fmt, __gnuc_va_list __arg) __attribute__ ((__format__ (__printf__, 2, 0))); extern int dprintf (int __fd, const char *__restrict __fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3))); extern int fscanf (FILE *__restrict __stream, const char *__restrict __format, ...) ; extern int scanf (const char *__restrict __format, ...) ; extern int sscanf (const char *__restrict __s, const char *__restrict __format, ...) __attribute__ ((__nothrow__ , __leaf__)); extern int fscanf (FILE *__restrict __stream, const char *__restrict __format, ...) __asm__ ("" "__isoc99_fscanf") ; extern int scanf (const char *__restrict __format, ...) __asm__ ("" "__isoc99_scanf") ; extern int sscanf (const char *__restrict __s, const char *__restrict __format, ...) __asm__ ("" "__isoc99_sscanf") __attribute__ ((__nothrow__ , __leaf__)) ; # 432 "/usr/include/stdio.h" 3 4 extern int vfscanf (FILE *__restrict __s, const char *__restrict __format, __gnuc_va_list __arg) __attribute__ ((__format__ (__scanf__, 2, 0))) ; extern int vscanf (const char *__restrict __format, __gnuc_va_list __arg) __attribute__ ((__format__ (__scanf__, 1, 0))) ; extern int vsscanf (const char *__restrict __s, const char *__restrict __format, __gnuc_va_list __arg) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__format__ (__scanf__, 2, 0))); extern int vfscanf (FILE *__restrict __s, const char *__restrict __format, __gnuc_va_list __arg) __asm__ ("" "__isoc99_vfscanf") __attribute__ ((__format__ (__scanf__, 2, 0))) ; extern int vscanf (const char *__restrict __format, __gnuc_va_list __arg) __asm__ ("" "__isoc99_vscanf") __attribute__ ((__format__ (__scanf__, 1, 0))) ; extern int vsscanf (const char *__restrict __s, const char *__restrict __format, __gnuc_va_list __arg) __asm__ ("" "__isoc99_vsscanf") __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__format__ (__scanf__, 2, 0))); # 485 "/usr/include/stdio.h" 3 4 extern int fgetc (FILE *__stream); extern int getc (FILE *__stream); extern int getchar (void); extern int getc_unlocked (FILE *__stream); extern int getchar_unlocked (void); # 510 "/usr/include/stdio.h" 3 4 extern int fgetc_unlocked (FILE *__stream); # 521 "/usr/include/stdio.h" 3 4 extern int fputc (int __c, FILE *__stream); extern int putc (int __c, FILE *__stream); extern int putchar (int __c); # 537 "/usr/include/stdio.h" 3 4 extern int fputc_unlocked (int __c, FILE *__stream); extern int putc_unlocked (int __c, FILE *__stream); extern int putchar_unlocked (int __c); extern int getw (FILE *__stream); extern int putw (int __w, FILE *__stream); extern char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream) ; # 587 "/usr/include/stdio.h" 3 4 extern char *fgets_unlocked (char *__restrict __s, int __n, FILE *__restrict __stream) ; # 603 "/usr/include/stdio.h" 3 4 extern __ssize_t __getdelim (char **__restrict __lineptr, size_t *__restrict __n, int __delimiter, FILE *__restrict __stream) ; extern __ssize_t getdelim (char **__restrict __lineptr, size_t *__restrict __n, int __delimiter, FILE *__restrict __stream) ; extern __ssize_t getline (char **__restrict __lineptr, size_t *__restrict __n, FILE *__restrict __stream) ; extern int fputs (const char *__restrict __s, FILE *__restrict __stream); extern int puts (const char *__s); extern int ungetc (int __c, FILE *__stream); extern size_t fread (void *__restrict __ptr, size_t __size, size_t __n, FILE *__restrict __stream) ; extern size_t fwrite (const void *__restrict __ptr, size_t __size, size_t __n, FILE *__restrict __s); # 662 "/usr/include/stdio.h" 3 4 extern int fputs_unlocked (const char *__restrict __s, FILE *__restrict __stream); # 673 "/usr/include/stdio.h" 3 4 extern size_t fread_unlocked (void *__restrict __ptr, size_t __size, size_t __n, FILE *__restrict __stream) ; extern size_t fwrite_unlocked (const void *__restrict __ptr, size_t __size, size_t __n, FILE *__restrict __stream); extern int fseek (FILE *__stream, long int __off, int __whence); extern long int ftell (FILE *__stream) ; extern void rewind (FILE *__stream); # 707 "/usr/include/stdio.h" 3 4 extern int fseeko (FILE *__stream, __off_t __off, int __whence); extern __off_t ftello (FILE *__stream) ; # 731 "/usr/include/stdio.h" 3 4 extern int fgetpos (FILE *__restrict __stream, fpos_t *__restrict __pos); extern int fsetpos (FILE *__stream, const fpos_t *__pos); # 750 "/usr/include/stdio.h" 3 4 extern int fseeko64 (FILE *__stream, __off64_t __off, int __whence); extern __off64_t ftello64 (FILE *__stream) ; extern int fgetpos64 (FILE *__restrict __stream, fpos64_t *__restrict __pos); extern int fsetpos64 (FILE *__stream, const fpos64_t *__pos); extern void clearerr (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)); extern int feof (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; extern int ferror (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; extern void clearerr_unlocked (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)); extern int feof_unlocked (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; extern int ferror_unlocked (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; extern void perror (const char *__s); # 1 "/usr/include/x86_64-linux-gnu/bits/sys_errlist.h" 1 3 4 # 26 "/usr/include/x86_64-linux-gnu/bits/sys_errlist.h" 3 4 extern int sys_nerr; extern const char *const sys_errlist[]; extern int _sys_nerr; extern const char *const _sys_errlist[]; # 782 "/usr/include/stdio.h" 2 3 4 extern int fileno (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; extern int fileno_unlocked (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; # 800 "/usr/include/stdio.h" 3 4 extern FILE *popen (const char *__command, const char *__modes) ; extern int pclose (FILE *__stream); extern char *ctermid (char *__s) __attribute__ ((__nothrow__ , __leaf__)); extern char *cuserid (char *__s); struct obstack; extern int obstack_printf (struct obstack *__restrict __obstack, const char *__restrict __format, ...) __attribute__ ((__nothrow__)) __attribute__ ((__format__ (__printf__, 2, 3))); extern int obstack_vprintf (struct obstack *__restrict __obstack, const char *__restrict __format, __gnuc_va_list __args) __attribute__ ((__nothrow__)) __attribute__ ((__format__ (__printf__, 2, 0))); extern void flockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)); extern int ftrylockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; extern void funlockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)); # 858 "/usr/include/stdio.h" 3 4 extern int __uflow (FILE *); extern int __overflow (FILE *, int); # 1 "/usr/include/x86_64-linux-gnu/bits/stdio.h" 1 3 4 # 38 "/usr/include/x86_64-linux-gnu/bits/stdio.h" 3 4 extern __inline __attribute__ ((__gnu_inline__)) int vprintf (const char *__restrict __fmt, __gnuc_va_list __arg) { return vfprintf (stdout, __fmt, __arg); } extern __inline __attribute__ ((__gnu_inline__)) int getchar (void) { return getc (stdin); } extern __inline __attribute__ ((__gnu_inline__)) int fgetc_unlocked (FILE *__fp) { return (__builtin_expect (((__fp)->_IO_read_ptr >= (__fp)->_IO_read_end), 0) ? __uflow (__fp) : *(unsigned char *) (__fp)->_IO_read_ptr++); } extern __inline __attribute__ ((__gnu_inline__)) int getc_unlocked (FILE *__fp) { return (__builtin_expect (((__fp)->_IO_read_ptr >= (__fp)->_IO_read_end), 0) ? __uflow (__fp) : *(unsigned char *) (__fp)->_IO_read_ptr++); } extern __inline __attribute__ ((__gnu_inline__)) int getchar_unlocked (void) { return (__builtin_expect (((stdin)->_IO_read_ptr >= (stdin)->_IO_read_end), 0) ? __uflow (stdin) : *(unsigned char *) (stdin)->_IO_read_ptr++); } extern __inline __attribute__ ((__gnu_inline__)) int putchar (int __c) { return putc (__c, stdout); } extern __inline __attribute__ ((__gnu_inline__)) int fputc_unlocked (int __c, FILE *__stream) { return (__builtin_expect (((__stream)->_IO_write_ptr >= (__stream)->_IO_write_end), 0) ? __overflow (__stream, (unsigned char) (__c)) : (unsigned char) (*(__stream)->_IO_write_ptr++ = (__c))); } extern __inline __attribute__ ((__gnu_inline__)) int putc_unlocked (int __c, FILE *__stream) { return (__builtin_expect (((__stream)->_IO_write_ptr >= (__stream)->_IO_write_end), 0) ? __overflow (__stream, (unsigned char) (__c)) : (unsigned char) (*(__stream)->_IO_write_ptr++ = (__c))); } extern __inline __attribute__ ((__gnu_inline__)) int putchar_unlocked (int __c) { return (__builtin_expect (((stdout)->_IO_write_ptr >= (stdout)->_IO_write_end), 0) ? __overflow (stdout, (unsigned char) (__c)) : (unsigned char) (*(stdout)->_IO_write_ptr++ = (__c))); } extern __inline __attribute__ ((__gnu_inline__)) __ssize_t getline (char **__lineptr, size_t *__n, FILE *__stream) { return __getdelim (__lineptr, __n, '\n', __stream); } extern __inline __attribute__ ((__gnu_inline__)) int __attribute__ ((__nothrow__ , __leaf__)) feof_unlocked (FILE *__stream) { return (((__stream)->_flags & 0x0010) != 0); } extern __inline __attribute__ ((__gnu_inline__)) int __attribute__ ((__nothrow__ , __leaf__)) ferror_unlocked (FILE *__stream) { return (((__stream)->_flags & 0x0020) != 0); } # 865 "/usr/include/stdio.h" 2 3 4 # 873 "/usr/include/stdio.h" 3 4 # 50 "/home/giulianob/gcc_git_gnu/gcc/libiberty/../include/libiberty.h" 2 # 55 "/home/giulianob/gcc_git_gnu/gcc/libiberty/../include/libiberty.h" extern void unlock_stream (FILE *); extern void unlock_std_streams (void); extern FILE *fopen_unlocked (const char *, const char *); extern FILE *fdopen_unlocked (int, const char *); extern FILE *freopen_unlocked (const char *, const char *, FILE *); extern char **buildargv (const char *) __attribute__ ((__malloc__)); extern void freeargv (char **); extern char **dupargv (char * const *) __attribute__ ((__malloc__)); extern void expandargv (int *, char ***); extern int writeargv (char * const *, FILE *); extern int countargv (char * const *); # 123 "/home/giulianob/gcc_git_gnu/gcc/libiberty/../include/libiberty.h" extern const char *lbasename (const char *) __attribute__ ((__returns_nonnull__)) __attribute__ ((__nonnull__ (1))); extern const char *dos_lbasename (const char *) __attribute__ ((__returns_nonnull__)) __attribute__ ((__nonnull__ (1))); extern const char *unix_lbasename (const char *) __attribute__ ((__returns_nonnull__)) __attribute__ ((__nonnull__ (1))); extern char *lrealpath (const char *); extern int is_valid_fd (int fd); extern char *concat (const char *, ...) __attribute__ ((__malloc__)) __attribute__ ((__returns_nonnull__)) __attribute__ ((__sentinel__)); # 157 "/home/giulianob/gcc_git_gnu/gcc/libiberty/../include/libiberty.h" extern char *reconcat (char *, const char *, ...) __attribute__ ((__malloc__)) __attribute__ ((__returns_nonnull__)) __attribute__ ((__sentinel__)); extern unsigned long concat_length (const char *, ...) __attribute__ ((__sentinel__)); extern char *concat_copy (char *, const char *, ...) __attribute__ ((__returns_nonnull__)) __attribute__ ((__nonnull__ (1))) __attribute__ ((__sentinel__)); extern char *concat_copy2 (const char *, ...) __attribute__ ((__returns_nonnull__)) __attribute__ ((__sentinel__)); extern char *libiberty_concat_ptr; # 193 "/home/giulianob/gcc_git_gnu/gcc/libiberty/../include/libiberty.h" extern int fdmatch (int fd1, int fd2); # 205 "/home/giulianob/gcc_git_gnu/gcc/libiberty/../include/libiberty.h" extern char * getpwd (void); # 218 "/home/giulianob/gcc_git_gnu/gcc/libiberty/../include/libiberty.h" extern long get_run_time (void); extern char *make_relative_prefix (const char *, const char *, const char *) __attribute__ ((__malloc__)); extern char *make_relative_prefix_ignore_links (const char *, const char *, const char *) __attribute__ ((__malloc__)); extern const char *choose_tmpdir (void) __attribute__ ((__returns_nonnull__)); extern char *choose_temp_base (void) __attribute__ ((__malloc__)) __attribute__ ((__returns_nonnull__)); extern char *make_temp_file (const char *) __attribute__ ((__malloc__)); extern char *make_temp_file_with_prefix (const char *, const char *) __attribute__ ((__malloc__)); extern int unlink_if_ordinary (const char *); extern const char *spaces (int count); extern int errno_max (void); extern const char *strerrno (int); extern int strtoerrno (const char *); extern char *xstrerror (int) __attribute__ ((__returns_nonnull__)); extern int signo_max (void); # 292 "/home/giulianob/gcc_git_gnu/gcc/libiberty/../include/libiberty.h" extern const char *strsigno (int); extern int strtosigno (const char *); extern int xatexit (void (*fn) (void)); extern void xexit (int status) __attribute__ ((__noreturn__)); extern void xmalloc_set_program_name (const char *); extern void xmalloc_failed (size_t) __attribute__ ((__noreturn__)); extern void *xmalloc (size_t) __attribute__ ((__malloc__)) __attribute__ ((__returns_nonnull__)) __attribute__ ((alloc_size (1))) __attribute__ ((warn_unused_result)); extern void *xrealloc (void *, size_t) __attribute__ ((__returns_nonnull__)) __attribute__ ((alloc_size (2))) __attribute__ ((warn_unused_result)); extern void *xcalloc (size_t, size_t) __attribute__ ((__malloc__)) __attribute__ ((__returns_nonnull__)) __attribute__ ((alloc_size (1, 2))) __attribute__ ((warn_unused_result)); extern char *xstrdup (const char *) __attribute__ ((__malloc__)) __attribute__ ((__returns_nonnull__)) __attribute__ ((warn_unused_result)); extern char *xstrndup (const char *, size_t) __attribute__ ((__malloc__)) __attribute__ ((__returns_nonnull__)) __attribute__ ((warn_unused_result)); extern void *xmemdup (const void *, size_t, size_t) __attribute__ ((__malloc__)) __attribute__ ((__returns_nonnull__)) __attribute__ ((warn_unused_result)); extern double physmem_total (void); extern double physmem_available (void); extern unsigned int xcrc32 (const unsigned char *, int, unsigned int); # 391 "/home/giulianob/gcc_git_gnu/gcc/libiberty/../include/libiberty.h" extern const unsigned char _hex_value[256]; extern void hex_init (void); # 428 "/home/giulianob/gcc_git_gnu/gcc/libiberty/../include/libiberty.h" extern struct pex_obj *pex_init (int flags, const char *pname, const char *tempbase) __attribute__ ((__returns_nonnull__)); # 528 "/home/giulianob/gcc_git_gnu/gcc/libiberty/../include/libiberty.h" extern const char *pex_run (struct pex_obj *obj, int flags, const char *executable, char * const *argv, const char *outname, const char *errname, int *err); # 543 "/home/giulianob/gcc_git_gnu/gcc/libiberty/../include/libiberty.h" extern const char *pex_run_in_environment (struct pex_obj *obj, int flags, const char *executable, char * const *argv, char * const *env, const char *outname, const char *errname, int *err); extern FILE *pex_input_file (struct pex_obj *obj, int flags, const char *in_name); extern FILE *pex_input_pipe (struct pex_obj *obj, int binary); extern FILE *pex_read_output (struct pex_obj *, int binary); extern FILE *pex_read_err (struct pex_obj *, int binary); extern int pex_get_status (struct pex_obj *, int count, int *vector); struct pex_time { unsigned long user_seconds; unsigned long user_microseconds; unsigned long system_seconds; unsigned long system_microseconds; }; extern int pex_get_times (struct pex_obj *, int count, struct pex_time *vector); extern void pex_free (struct pex_obj *); # 618 "/home/giulianob/gcc_git_gnu/gcc/libiberty/../include/libiberty.h" extern const char *pex_one (int flags, const char *executable, char * const *argv, const char *pname, const char *outname, const char *errname, int *status, int *err); # 637 "/home/giulianob/gcc_git_gnu/gcc/libiberty/../include/libiberty.h" extern int pexecute (const char *, char * const *, const char *, const char *, char **, char **, int); extern int pwait (int, int *, int); extern void *bsearch_r (const void *, const void *, size_t, size_t, int (*)(const void *, const void *, void *), void *); # 661 "/home/giulianob/gcc_git_gnu/gcc/libiberty/../include/libiberty.h" extern char *xasprintf (const char *, ...) __attribute__ ((__malloc__)) __attribute__ ((__format__ (__printf__, 1, 2))) __attribute__ ((__nonnull__ (1))); # 673 "/home/giulianob/gcc_git_gnu/gcc/libiberty/../include/libiberty.h" extern char *xvasprintf (const char *, va_list) __attribute__ ((__malloc__)) __attribute__ ((__format__ (__printf__, 1, 0))) __attribute__ ((__nonnull__ (1))); # 722 "/home/giulianob/gcc_git_gnu/gcc/libiberty/../include/libiberty.h" extern void setproctitle (const char *name, ...); extern void stack_limit_increase (unsigned long); # 735 "/home/giulianob/gcc_git_gnu/gcc/libiberty/../include/libiberty.h" extern void *C_alloca (size_t) __attribute__ ((__malloc__)); # 43 "/home/giulianob/gcc_git_gnu/gcc/libiberty/getpwd.c" 2 # 67 "/home/giulianob/gcc_git_gnu/gcc/libiberty/getpwd.c" char * getpwd (void) { static char *pwd; static int failure_errno; char *p = pwd; size_t s; struct stat dotstat, pwdstat; if (!p && !( # 77 "/home/giulianob/gcc_git_gnu/gcc/libiberty/getpwd.c" 3 4 (*__errno_location ()) # 77 "/home/giulianob/gcc_git_gnu/gcc/libiberty/getpwd.c" = failure_errno)) { if (! ((p = getenv ("PWD")) != 0 && *p == '/' && stat (p, &pwdstat) == 0 && stat (".", &dotstat) == 0 && dotstat.st_ino == pwdstat.st_ino && dotstat.st_dev == pwdstat.st_dev)) for (s = ( # 87 "/home/giulianob/gcc_git_gnu/gcc/libiberty/getpwd.c" 3 4 4096 # 87 "/home/giulianob/gcc_git_gnu/gcc/libiberty/getpwd.c" + 1); !getcwd (p = ((char *) xmalloc (sizeof (char) * (s))), s); s *= 2) { int e = # 89 "/home/giulianob/gcc_git_gnu/gcc/libiberty/getpwd.c" 3 4 (*__errno_location ()) # 89 "/home/giulianob/gcc_git_gnu/gcc/libiberty/getpwd.c" ; free (p); if (e != # 92 "/home/giulianob/gcc_git_gnu/gcc/libiberty/getpwd.c" 3 4 34 # 92 "/home/giulianob/gcc_git_gnu/gcc/libiberty/getpwd.c" ) { # 95 "/home/giulianob/gcc_git_gnu/gcc/libiberty/getpwd.c" 3 4 (*__errno_location ()) # 95 "/home/giulianob/gcc_git_gnu/gcc/libiberty/getpwd.c" = failure_errno = e; p = 0; break; } } pwd = p; } return p; }
the_stack_data/248581021.c
/* * SimpleSection.c * * Linux: * gcc -c SimpleSection.c * * Windows: * cl SimpleSection.c /c /Za */ int printf( const char* format, ... ); int global_init_var = 84; int global_uninit_var; void func1( int i ) { printf( "%d\n", i ); } int main(void) { static int static_var = 85; static int static_var2; int a = 1; int b; func1( static_var + static_var2 + a + b ); return a; }
the_stack_data/1219319.c
int mySqrt(int x){ double y = 1; for(int i=0; i<20; i++) { y = y / 2 + x / (2 * y); } return y; }
the_stack_data/86075656.c
#include <stdio.h> #include <stdlib.h> #include <pthread.h> #include <semaphore.h> #include <string.h> #include <time.h> #include <math.h> #include <sys/types.h> #include <sys/ipc.h> #include <sys/shm.h> #define SIZE_GAU 8 #define SIZE_JVL 15 #define KEY 1234 typedef struct DINNER { int JAVA_COUNT; sem_t table; sem_t hungry; }dinner; dinner *ptr; void replaceJAVALIS() { sem_wait(&ptr->table); ptr->JAVA_COUNT = SIZE_JVL; printf("\n < The Cooker Made his Magic >"); sem_post(&ptr->hungry); } void *cooker() { while(1) { replaceJAVALIS(); } } int main(int args, char *argv[]) { key_t key; int i = 0; int shmid; pthread_t COOKER; printf("1\n"); //generating a public key key = ftok("/home/ecomp/a1543857/SO/Shared Memory/shrd.txt", KEY); printf("2\n"); //creating n saving shared memory shmid = shmget(key, sizeof(struct dinner*), 0); if(shmid == -1) { perror("shmget"); exit(1); } printf("3\n"); //connecting process with memory space ptr = shmat(shmid, 0, 0); if((int) ptr == -1) { perror("shmat"); exit(1); } ptr->JAVA_COUNT = SIZE_JVL; printf("4\n"); pthread_create(&COOKER, NULL, cooker, NULL); sleep(5); return 1; }
the_stack_data/108621.c
/* * Copyright © 2014-2017 Broadcom * * Permission is hereby granted, 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 (including the next * paragraph) 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. */ /** * @file v3d_simulator_hw.c * * Implements the actual HW interaction betweeh the GL driver's VC5 simulator and the simulator. * * The register headers between V3D versions will have conflicting defines, so * all register interactions appear in this file and are compiled per V3D version * we support. */ #ifdef USE_V3D_SIMULATOR #include "v3d_screen.h" #include "v3d_context.h" #include "v3d_simulator_wrapper.h" #define HW_REGISTER_RO(x) (x) #define HW_REGISTER_RW(x) (x) #if V3D_VERSION >= 41 #include "libs/core/v3d/registers/4.1.34.0/v3d.h" #else #include "libs/core/v3d/registers/3.3.0.0/v3d.h" #endif #define V3D_WRITE(reg, val) v3d_hw_write_reg(v3d, reg, val) #define V3D_READ(reg) v3d_hw_read_reg(v3d, reg) static void v3d_invalidate_l3(struct v3d_hw *v3d) { if (!v3d_hw_has_gca(v3d)) return; #if V3D_VERSION < 40 uint32_t gca_ctrl = V3D_READ(V3D_GCA_CACHE_CTRL); V3D_WRITE(V3D_GCA_CACHE_CTRL, gca_ctrl | V3D_GCA_CACHE_CTRL_FLUSH_SET); V3D_WRITE(V3D_GCA_CACHE_CTRL, gca_ctrl & ~V3D_GCA_CACHE_CTRL_FLUSH_SET); #endif } /* Invalidates the L2C cache. This is a read-only cache for uniforms and instructions. */ static void v3d_invalidate_l2c(struct v3d_hw *v3d) { if (V3D_VERSION >= 33) return; V3D_WRITE(V3D_CTL_0_L2CACTL, V3D_CTL_0_L2CACTL_L2CCLR_SET | V3D_CTL_0_L2CACTL_L2CENA_SET); } /* Invalidates texture L2 cachelines */ static void v3d_invalidate_l2t(struct v3d_hw *v3d) { V3D_WRITE(V3D_CTL_0_L2TFLSTA, 0); V3D_WRITE(V3D_CTL_0_L2TFLEND, ~0); V3D_WRITE(V3D_CTL_0_L2TCACTL, V3D_CTL_0_L2TCACTL_L2TFLS_SET | (0 << V3D_CTL_0_L2TCACTL_L2TFLM_LSB)); } /* Invalidates the slice caches. These are read-only caches. */ static void v3d_invalidate_slices(struct v3d_hw *v3d) { V3D_WRITE(V3D_CTL_0_SLCACTL, ~0); } static void v3d_invalidate_caches(struct v3d_hw *v3d) { v3d_invalidate_l3(v3d); v3d_invalidate_l2c(v3d); v3d_invalidate_l2t(v3d); v3d_invalidate_slices(v3d); } static uint32_t g_gmp_ofs; static void v3d_reload_gmp(struct v3d_hw *v3d) { /* Completely reset the GMP. */ V3D_WRITE(V3D_GMP_0_CFG, V3D_GMP_0_CFG_PROTENABLE_SET); V3D_WRITE(V3D_GMP_0_TABLE_ADDR, g_gmp_ofs); V3D_WRITE(V3D_GMP_0_CLEAR_LOAD, ~0); while (V3D_READ(V3D_GMP_0_STATUS) & V3D_GMP_0_STATUS_CFG_BUSY_SET) { ; } } int v3dX(simulator_submit_tfu_ioctl)(struct v3d_hw *v3d, struct drm_v3d_submit_tfu *args) { int last_vtct = V3D_READ(V3D_TFU_CS) & V3D_TFU_CS_CVTCT_SET; V3D_WRITE(V3D_TFU_IIA, args->iia); V3D_WRITE(V3D_TFU_IIS, args->iis); V3D_WRITE(V3D_TFU_ICA, args->ica); V3D_WRITE(V3D_TFU_IUA, args->iua); V3D_WRITE(V3D_TFU_IOA, args->ioa); V3D_WRITE(V3D_TFU_IOS, args->ios); V3D_WRITE(V3D_TFU_COEF0, args->coef[0]); V3D_WRITE(V3D_TFU_COEF1, args->coef[1]); V3D_WRITE(V3D_TFU_COEF2, args->coef[2]); V3D_WRITE(V3D_TFU_COEF3, args->coef[3]); V3D_WRITE(V3D_TFU_ICFG, args->icfg); while ((V3D_READ(V3D_TFU_CS) & V3D_TFU_CS_CVTCT_SET) == last_vtct) { v3d_hw_tick(v3d); } return 0; } int v3dX(simulator_get_param_ioctl)(struct v3d_hw *v3d, struct drm_v3d_get_param *args) { static const uint32_t reg_map[] = { [DRM_V3D_PARAM_V3D_UIFCFG] = V3D_HUB_CTL_UIFCFG, [DRM_V3D_PARAM_V3D_HUB_IDENT1] = V3D_HUB_CTL_IDENT1, [DRM_V3D_PARAM_V3D_HUB_IDENT2] = V3D_HUB_CTL_IDENT2, [DRM_V3D_PARAM_V3D_HUB_IDENT3] = V3D_HUB_CTL_IDENT3, [DRM_V3D_PARAM_V3D_CORE0_IDENT0] = V3D_CTL_0_IDENT0, [DRM_V3D_PARAM_V3D_CORE0_IDENT1] = V3D_CTL_0_IDENT1, [DRM_V3D_PARAM_V3D_CORE0_IDENT2] = V3D_CTL_0_IDENT2, }; switch (args->param) { case DRM_V3D_PARAM_SUPPORTS_TFU: args->value = 1; return 0; } if (args->param < ARRAY_SIZE(reg_map) && reg_map[args->param]) { args->value = V3D_READ(reg_map[args->param]); return 0; } fprintf(stderr, "Unknown DRM_IOCTL_VC5_GET_PARAM(%lld)\n", (long long)args->value); abort(); } static struct v3d_hw *v3d_isr_hw; static void v3d_isr(uint32_t hub_status) { struct v3d_hw *v3d = v3d_isr_hw; /* Check the per-core bits */ if (hub_status & (1 << 0)) { uint32_t core_status = V3D_READ(V3D_CTL_0_INT_STS); V3D_WRITE(V3D_CTL_0_INT_CLR, core_status); if (core_status & V3D_CTL_0_INT_STS_INT_OUTOMEM_SET) { uint32_t size = 256 * 1024; uint32_t offset = v3d_simulator_get_spill(size); v3d_reload_gmp(v3d); V3D_WRITE(V3D_PTB_0_BPOA, offset); V3D_WRITE(V3D_PTB_0_BPOS, size); return; } if (core_status & V3D_CTL_0_INT_STS_INT_GMPV_SET) { fprintf(stderr, "GMP violation at 0x%08x\n", V3D_READ(V3D_GMP_0_VIO_ADDR)); abort(); } else { fprintf(stderr, "Unexpected ISR with core status 0x%08x\n", core_status); } abort(); } return; } void v3dX(simulator_init_regs)(struct v3d_hw *v3d) { #if V3D_VERSION == 33 /* Set OVRTMUOUT to match kernel behavior. * * This means that the texture sampler uniform configuration's tmu * output type field is used, instead of using the hardware default * behavior based on the texture type. If you want the default * behavior, you can still put "2" in the indirect texture state's * output_type field. */ V3D_WRITE(V3D_CTL_0_MISCCFG, V3D_CTL_1_MISCCFG_OVRTMUOUT_SET); #endif uint32_t core_interrupts = (V3D_CTL_0_INT_STS_INT_GMPV_SET | V3D_CTL_0_INT_STS_INT_OUTOMEM_SET); V3D_WRITE(V3D_CTL_0_INT_MSK_SET, ~core_interrupts); V3D_WRITE(V3D_CTL_0_INT_MSK_CLR, core_interrupts); v3d_isr_hw = v3d; v3d_hw_set_isr(v3d, v3d_isr); } void v3dX(simulator_submit_cl_ioctl)(struct v3d_hw *v3d, struct drm_v3d_submit_cl *submit, uint32_t gmp_ofs) { g_gmp_ofs = gmp_ofs; v3d_reload_gmp(v3d); v3d_invalidate_caches(v3d); if (submit->qma) { V3D_WRITE(V3D_CLE_0_CT0QMA, submit->qma); V3D_WRITE(V3D_CLE_0_CT0QMS, submit->qms); } #if V3D_VERSION >= 41 if (submit->qts) { V3D_WRITE(V3D_CLE_0_CT0QTS, V3D_CLE_0_CT0QTS_CTQTSEN_SET | submit->qts); } #endif V3D_WRITE(V3D_CLE_0_CT0QBA, submit->bcl_start); V3D_WRITE(V3D_CLE_0_CT0QEA, submit->bcl_end); /* Wait for bin to complete before firing render. The kernel's * scheduler implements this using the GPU scheduler blocking on the * bin fence completing. (We don't use HW semaphores). */ while (V3D_READ(V3D_CLE_0_CT0CA) != V3D_READ(V3D_CLE_0_CT0EA)) { v3d_hw_tick(v3d); } v3d_invalidate_caches(v3d); V3D_WRITE(V3D_CLE_0_CT1QBA, submit->rcl_start); V3D_WRITE(V3D_CLE_0_CT1QEA, submit->rcl_end); while (V3D_READ(V3D_CLE_0_CT1CA) != V3D_READ(V3D_CLE_0_CT1EA) || V3D_READ(V3D_CLE_1_CT1CA) != V3D_READ(V3D_CLE_1_CT1EA)) { v3d_hw_tick(v3d); } } #endif /* USE_V3D_SIMULATOR */
the_stack_data/59511473.c
#include <stdio.h> int main() { int i; i=1; do { printf("%d\n", i); i++; } while(i<=10); return 0; }
the_stack_data/23575218.c
#include<stdio.h> #include<stdlib.h> #define N 10 typedef struct item{ int key,data; struct item* next; }item; item* hTable[N]; item* createItem(int key,int data){ item* newItem = (item*)malloc(sizeof(item)); newItem->key = key; newItem->data = data; newItem->next = NULL; } int hash(int x){ return (x%N); } void insert(int key,int data){ int idx=hash(key); item** curItem = &(hTable[idx]); while((*curItem)!=NULL) curItem = &((*curItem)->next); (*curItem) = createItem(key,data); } item* find(int key){ int idx = hash(key); item* curItem = hTable[idx]; while(curItem != NULL && curItem->key != key) curItem = curItem->next; return curItem; } void printTable(){ for(int i=0;i<N;i++){ printf("%d: ",i); item* curItem = hTable[i]; while(curItem!=NULL){ printf("(%d, %d) ",curItem->key,curItem->data); curItem = curItem->next; } printf("\n"); } } int main(){ insert(1, 20); insert(12, 70); insert(22, 80); insert(4, 25); insert(52, 44); insert(44, 32); insert(7, 11); insert(53, 78); insert(17, 97); printTable(); int x = 18; item* a = find(x); if(a!=NULL) printf("found (%d,%d)\n",x,a->data); else printf("%d hasn't been found\n",x); return 0; }
the_stack_data/39612.c
#include <unistd.h> #include <stdio.h> int main(void) { printf("exit() test"); exit(0); }
the_stack_data/220456871.c
/* Test and timing harness program for developing a dense matrix multiplication routine for the CS3014 module. Authors: Basil L. Contovounesios Ben Lynch Simon Markham */ #include <stdio.h> #include <stdlib.h> #include <sys/time.h> #include <assert.h> #include <omp.h> #include <xmmintrin.h> #include <pthread.h> /* Uncomment the following to use sysconf(_SC_NPROCESSORS_ONLN) to determine number of online cores on the system. */ // #include <unistd.h> /* The following two definitions of DEBUGGING control whether or not debugging information is written out. Defining DEBUG, e.g. via preprocessor options at compilation, puts the program into debugging mode. */ #ifdef DEBUG #define DEBUGGING(_x) _x #else #define DEBUGGING(_x) #endif /* The following definition reflects the number of online cores on the system and determines the maximum number of pthreads created. It defaults to 64, which is the number of cores on the target machine stoker. It is intended to be defined at compilation via a preprocessor option if run on a different target. */ #ifndef NCORES #define NCORES 64 #endif /* Complex number unit stored in matrices. */ struct complex { float real; float imag; }; /* Write matrix to stdout. */ void write_out(struct complex ** a, int dim1, int dim2) { for (int i = 0; (i < dim1); i++) { for (int j = 0; (j < dim2 - 1); j++) { printf("%f + %fi ", a[i][j].real, a[i][j].imag); } printf("%f + %fi\n", a[i][dim2 - 1].real, a[i][dim2 - 1].imag); } } /* Create new empty matrix. */ struct complex ** new_empty_matrix(int dim1, int dim2) { struct complex ** result = malloc(sizeof(struct complex*) * dim1); struct complex * new_matrix = malloc(sizeof(struct complex) * dim1 * dim2); for (int i = 0; (i < dim1); i++) { result[i] = &new_matrix[i * dim2]; } return result; } /* Free matrix. */ void free_matrix(struct complex ** matrix) { free (matrix[0]); // Free the contents free (matrix); // Free the header } /* Take a copy of the matrix and return in a newly allocated matrix. */ struct complex ** copy_matrix(struct complex ** source_matrix, int dim1, int dim2) { struct complex ** result = new_empty_matrix(dim1, dim2); for (int i = 0; (i < dim1); i++) { for (int j = 0; (j < dim2); j++) { result[i][j] = source_matrix[i][j]; } } return result; } /* Create a matrix and fill it with random numbers. */ struct complex ** gen_random_matrix(int dim1, int dim2) { const int random_range = 512; struct complex ** result; struct timeval seedtime; int seed; result = new_empty_matrix(dim1, dim2); // Use the microsecond part of the current time as a pseudo-random seed gettimeofday(&seedtime, NULL); seed = seedtime.tv_usec; srandom(seed); // Fill the matrix with random numbers for (int i = 0; (i < dim1); i++) { for (int j = 0; (j < dim2); j++) { // Evenly generate values in the range [0, random_range - 1) result[i][j].real = (float)(random() % random_range); result[i][j].imag = (float)(random() % random_range); // At no loss of precision, negate the values sometimes so the range is // now (-(random_range - 1), random_range - 1) if (random() & 1) result[i][j].real = -result[i][j].real; if (random() & 1) result[i][j].imag = -result[i][j].imag; } } return result; } /* Check the sum of absolute differences is within reasonable epsilon. */ void check_result(struct complex ** result, struct complex ** control, int dim1, int dim2) { double diff = 0.0; double sum_abs_diff = 0.0; const double EPSILON = 0.0625; for (int i = 0; (i < dim1); i++) { for (int j = 0; (j < dim2); j++) { diff = abs(control[i][j].real - result[i][j].real); sum_abs_diff += diff; diff = abs(control[i][j].imag - result[i][j].imag); sum_abs_diff += diff; } } if (sum_abs_diff > EPSILON) { fprintf(stderr, "WARNING: sum of absolute differences (%f) > EPSILON (%f)\n", sum_abs_diff, EPSILON); } } /* Multiply matrix A times matrix B and put result in matrix C. */ void matmul(struct complex ** A, struct complex ** B, struct complex ** C, int a_dim1, int a_dim2, int b_dim2) { struct complex sum; for (int i = 0; (i < a_dim1); i++) { for(int j = 0; (j < b_dim2); j++) { sum = (struct complex){0.0, 0.0}; for (int k = 0; (k < a_dim2); k++) { // The following code does: sum += A[i][k] * B[k][j]; sum.real += A[i][k].real * B[k][j].real - A[i][k].imag * B[k][j].imag; sum.imag += A[i][k].real * B[k][j].imag + A[i][k].imag * B[k][j].real; } C[i][j] = sum; } } } /* The fast version of matmul() written by the team. */ void team_matmul(struct complex ** A, struct complex ** B, struct complex ** C, int a_dim1, int a_dim2, int b_dim2) { struct complex sum; #pragma omp parallel for if (a_dim1 >= NCORES) for (int i = 0; i < a_dim1; i++) { #pragma omp parallel for if (b_dim2 >= NCORES) private(sum) for(int j = 0; j < b_dim2; j++) { sum = (struct complex){0.0, 0.0}; for (int k = 0; k < a_dim2; k++) { // The following code does: sum += A[i][k] * B[k][j]; sum.real += A[i][k].real * B[k][j].real - A[i][k].imag * B[k][j].imag; sum.imag += A[i][k].real * B[k][j].imag + A[i][k].imag * B[k][j].real; } C[i][j] = sum; } } } /* Returns the difference, in microseconds, between the two given times. */ long long time_diff(struct timeval * start, struct timeval *end) { return ((end->tv_sec - start->tv_sec) * 1000000L) + (end->tv_usec - start->tv_usec); } /* Main harness. */ int main(int argc, char ** argv) { struct complex ** A, ** B, ** C; struct complex ** ctrl_matrix; long long ctrl_time, mult_time; int a_dim1, a_dim2, b_dim1, b_dim2; struct timeval time0, time1, time2; double speedup; if (argc != 5) { fputs("Usage: matMul <A nrows> <A ncols> <B nrows> <B ncols>\n", stderr); exit(1); } else { a_dim1 = atoi(argv[1]); a_dim2 = atoi(argv[2]); b_dim1 = atoi(argv[3]); b_dim2 = atoi(argv[4]); } // Check the matrix sizes are compatible if (a_dim2 != b_dim1) { fprintf(stderr, "FATAL number of columns of A (%d) does not " "match number of rows of B (%d)\n", a_dim2, b_dim1); exit(1); } // Allocate the matrices A = gen_random_matrix(a_dim1, a_dim2); B = gen_random_matrix(b_dim1, b_dim2); C = new_empty_matrix(a_dim1, b_dim2); ctrl_matrix = new_empty_matrix(a_dim1, b_dim2); DEBUGGING({ puts("Matrix A:"); write_out(A, a_dim1, a_dim2); puts("\nMatrix B:"); write_out(B, b_dim1, b_dim2); puts(""); }) // Record control start time gettimeofday(&time0, NULL); // Use a simple matmul routine to produce control result matmul(A, B, ctrl_matrix, a_dim1, a_dim2, b_dim2); DEBUGGING( { puts("Resultant matrix:"); write_out(ctrl_matrix, a_dim1, b_dim2); } ) // Record start time gettimeofday(&time1, NULL); // Perform matrix multiplication team_matmul(A, B, C, a_dim1, a_dim2, b_dim2); // Record finishing time gettimeofday(&time2, NULL); // Compute elapsed times and speedup factor ctrl_time = time_diff(&time0, &time1); mult_time = time_diff(&time1, &time2); speedup = (float)ctrl_time / mult_time; printf("Control time: %lld μs\n", ctrl_time); printf("Matmul time: %lld μs\n", mult_time); if ((mult_time > 0) && (ctrl_time > 0)) { printf("Speedup: %.2fx\n", speedup); } // Now check that team_matmul() gives the same answer as the control check_result(C, ctrl_matrix, a_dim1, b_dim2); DEBUGGING({ puts("Resultant matrix:"); write_out(C, a_dim1, b_dim2); }) // Free all matrices free_matrix(A); free_matrix(B); free_matrix(C); free_matrix(ctrl_matrix); return EXIT_SUCCESS; }
the_stack_data/150142338.c
// RUN: jlang-cc %s -E | grep '#pragma x y z' && // RUN: jlang-cc %s -E | grep '#pragma a b c' _Pragma("x y z") _Pragma("a b c")
the_stack_data/40762552.c
#include<stdio.h> #include<stdbool.h> #define max 50 int front= -1; int rear = -1; int Queue[max]; bool isfull(int size) { if(rear ==( size - 1)) return true; else return false; } bool isempty() { if (rear < 0 || front >= rear) return true; else return false; } void enqueue(int queue[] ,int size){ if(isfull(size)){ printf("Queue is full"); } else { int item; printf("Enter the value to be inserted :"); scanf("%d",&item); rear++; queue[rear] = item; printf("%d is added to Queue",item); } } void dequeue(int queue[]){ if(!isempty()){ ++front; int data=queue[front]; printf("The dequeued value is %d\n",data); }else{ printf("The Queue is empty\n"); } } void display(int queue[]){ int i; if(isempty()){ printf(" Queue is empty"); } else { printf("Elements in the queue:\n"); for(i=front+1;i<rear+1;i++){ printf("%d\t",queue[i]); } } } int main(){ int choice,x,size; printf("Enter the size of the queue:"); scanf("%d",&size); do{ printf("\nEnter the choice of function you want to perform: 1:enqueue 2:dequeue 3:display 4:exit\n"); scanf("%d",&choice); switch(choice){ case 1 :enqueue(Queue,size); break; case 2 :dequeue(Queue); break; case 3: display(Queue); break; case 4 :printf("existing from the queue operation"); break; default: printf("invalid choice"); } } while(choice!=4); return 0; }
the_stack_data/23574190.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 int input[1] , unsigned int 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 RandomFunc(unsigned int input[1] , unsigned int output[1] ) { unsigned int state[1] ; unsigned int local1 ; { state[0UL] = input[0UL] + 4284877637U; local1 = 0UL; while (local1 < 0U) { if (! (state[0UL] > local1)) { state[local1] += state[0UL]; } local1 += 2UL; } output[0UL] = state[0UL] + 255873917UL; } } int main(int argc , char *argv[] ) { unsigned int input[1] ; unsigned int output[1] ; int randomFuns_i5 ; unsigned int 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 int )strtoul(argv[randomFuns_i5 + 1], 0, 10); input[randomFuns_i5] = randomFuns_value6; randomFuns_i5 ++; } RandomFunc(input, output); if (output[0] == 245796603U) { printf("You win!\n"); } else { } randomFuns_main_i7 = 0; while (randomFuns_main_i7 < 1) { printf("%u\n", output[randomFuns_main_i7]); randomFuns_main_i7 ++; } } } void megaInit(void) { { } }
the_stack_data/7949167.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_isascii.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: reezeddi <[email protected]> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/17 19:01:27 by reezeddi #+# #+# */ /* Updated: 2020/04/17 19:01:45 by reezeddi ### ########.fr */ /* */ /* ************************************************************************** */ int ft_isascii(int c) { return (c >= 0 && c <= 127); }
the_stack_data/220454522.c
// Written by mr-andrej // "Growth of a Population" by g964 // https://www.codewars.com/kata/563b662a59afc2b5120000c6 // Kyu: 7 int nbYear(int p0, double percent, int aug, int p) { int n; int population = p0; for (n = 0; !(population >= p); n++) population += (population * percent / 100) + aug; return (n); }
the_stack_data/161081741.c
#include <inttypes.h> #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { int32_t i = 0; while (i <= 10) { printf("%d\n", i); i++; } /* the same done using ``for'' */ for (int32_t j = 0; j <= 10; j++) { printf("%d\n", j); } exit(EXIT_SUCCESS); }
the_stack_data/179831488.c
int api_open_win(char *buf, int xsize, int ysize, int col_inv, char *title); void api_boxfill_win(int win, int x0, int y0, int x1, int y1, int col); void api_malloc_init(void); void *api_malloc(int size); void api_point(int win, int x, int y, int col); void api_end(void); int main(void) { api_malloc_init(); char *buf = api_malloc(150 * 100); int win = api_open_win(buf, 150, 100, -1, "star1"); api_boxfill_win(win, 6, 26, 143, 93, 0); api_point(win, 75, 59, 3); api_end(); return 0; }
the_stack_data/94303.c
// RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm %s -o - | grep 'declare i32 @printf' | count 1 // RUN: %clang_cc1 -triple i386-unknown-unknown -O2 -emit-llvm %s -o - | grep 'declare i32 @puts' | count 1 // RUN: %clang_cc1 -triple i386-unknown-unknown -ffreestanding -O2 -emit-llvm %s -o - | grep 'declare i32 @puts' | count 0 int printf(const char *, ...); void f0() { printf("hello\n"); }
the_stack_data/59513920.c
#include <stdio.h> #include <stdlib.h> int nomain(void) { printf("test nomain\n"); exit(0); // not return // as no CRT init, so not could return. // CRT -> _start -> main // return of main -> exit // so now, need manually exit return 0; }
the_stack_data/156393109.c
#include <stdio.h> #include <stdlib.h> typedef struct point { int x,y; } point; typedef struct rect { point pt1, pt2; } rect; point addpoint(point p1, point p2) { /* add two points */ p1.x += p2.x; p1.y += p2.y; return p1; } #define min(a, b) ((a) < (b) ? (a) : (b)) #define max(a, b) ((a) > (b) ? (a) : (b)) rect canonrect(rect r) { /* canonicalize rectangle coordinates */ rect temp; temp.pt1.x = min(r.pt1.x, r.pt2.x); temp.pt1.y = min(r.pt1.y, r.pt2.y); temp.pt2.x = max(r.pt1.x, r.pt2.x); temp.pt2.y = max(r.pt1.y, r.pt2.y); return temp; } point makepoint(int x, int y) { /* make a point from x and y components */ point p; p.x = x; p.y = y; return p; } rect makerect(point p1, point p2) { /* make a rectangle from two points */ rect r; r.pt1 = p1; r.pt2 = p2; return canonrect(r); } int ptinrect(point p, rect r) { /* is p in r? */ return p.x >= r.pt1.x && p.x < r.pt2.x && p.y >= r.pt1.y && p.y < r.pt2.y; } struct odd {char a[3]; } y = {{'a', 'b', 0}}; void odd(struct odd y) { struct odd x = y; printf("%s\n", x.a); } int main(void) { int i; point x, origin = { 0, 0 }, maxpt = { 320, 320 }; point pts[] = { -1, -1, 1, 1, 20, 300, 500, 400 }; rect screen = makerect(addpoint(maxpt, makepoint(-10, -10)), addpoint(origin, makepoint(10, 10))); for (i = 0; i < sizeof pts/sizeof pts[0]; i++) { printf("(%d,%d) is ", pts[i].x, (x = makepoint(pts[i].x, pts[i].y)).y); if (ptinrect(x, screen) == 0) printf("not "); printf("within [%d,%d; %d,%d]\n", screen.pt1.x, screen.pt1.y, screen.pt2.x, screen.pt2.y); } odd(y); exit(0); return 0; }
the_stack_data/179830700.c
#include <stdio.h> int gval; int main(void) { char buf[256]; printf("&gval %p\n", (void *)&gval); printf("Input initial value.\n"); fgets(buf, sizeof(buf), stdin); sscanf(buf, "%d", &gval); for (;;) { printf("gval %d\n", gval); getchar(); gval++; } }
the_stack_data/74645.c
void scilab_rt_sum_d2_d0(int sin00, int sin01, double in0[sin00][sin01], double* out0) { int i; int j; double val0 = 0; for (i = 0; i < sin00; ++i) { for (j = 0; j < sin01; ++j) { val0 += in0[i][j]; } } *out0 = val0; }
the_stack_data/53103.c
#include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <pthread.h> #include <inttypes.h> //les nombres qu'on doit calculer pour chaque thread uint64_t n1,n2; //fichier de lecture FILE* input; // mutex qui nous permet de differencier les threads pthread_mutex_t mutexLecture; /* * Procedure qui affiche les facteurs premiers d'un nombre sur 64 bits * Il regard,d'abord, si le nombre est pair * et apres il prend tout ses facteurs impaires */ void print_prime_factors(uint64_t n) { uint64_t i; printf("%" SCNu64":",n); if(n%2==0) { n=n/2; printf(" 2"); while(n%2==0) { n=n/2; printf(" 2"); } } for(i=3;i<=n;i+=2) { if(n%i==0) { n=n/i; printf(" %" SCNu64,i); while(n%i==0) { n=n/i; printf(" %" SCNu64,i); } } } printf("\n"); } /* * Procedure du premier thread */ void print_prime_factors_t1(void) { print_prime_factors(n1); } /* * Procedure du deuxieme thread */ void print_prime_factors_t2(void) { print_prime_factors(n2); } /* * Procedure qui declanche le premier thread */ void Compute_Simul_t1(void) { while(1) { pthread_mutex_lock(&mutexLecture); if(fscanf(input,"%" SCNu64,&n1)==1) { pthread_mutex_unlock(&mutexLecture); print_prime_factors_t1(); } else { pthread_mutex_unlock(&mutexLecture); break; } } } /* * Procedure qui declanche le deuxieme thread */ void Compute_Simul_t2(void) { while(1) { pthread_mutex_lock(&mutexLecture); if(fscanf(input,"%" SCNu64,&n2)==1) { pthread_mutex_unlock(&mutexLecture); print_prime_factors_t2(); } else { pthread_mutex_unlock(&mutexLecture); break; } } } /* * Procedure Main du fichier source */ int main() { //int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg); //int pthread_join(pthread_t thread, void **retval); //int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr); //freopen("test.in","r",stdin); pthread_t t1,t2; //freopen("test.out","w",stdout); input = fopen("test.in","r"); pthread_mutex_init(&mutexLecture,NULL); pthread_create(&t1,NULL,(void*) Compute_Simul_t1,NULL); pthread_create(&t2,NULL,(void*) Compute_Simul_t2,NULL); pthread_join(t1, NULL); pthread_join(t2, NULL); pthread_mutex_destroy(&mutexLecture); return 0; }
the_stack_data/156392281.c
char ERROR_UNAUTHORIZED[] = "{\"error\":{\"message\":\"Unauthorized\",\"code\":401}}"; char ERROR_BAD_REQUEST[] = "{\"error\":{\"message\":\"Bad Request\",\"code\":400}}"; char ERROR_UNKNOW[] = "{\"error\":{\"message\":\"Unknow\",\"code\":-1}}"; char ERROR_FAILED_LOGIN[] = "{\"error\":{\"message\":\"Username or Password incorrect\",\"code\":201}}"; char ERROR_USERNAME_TAKEN[] = "{\"error\":{\"message\":\"Username taken\",\"code\":202}}"; char ERROR_INVALID_TOKEN[] = "{\"error\":{\"message\":\"Invalid Session Token\",\"code\":209}}";
the_stack_data/145676.c
void checkpoint() { } struct S { int c1; char c2; }; struct S st = {1, 'x'}; int main() { checkpoint(); return 0; }
the_stack_data/61076209.c
//file: _insn_test_st1_add_X1.c //op=208 #include <stdio.h> #include <stdlib.h> void func_exit(void) { printf("%s\n", __func__); exit(0); } void func_call(void) { printf("%s\n", __func__); exit(0); } unsigned long mem[2] = { 0x94fce0885d473733, 0xe22608b00f39a4c5 }; int main(void) { unsigned long a[4] = { 0, 0 }; asm __volatile__ ( "moveli r47, -21466\n" "shl16insli r47, r47, 11354\n" "shl16insli r47, r47, -10374\n" "shl16insli r47, r47, 87\n" "moveli r29, 29514\n" "shl16insli r29, r29, 14828\n" "shl16insli r29, r29, 1013\n" "shl16insli r29, r29, 14302\n" "move r47, %2\n" "{ fnop ; st1_add r47, r29, -39 }\n" "move %0, r47\n" "move %1, r29\n" :"=r"(a[0]),"=r"(a[1]) : "r"(mem)); printf("%016lx %016lx\n", mem[0], mem[1]); printf("%016lx\n", a[0]); printf("%016lx\n", a[1]); return 0; }
the_stack_data/67325192.c
// Definition of NULL #include <stdio.h> void memcopy04(int size, char* src, char* dst) { int i; if (src!=NULL && dst!=NULL) { char* s = (char*) src; char* d = (char*) dst; for (i=0; i<size; i++) *d++ = *s++; } }
the_stack_data/225144140.c
#include<stdio.h> #include<stdlib.h> struct Node{ struct Node* left; int data; struct Node* right; }; struct Node* getNewNode(int x){ struct Node* temp=(struct Node*)malloc(sizeof(struct Node)); temp->data=x; temp->left=NULL; temp->right=NULL; return temp; } struct Node* Insert(struct Node* root,int x){ struct Node* newNode= getNewNode(x); if(root==NULL){ root=newNode; return root; } else if(x < root->data){ root->left=Insert(root->left,x); } else{ root->right= Insert(root->right,x); } return root; } struct Node* FindMin(struct Node* root){ struct Node* temp=root; while(temp->left!=NULL){ temp=temp->left; } return temp; } struct Node* search(struct Node* root,int x){ if(root==NULL) return NULL; else if(root->data==x) return root; else if(x < root->data) return search(root->left,x); else return search(root->right,x); } struct Node* getsuccessor(struct Node* root,int x){ struct Node* current= search(root,x); if(current==NULL){ return NULL; } else if(current->right!=NULL) return FindMin(current->right); else{ struct Node* successor=NULL; struct Node* ancestor= root; while(ancestor!=current){ if(current->data < ancestor->data){ successor=ancestor; ancestor=ancestor->left; } else{ successor=ancestor; ancestor=ancestor->right; } } return successor; } } int main(){ struct Node* root=NULL; root= Insert(root,5); root= Insert(root,6); root= Insert(root,9); root= Insert(root,7); root= Insert(root,45); struct Node* successor; successor=getsuccessor(root,6); printf("%d",successor->data); }
the_stack_data/182476.c
#include <stdio.h> int main() { int len, num, clone; printf("enter the number "); scanf("%d", &num); len=0; clone=num; while (clone>0) { clone=clone/10; len++; } int digits[len]; for (int i = 1; i <= len; i++) { digits[len - i] = num % 10; num = num / 10; } printf("reversed num is:- "); int reverse=0; int count=1; for (int i = 0; i <len; i++) { reverse+=digits[i]*count; count=count*10; } printf("%d",reverse); }
the_stack_data/25985.c
/* Check basic stack overflow detection. It's difficult to get consistent behaviour across all platforms. For example, x86 w/ gcc-4.3.1 gives Expected: stack array "a" in frame 2 back from here Actual: stack array "beforea" in frame 2 back from here whereas amd64 w/ gcc-4.3.1 gives Expected: stack array "a" in frame 2 back from here Actual: unknown This happens because on x86 the arrays are placed on the stack without holes in between, but not so for amd64. I don't know why. */ #include <stdio.h> __attribute__((noinline)) void foo ( long* sa, int n ) { int i; for (i = 0; i < n; i++) sa[i] = 0; } __attribute__((noinline)) void bar ( long* sa, int n ) { foo(sa, n); } int main ( void ) { int i; long beforea[3]; long a[7]; long aftera[3]; bar(a, 7+1); /* generates error */ bar(a, 7+0); /* generates no error */ for (i = 0; i < 7+1; i++) { a[i] = 0; } {char beforebuf[8]; char buf[8]; char afterbuf[8]; sprintf(buf, "%d", 123456789); return 1 & ((a[4] + beforea[1] + aftera[1] + beforebuf[1] + buf[2] + afterbuf[3]) / 100000) ; } }
the_stack_data/178265828.c
/* * ORVL: Orvibo (S20) Control program. 2017-03-27. SMS. * *---------------------------------------------------------------------- * Copyright 2017 Steven M. Schweda * * This file is part of ORVL. * * ORVL is subject to the terms of the Perl Foundation Artistic License * 2.0. A copy of the License is included in the ORVL kit file * "artistic_license_2_0.txt", and on the Web at: * http://www.perlfoundation.org/artistic_license_2_0 * * "Orvibo" is a trademark of ORVIBO Ltd. http://www.orvibo.com *---------------------------------------------------------------------- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * * C macros for program customization by the user: * * EARLY_RECVFROM Defining EARLY_RECVFROM causes the program to * NO_EARLY_RECVFROM attempt a recvfrom() before sending a message. * May not be useful. * Default: defined, unless NO_EARLY_RECVFROM is * defined. * * NEED_SYS_FILIO_H Use <sys/filio.h> to get FIONBIO defined. * (FIONBIO is used with ioctl().) * * NO_AF_CHECK Define NO_AF_CHECK to disable a check on results * GETADDRINFO_OK from getaddrinfo() (address family == AF_INET). * On VMS VAX systems running TCPIP V5.3 - ECO 4, * an apparent bug causes the check to fail. By * default, on all VMS VAX systems, a work-around * is applied, to avoid the spurious failure. * Define GETADDRINFO_OK to disable the * work-around, without disabling the check. * * NO_OPER_PRIVILEGE On VMS, do not attempt to gain OPER privilege. * * NO_STATE_IN_EXIT_STATUS Define to omit any device state data from * the program exit status. * * ORVL_DDF Default name of the device data file (DDF). * Default: "ORVL_DDF". This name is treated as * an environment variable (VMS: logical name) * which points to an actual file, but if that * translation fails, then the value itself is * used. A simple "ddf" command-line option * enables use of the DDF; an explicit "ddf=name" * command-line option overrides this default file * name. * * RECVFROM_6 The data type to use for arg 6 of recvfrom(). * Default: "unsigned int". Popular alternatives * include "int" and "socklen_t". (If the actual * type has the same size as "unsigned int", then * compiler warnings about mismatched pointer types * are probably harmless.) * * SOCKET_TIMEOUT Time to wait for a device response. * Default: 0.5s (500000 microseconds). * * TASK_RETRY_MAX Number of times to retry a task (send message to * device, receive response from device). * Default: 4. (4 retries means 5 tries, total.) * * TASK_RETRY_WAIT Time to wait before retrying a task. * Default: 0.5s (500 milliseconds). * Must be less than 1.0s (1000 milliseconds). * * USE_FCNTL Use fcntl() to set socket to non-blocking. * Default is to use ioctl(). * * Notes/hints: * * On AIX, try "-DRECVFROM_6=socklen_t", and the appropriate compiler * option to make "char" signed by default (GCC: "-fsigned-char"?). * * On Solaris, try "-DNEED_SYS_FILIO_H" or "-DUSE_FCNTL" to compile, * and "-lsocket" to link. * * Some of this code depends on guesswork, based on some reverse * engineering. In some cases, such as packing some (probable) two-byte * values (where one byte is always zero), it's not clear which two * bytes belong together. Some adjustment may be needed when values * larger than 255 are encountered. * * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /*--------------------------------------------------------------------*/ /* Program identification. */ #define PROGRAM_NAME "ORVL" #define PROGRAM_VERSION_MAJ 0 #define PROGRAM_VERSION_MIN 2 /*--------------------------------------------------------------------*/ /* Header files, and related macros. */ #ifdef VMS # include <prvdef.h> # include <ssdef.h> # include <starlet.h> # include <stsdef.h> #endif /* def VMS */ #ifdef _WIN32 # define _CRT_SECURE_NO_WARNINGS # include <Winsock2.h> # include <Ws2tcpip.h> # define ssize_t SSIZE_T # define BAD_SOCKET( s) ((s) == INVALID_SOCKET) # define CLOSE_SOCKET closesocket # define IOCTL_SOCKET ioctlsocket # define LOCALTIME_R( t, tm) localtime_s( (tm), (t)) /* Note arg order. */ # define STRNCASECMP _strnicmp #else /* def _WIN32 */ # include <unistd.h> # include <netdb.h> # include <netinet/in.h> # include <sys/socket.h> # ifdef USE_FCNTL # include <fcntl.h> # else /* def USE_FCNTL */ # include <sys/ioctl.h> # ifdef NEED_SYS_FILIO_H # include <sys/filio.h> /* For FIONBIO. */ # endif /* def NEED_SYS_FILIO_H */ # endif /* def USE_FCNTL [else] */ # define BAD_SOCKET( s) ((s) < 0) # define CLOSE_SOCKET close # define INVALID_SOCKET (-1) # define IOCTL_SOCKET ioctl # define LOCALTIME_R( t, tm) localtime_r( (t), (tm)) # define SOCKET int # define STRNCASECMP strncasecmp #endif /* def _WIN32 [else] */ #include <ctype.h> #include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> /*--------------------------------------------------------------------*/ /* User-adjustable macros. */ #ifndef NO_EARLY_RECVFROM # define EARLY_RECVFROM /* Perform early recvfrom(). */ #endif /* ndef NO_EARLY_RECVFROM */ #define ORVL_DDF "ORVL_DDF" /* ORVL device data file name. */ # ifndef RECVFROM_6 # define RECVFROM_6 unsigned int /* Type for arg 6 of recvfrom(). */ # endif /* ndef RECVFROM_6 */ /* ("int", "socklen_t", ...?) */ #define SOCKET_TIMEOUT 500000 /* Microseconds. */ #define TASK_RETRY_MAX 4 /* Task retry count, */ #define TASK_RETRY_WAIT 500 /* delay. Milliseconds (< 1000ms). */ /*--------------------------------------------------------------------*/ /* Fixed macros. */ #define DEV_NAME_LEN 16 #define PASSWORD_LEN 12 #define MAC_ADDR_SIZE 6 #define PORT_ORV 10000 /* IP port used for device comm. */ #define TIME_OFS 0x83aa7e80 /* 70y (1970 - 1900). */ #define OMIN( a, b) (((a) <= (b)) ? (a) : (b)) /*--------------------------------------------------------------------*/ /* Data structures. */ typedef struct orv_data_t /* Orvibo device data. */ { struct orv_data_t *next; /* Link to next. */ struct orv_data_t *prev; /* Link to previous. */ unsigned int cnt_flg; /* Count (O)/flag. */ int sort_key; /* Sort key. */ struct in_addr ip_addr; /* IP address (net order). */ unsigned short port; /* IP port (net order). */ short type; /* Device type (icon code). */ unsigned char name[ DEV_NAME_LEN]; /* Device name. */ unsigned char passwd[ PASSWORD_LEN]; /* Remote password. */ unsigned char mac_addr[ MAC_ADDR_SIZE]; /* MAC address. */ char state; /* Device state. */ } orv_data_t; /*--------------------------------------------------------------------*/ /* Symbolic constants. */ /* Debug category flags. */ #define DBG_ACT 0x00000001 /* Action. */ #define DBG_DNS 0x00000002 /* DNS, name resolution. */ #define DBG_DEV 0x00000004 /* Device list. */ #define DBG_FIL 0x00000008 /* Device data file. */ #define DBG_MSI 0x00000010 /* Message in. */ #define DBG_MSO 0x00000020 /* Message out. */ #define DBG_OPT 0x00000040 /* Options. */ #define DBG_SEL 0x00000080 /* Name, address selection. */ #define DBG_SIO 0x00000100 /* Socket I/O. */ #define DBG_VMS 0x00000200 /* VMS-specific. */ #define DBG_WIN 0x00000400 /* Windows-specific. */ /* fprintf_device_list() flags. */ #define FDL_BRIEF 0x00000001 /* Brief. */ #define FDL_DDF 0x00000002 /* Device data file. */ #define FDL_QUIET 0x00000004 /* Quiet. */ #define FDL_SINGLE 0x00000008 /* Single device. */ /* Response types (bit mask). */ #define RSP_CL 0x00000001 /* Subscribe. */ #define RSP_DC 0x00000002 /* Device control (message). */ #define RSP_HB 0x00000004 /* Heartbeat. */ #define RSP_QA 0x00000008 /* Global discovery. */ #define RSP_QG 0x00000010 /* Unit discovery. */ #define RSP_RT 0x00000020 /* Read table. */ #define RSP_SF 0x00000040 /* Device control. */ #define RSP_TM 0x00000080 /* Write Table. */ #define RSP___ 0x80000000 /* Unknown/unrecognized response. */ /* Task codes. */ #define TSK_MIN 0 /* Smallest TSK_xxx value. */ #define TSK_GLOB_DISC_B 0 /* Global discovery, broadcast. */ #define TSK_GLOB_DISC 1 /* Global discovery, specific. */ #define TSK_UNIT_DISC 2 /* Unit discovery. */ #define TSK_SUBSCRIBE 3 /* Subscribe. */ #define TSK_HEARTBEAT 4 /* Heartbeat. */ #define TSK_SW_OFF 5 /* Switch off. */ #define TSK_SW_ON 6 /* Switch on. */ #define TSK_RT_SOCKET 7 /* Read table: socket. */ #define TSK_RT_TIMING 8 /* Read table: timing. */ #define TSK_WT_SOCKET 9 /* Write table: socket. */ #define TSK_WT_TIMING 10 /* Write table: timing. */ #define TSK_MAX 10 /* Largest TSK_xxx value. */ /*--------------------------------------------------------------------*/ /* Global Storage. * Device messages, device type names, command-line keyword arrays. */ static int debug; /* Debug flag(s). */ /* Basic output message content: * [0],[1]: Prefix ("magic key") = "hd". * [2],[3]: Message length. * [4],[5]: Operation code. */ /* Subscribe ("cl" = Claim?). */ static unsigned char cmd_subs[] = { 'h', 'd', 0x00, 0x00, 'c', 'l', /* Prefix, length, op. */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* MAC address (fwd). */ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, /* 0x20 fill. */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* MAC address (rev). */ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 /* 0x20 fill. */ }; /* Switch off/on ("dc" = Device Control?). */ static unsigned char cmd_switch[] = { 'h', 'd', 0x00, 0x00, 'd', 'c', /* Prefix, length, op. */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* MAC address. */ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, /* 0x20 fill. */ 0x00, 0x00, 0x00, 0x00, 0x00 }; /* Heartbeat ("hb" = HeartBeat?). */ static unsigned char cmd_heartbeat[] = { 'h', 'd', 0x00, 0x00, 'h', 'b', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* MAC address. */ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, /* 0x20 fill. */ 0x00, 0x00, 0x00, 0x00 /* Unk(4). */ }; /* Global discovery ("qa" = Query All?). */ static unsigned char cmd_glob_disc[] = { 'h', 'd', 0x00, 0x00, 'q', 'a' }; /* Prefix, length, op. */ /* Unit discovery ("qg" = Query G?). */ static unsigned char cmd_unit_disc[] = { 'h', 'd', 0x00, 0x00, 'q', 'g', /* Prefix, length, op. */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* MAC address. */ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 /* 0x20 fill. */ }; /* Read table ("rt" = Read Table?). */ static unsigned char cmd_read_table[] = { 'h', 'd', 0x00, 0x00, 'r', 't', /* Prefix, length, op. */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* MAC address. */ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, /* 0x20 fill. */ 0x00, 0x00, 0x00, 0x00, /* Unk(4). */ 0x04, 0x00, 0x00, 0x00, /* Table 04, version 00. */ 0x00, 0x00, 0x00 /* Unk(1), rec-len(2) = 0. */ }; #define READ_TABLE_TABLE 22 #define READ_TABLE_VERSION 24 /* Write table ("tm" = Table Modify?). */ static unsigned char cmd_write_table[] = { 'h', 'd', 0x00, 0x00, 't', 'm' /* Prefix, length, op. */ /* 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, */ /* MAC address. */ /* 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, */ /* 0x20 fill. */ /* 0x00, 0x00, 0x00, 0x00, */ /* Unk(4). */ /* 0x04, 0x00, 0x01 */ /* Table 04, version 01. */ /* 0x00, 0x00 */ /* rec-len(2). */ }; /* Device type names. */ #define ICON_MAX 5 static const char *icon_name[ ICON_MAX+ 1] = /* Device type names. */ { "Light", "Fan", "Thermostat", "Switch", "Socket-US", "Socket-AU" }; /* ORVL operation keywords. */ char *oprs[] = { "heartbeat", "help", "list", "qlist", "off", "on", "set", "usage", "version" }; #define OPR_HEARTBEAT 0 #define OPR_HELP 1 #define OPR_LIST 2 #define OPR_QLIST 3 #define OPR_OFF 4 #define OPR_ON 5 #define OPR_SET 6 #define OPR_USAGE 7 #define OPR_VERSION 8 /* ORVL option keywords. */ char *opts[] = { "brief", "quiet", "ddf", "ddf=", "debug", "debug=", "name=", "password=", "sort=" }; #define OPT_BRIEF 0 #define OPT_QUIET 1 #define OPT_DDF 2 #define OPT_DDF_EQ 3 #define OPT_DEBUG 4 #define OPT_DEBUG_EQ 5 #define OPT_NAME_EQ 6 #define OPT_PASSWORD_EQ 7 #define OPT_SORT_EQ 8 /* "sort=" option value keywords. */ char *sort_keys[] = { "ip", "mac" }; #define SRT_IP 0 #define SRT_MAC 1 /*--------------------------------------------------------------------*/ /* Functions. */ /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* usage(): Display usage information. */ int usage( void) { int i; int sts = 0; char *usage_text[] = { " Usage: orvl [ options ] operation [ identifier ]", "", "Options: debug[=value] Set debug flags, all or selected.", " ddf[=file_spec] Use device data file. Default: ORVL_DDF", " (normally an env-var or logical name).", " name=device_name New device name for \"set\" operation.", " password=passwd New remote password for \"set\" operation.", " brief Simplify [q]list and off/on reports.", " quiet Suppress [q]list and off/on reports.", " sort={ip|mac} Sort devs by IP or MAC addr. Default: ip", "", "Operations: help, usage Display this help/usage text.", " list List devices. (Minimal device queries.)", " qlist Query and list devices. (Query device(s)", " to get detailed device information.)", " off, on Switch off/on. Identifier required.", " set Set dev data (name, password). Ident req'd.", " version Show program version.", "", "Identifier: DNS name DNS name, numeric IP address, or dev name.", " IP address Used with operations \"off\", \"on\", or \"set\",", " Device name or to limit a [q]list report to one device." }; fprintf( stderr, "\n"); fprintf( stderr, " %s %d.%d %s\n", PROGRAM_NAME, PROGRAM_VERSION_MAJ, PROGRAM_VERSION_MIN, usage_text[ 0]); for (i = 1; i < (sizeof( usage_text)/ sizeof( *usage_text)); i++) { fprintf( stderr, "%s\n", usage_text[ i]); } return sts; } /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* dev_name(): Store a trimmed device name into user's buffer. * Return length in *name_len. */ char *dev_name( orv_data_t *orv_data_p, char *name_buf, int *name_len) { int i; int last_non_blank = -1; #define UNSET_NAME "(unset)" for (i = 0; i < DEV_NAME_LEN; i++) { /* Check first character for special values. */ if ((orv_data_p->name)[ i] == 0xff) { /* Unset. (Factory name = DEV_NAME_LEN* 0xff.) */ if (name_buf != NULL) { memcpy( name_buf, UNSET_NAME, strlen( UNSET_NAME)); } last_non_blank = strlen( UNSET_NAME)- 1; break; } else if ((orv_data_p->name)[ i] == '\0') { /* Unread. (Our unread value is DEV_NAME_LEN* '\0'.) */ break; } else { /* Normal name. */ if ((orv_data_p->name)[ i] != ' ') { last_non_blank = i; } if (name_buf != NULL) { name_buf[ i] = (orv_data_p->name)[ i]; } } } if (name_buf != NULL) { name_buf[ last_non_blank+ 1] = '\0'; } if (name_len != NULL) { *name_len = last_non_blank+ 1; } return name_buf; } /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* orv_data_find_ip_addr(): Find an ip address (at LL orgn) in orv_data LL. */ orv_data_t *orv_data_find_ip_addr( orv_data_t *origin_p) { orv_data_t *orv_data_p; orv_data_t *result = NULL; /* Result = NULL, if not found. */ orv_data_p = origin_p->next; /* Start with the first (real?) LL member. */ while (orv_data_p != origin_p) /* Quit when back to origin. */ { if (origin_p->ip_addr.s_addr == orv_data_p->ip_addr.s_addr) { if ((debug& DBG_SEL) != 0) { fprintf( stderr, " odfip(). Match: ip = %08x.\n", ntohl( orv_data_p->ip_addr.s_addr)); } result = orv_data_p; /* Found it. Return this as result. */ break; } orv_data_p = orv_data_p->next; /* Advance to the next member. */ } return result; } /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* orv_data_find_name(): Find device name in orv_data LL. */ orv_data_t *orv_data_find_name( orv_data_t *origin_p, char *name) { int name_len; orv_data_t *orv_data_p; orv_data_t *result = NULL; /* Result = NULL, if not found. */ name_len = strlen( name); if ((debug& DBG_SEL) != 0) { fprintf( stderr, " odfn(). name_len = %d.\n", name_len); } orv_data_p = origin_p->next; /* Start with the first (real?) LL member. */ while (orv_data_p != origin_p) /* Quit when back to origin. */ { int orv_name_len; dev_name( orv_data_p, NULL, &orv_name_len); /* Get candidate name len. */ if ((debug& DBG_SEL) != 0) { fprintf( stderr, " odfn(). orv_name_len = %d.\n", orv_name_len); } if (orv_name_len > 0) { /* orv_data_p->name is not NUL-terminated. */ if ((name_len == orv_name_len) && (strncmp( name, (char *)orv_data_p->name, name_len) == 0)) { if ((debug& DBG_SEL) != 0) { fprintf( stderr, " odfn(). >>> Match: name = >%s<.\n", name); } result = orv_data_p; break; } } orv_data_p = orv_data_p->next; /* Advance to the next member. */ } return result; } /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* orv_data_find_dev(): Find device IP address or name in orv_data LL. */ int orv_data_find_dev( orv_data_t *origin_p, int use_ip, char *name, int loc) { int sts = 0; /* Assume success. */ orv_data_t *orv_data_p; if (use_ip == 0) { /* Compare device names (name arg v. real LL data). */ orv_data_p = orv_data_find_name( origin_p, name); } else { /* Compare IP addresses (LL origin v. real LL data). */ orv_data_p = orv_data_find_ip_addr( origin_p); } if (orv_data_p == NULL) { fprintf( stderr, "%s: Device name not matched (loc=%d): >%s<.\n", PROGRAM_NAME, loc, name); errno = ENXIO; sts = EXIT_FAILURE; } else { orv_data_p->cnt_flg = 1; /* Mark this member for reportng. */ } if ((debug& DBG_SEL) != 0) { fprintf( stderr, " odfd(). sts = %d, use_ip = %d, loc = %d. o_d_p = %sNULL.\n", sts, use_ip, loc, ((orv_data_p == NULL) ? "" : "non-")); } return sts; } /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* orv_data_find_mac(): Find MAC address in orv_data LL. */ orv_data_t *orv_data_find_mac( orv_data_t *origin_p, unsigned char *mac_addr) { int sts; orv_data_t *orv_data_p; orv_data_t *result = NULL; /* Result = NULL, if not found. */ orv_data_p = origin_p->next; /* Start with the first (real?) LL member. */ while (orv_data_p != origin_p) /* Quit when back to the origin. */ { sts = memcmp( mac_addr, orv_data_p->mac_addr, MAC_ADDR_SIZE); if (sts == 0) { result = orv_data_p; /* Found it. Return this as result. */ break; } orv_data_p = orv_data_p->next; /* Advance to the next member. */ } return result; } /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* mac_cmp(): Compare two MAC addresses. */ int mac_cmp( unsigned char *ma1, unsigned char *ma2) { int i; int result = 0; for (i = 0; i < MAC_ADDR_SIZE; i++) { if (ma1[ i] < ma2[ i]) { result = -1; break; } else if (ma1[ i] > ma2[ i]) { result = 1; break; } } return result; } /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* orv_data_new(): Insert new member into orv_data LL. */ orv_data_t *orv_data_new( orv_data_t *origin_p, void *sort_p) { orv_data_t *orv_data_p; orv_data_t *orv_data_new_p; /* Allocate storage for the new LL member. */ orv_data_new_p = malloc( sizeof( orv_data_t)); if (orv_data_new_p != NULL) { /* Find insertion point in LL, sorting by IP address (in host order). */ orv_data_p = origin_p->next; /* Start with first (real?) LL mmbr. */ while (orv_data_p != origin_p) /* Quit when back to the origin. */ { if (origin_p->sort_key == SRT_IP) { /* Sort by IP address. */ if (ntohl( ((struct in_addr *)sort_p)->s_addr) < ntohl( orv_data_p->ip_addr.s_addr)) { break; /* Insert new member before this member. */ } } else { /* Sort by MAC address. */ if (mac_cmp( (unsigned char *)sort_p, orv_data_p->mac_addr) < 0) { break; } } orv_data_p = orv_data_p->next; /* Advance to the next member. */ } origin_p->cnt_flg++; /* Count the new member. */ /* Initialize new member data. * (Note: memset(0) sets sort_key to SRT_IP.) */ memset( orv_data_new_p, 0, sizeof( orv_data_t)); /* Zero all data. */ orv_data_new_p->type = -1; /* Set unknown device type. */ orv_data_new_p->state = -1; /* Set unknown device state. */ /* Insert the new member into the LL before the insertion-point member. */ orv_data_new_p->next = orv_data_p; /* New.next = Old. */ orv_data_new_p->prev = orv_data_p->prev; /* New.prev = Old.prev. */ orv_data_p->prev->next = orv_data_new_p; /* Old.prev.next = New. */ orv_data_p->prev = orv_data_new_p; /* Old.prev = New. */ } return orv_data_new_p; /* Return pointer to New. */ } /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* type_name(): Store a device type name into user's buffer. */ char *type_name( int type, char *type_buf) { if ((type >= 0) && (type < ICON_MAX)) { strcpy( type_buf, icon_name[ type]); } else if (type == -1) { strcpy( type_buf, ""); } else { sprintf( type_buf, "?%04x?", type); } return type_buf; } /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* fprintf_device(): Display device data from LL member. */ int fprintf_device( FILE *fp, orv_data_t *orv_data_p) { int bw = 0; /* Bytes written. */ int bwt = 0; /* Bytes written, total. */ int nam_len; /* Device name length. */ char type_str[ 16]; /* Device type string. */ char ip_str[ 16]; /* IP address string. */ char nam_buf[ DEV_NAME_LEN+ 1]; /* Device name string. */ unsigned int ia4; /* IP address (host order). */ ia4 = ntohl( orv_data_p->ip_addr.s_addr); nam_buf[ 0] = '>'; /* ">device name<". */ dev_name( orv_data_p, &nam_buf[ 1], &nam_len); nam_buf[ nam_len+ 1] = '<'; nam_buf[ nam_len+ 2] = '\0'; sprintf( ip_str, "%u.%u.%u.%u", /* IP address. */ ((ia4/ 0x100/ 0x100/ 0x100)& 0xff), ((ia4/ 0x100/ 0x100)& 0xff), ((ia4/ 0x100)& 0xff), (ia4& 0xff)); type_name( orv_data_p->type, type_str); bw = fprintf( fp, "%-15s %02x:%02x:%02x:%02x:%02x:%02x %-18s # %s %s\n", ip_str, /* IP address. */ orv_data_p->mac_addr[ 0], orv_data_p->mac_addr[ 1], /* MAC address. */ orv_data_p->mac_addr[ 2], orv_data_p->mac_addr[ 3], orv_data_p->mac_addr[ 4], orv_data_p->mac_addr[ 5], nam_buf, /* ">dev name<". */ ((orv_data_p->state == -1) ? "???" : /* State string (Unk). */ ((orv_data_p->state == 0) ? "Off" : "On ")), /* State string (0, 1). */ type_str); /* Device type. */ if (bw >= 0) { bwt += bw; } else { bwt = -1; } return bwt; /* Bytes written, total. If error, then -1. */ } /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* fprintf_device_header(): Display device list header. */ int fprintf_device_header( FILE *fp, int flags, orv_data_t *origin_p) { int bw = 0; /* Bytes written. */ int bwt = 0; /* Bytes written, total. */ char dev_cnt_str[ 20]; time_t t1; struct tm stm; time( &t1); LOCALTIME_R( &t1, &stm); sprintf( dev_cnt_str, "(%s: %d)", (((flags& FDL_DDF) != 0) ? "ddf" : "probe"), origin_p->cnt_flg); bw = fprintf( fp, "# %s %2d.%d -- Devices %-18s %04d-%02d-%02d:%02d:%02d:%02d\n", PROGRAM_NAME, PROGRAM_VERSION_MAJ, PROGRAM_VERSION_MIN, dev_cnt_str, (stm.tm_year+ 1900), (stm.tm_mon+ 1), stm.tm_mday, stm.tm_hour, stm.tm_min, stm.tm_sec); if (bw >= 0) { bwt += bw; bw = fprintf( fp, "# IP address MAC address >Device name< # State Type\n"); } if (bw >= 0) { bwt += bw; bw = fprintf( fp, "#-----------------------------------------------------------------------\n"); } if (bw >= 0) { bwt += bw; } if (bw < 0) { bwt = -1; } return bwt; /* Bytes written, total. If error, then -1. */ } /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* fprintf_device_list(): Display device list. */ int fprintf_device_list( FILE *fp, int flags, orv_data_t *origin_p) { orv_data_t *orv_data_p; int bw = 0; /* Bytes written. */ int bwt = 0; /* Bytes written, total. */ int header_written = 0; orv_data_p = origin_p->next; /* Start with the first (real?) LL member. */ while (orv_data_p != origin_p) /* Quit when back to the origin. */ { bwt += bw; bw = 0; /* If reporting only this device, then save its state (at origin). */ if (orv_data_p->cnt_flg != 0) { origin_p->state = orv_data_p->state; } if ((flags& FDL_QUIET) == 0) /* Not quiet. */ { if (((flags& FDL_SINGLE) == 0) || /* Not specific, or: */ (orv_data_p->cnt_flg != 0)) /* this one device. */ { if ((header_written == 0) && ((flags& FDL_BRIEF) == 0)) { /* Write the header once, before any device data. */ header_written = 1; bw = fprintf_device_header( fp, flags, origin_p); if (bw < 0) { break; } bwt += bw; } bw = fprintf_device( fp, orv_data_p); if (bw < 0) { break; } } } orv_data_p = orv_data_p->next; /* Advance to the next member. */ } /* while */ if (bw >= 0) { bwt += bw; } if (bw < 0) { bwt = -1; } return bwt; /* Bytes written, total. If error, then -1. */ } /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* msg_dump(): Display message data. */ void msg_dump( unsigned char *buf, ssize_t len) { ssize_t i; char dmp[ 17]; for (i = 0; i < len; i++) { fprintf( stderr, " %02x", buf[ i]); if ((buf[ i] >= 32) && (buf[ i] <= 127)) { dmp[ i% 16] = buf[ i]; } else { dmp[ i% 16] = '.'; } if ((i% 16) == 15) { dmp[ (i% 16)+ 1] = '\0'; fprintf( stderr, " >%s<\n", dmp); } } if ((i% 16) != 0) { dmp[ (i% 16)] = '\0'; } for (i = len; i < (ssize_t)((len+ 15)& 0xfffffff0); i++) { fprintf( stderr, " "); } fprintf( stderr, " >%s<\n", dmp); } /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* hexchr2int(): Convert hex character to int value. */ int hexchr2int( char c) { int val = -1; if ((c >= '0') && (c <= '9')) { val = c- '0'; } else if ((c >= 'A') && (c <= 'F')) { val = c- 'A'+ 10; } else if ((c >= 'a') && (c <= 'f')) { val = c- 'a'+ 10; } return val; } /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* parse_mac(): Translate "xx:xx:xx:xx:xx:xx" string to byte array. */ int parse_mac( char *str, unsigned char *bytes) { int i; int sts = 0; /* Assume success. */ if (strlen( str) != (MAC_ADDR_SIZE* 3- 1)) { sts = -1; /* Wrong string length. */ } else { /* Allow ":" or "-" as MAC octet separators. */ for (i = 0; i < (MAC_ADDR_SIZE- 1); i++) { if ((str[ i* 3+ 2] != ':') && (str[ i* 3+ 2] != '-')) { sts = -2; /* Bad separator. */ break; } } if (sts == 0) { for (i = 0; i < MAC_ADDR_SIZE; i++) { int c0; int c1; c1 = hexchr2int( str[ 3* i]); c0 = hexchr2int( str[ 3* i+ 1]); if ((c0 < 0) || (c1 < 0)) { sts = -3; /* Invalid hex digit. */ break; } else { bytes[ i] = 16* c1+ c0; } } } } return sts; } /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* revcpy(): Reverse memcpy(). */ void *revcpy( void *dst, const void *src, size_t siz) { size_t i; for (i = 0; i < siz; i++) { ((unsigned char *)dst)[ i] = ((unsigned char *)src)[ siz- 1- i]; } return dst; } /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* show_errno(): Display error code(s), message. */ int show_errno( char *prog_name) { int sts; if (prog_name == NULL) { prog_name = ""; } #ifdef _WIN32 sts = fprintf( stderr, "%s: errno = %d, WSAGLA() = %d.\n", prog_name, errno, WSAGetLastError()); #else /* def _WIN32 */ # ifdef VMS sts = fprintf( stderr, "%s: errno = %d, vaxc$errno = %08x.\n", prog_name, errno, vaxc$errno); # else /* def VMS */ sts = fprintf( stderr, "%s: errno = %d.\n", prog_name, errno); # endif /* def VMS [else] */ #endif /* def _WIN32 [else]*/ if (sts >= 0) { fprintf( stderr, "%s: %s\n", prog_name, strerror( errno)); } return sts; } /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* dns_resolve(): Resolve DNS name to IPv4 address using getaddrinfo(). */ int dns_resolve( char *name, struct in_addr *ip_addr) { int sts; struct addrinfo *ai_pp; /* addrinfo() result (linked list). */ struct addrinfo ai_h; /* addrinfo() hints. */ /* Fill getaddrinfo() hints structure. */ memset( &ai_h, 0, sizeof( ai_h)); ai_h.ai_family = AF_INET; ai_h.ai_protocol = IPPROTO_UDP; sts = getaddrinfo( name, /* Node name. */ NULL, /* Service name. */ &ai_h, /* Hints. */ &ai_pp); /* Results (linked list). */ if (sts != 0) { if ((debug& DBG_DNS) != 0) { fprintf( stderr, " getaddrinfo() failed.\n"); } } else { /* Use the first result in the ai_pp linked list. */ if ((debug& DBG_DNS) != 0) { fprintf( stderr, " getaddrinfo():\n"); fprintf( stderr, " ai_family = %d, ai_socktype = %d, ai_protocol = %d\n", ai_pp->ai_family, ai_pp->ai_socktype, ai_pp->ai_protocol); fprintf( stderr, " ai_addrlen = %d, ai_addr->sa_family = %d.\n", ai_pp->ai_addrlen, ai_pp->ai_addr->sa_family); fprintf( stderr, " ai_flags = 0x%08x.\n", ai_pp->ai_flags); if (ai_pp->ai_addr->sa_family == AF_INET) { fprintf( stderr, " ai_addr->sa_data[ 2: 5] = %u.%u.%u.%u\n", (unsigned char)ai_pp->ai_addr->sa_data[ 2], (unsigned char)ai_pp->ai_addr->sa_data[ 3], (unsigned char)ai_pp->ai_addr->sa_data[ 4], (unsigned char)ai_pp->ai_addr->sa_data[ 5]); } } #ifndef NO_AF_CHECK /* Disable the address-family check everywhere. */ { # if defined( VMS) && defined( VAX) && !defined( GETADDRINFO_OK) /* Work around apparent bug in getaddrinfo() in TCPIP V5.3 - ECO 4 * on VMS V7.3 (typical hobbyist kit?). sa_family seems to be * misplaced, misaligned, corrupted. Spurious sa_len? */ int sa_fam; # define SA_FAMILY sa_fam if (ai_pp->ai_addr->sa_family != AF_INET) { if ((debug& DBG_DNS) != 0) { fprintf( stderr, " Unexpected address family (not %d, V-V work-around): %d.\n", AF_INET, ai_pp->ai_addr->sa_family); } SA_FAMILY = ai_pp->ai_addr->sa_family/ 256; /* Try offset. */ } # else /* defined( VMS) && defined( VAX) && !defined( GETADDRINFO_OK) */ # define SA_FAMILY ai_pp->ai_addr->sa_family # endif /* defined( VMS) && defined( VAX) && !defined( GETADDRINFO_OK) [else] */ if (SA_FAMILY != AF_INET) { /* Complain about (original) bad value. */ fprintf( stderr, "%s: Unexpected address family (not %d): %d.\n", PROGRAM_NAME, AF_INET, ai_pp->ai_addr->sa_family); sts = -1; } } #endif /* ndef NO_AF_CHECK */ if ((sts == 0) && (ip_addr != NULL)) { /* IPv4 address (net order). */ memcpy( ip_addr, &ai_pp->ai_addr->sa_data[ 2], sizeof( *ip_addr)); } } return sts; } /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* set_socket_noblock(): Set socket to non-blocking. */ int set_socket_noblock( int sock) { #ifdef USE_FCNTL /* Use fcntl(). */ int fc_flgs; int sts = 0; /* Assume success. */ fc_flgs = fcntl( sock, F_GETFL, 0); /* Get current flags. */ if ((debug& DBG_SIO) != 0) { fprintf( stderr, " fcntl(0). Sock = %d, flgs = %08x .\n", sock, fc_flgs); } if (fc_flgs != -1) { fc_flgs |= O_NONBLOCK; /* OR-in O_NONBLOCK. */ if ((debug& DBG_SIO) != 0) { fprintf( stderr, " fcntl(1). flgs = %08x .\n", fc_flgs); } fc_flgs = fcntl( sock, F_SETFL, fc_flgs); /* Set revised flags.*/ if ((debug& DBG_SIO) != 0) { fprintf( stderr, " fcntl(2). flgs = %08x .\n", fc_flgs); } } if (fc_flgs == -1) { fprintf( stderr, "%s: fcntl(noblock) failed. sock = %d.\n", PROGRAM_NAME, sock); show_errno( PROGRAM_NAME); sts = -1; } #else /* def USE_FCNTL */ /* Use ioctl(). */ int ioctl_tmp; int sts; ioctl_tmp = 1; sts = IOCTL_SOCKET( sock, FIONBIO, &ioctl_tmp); /* Set FIONBIO. */ if ((debug& DBG_SIO) != 0) { fprintf( stderr, " ioctl() sts = %d, tmp = %08x .\n", sts, ioctl_tmp); } if (sts < 0) { fprintf( stderr, "%s: ioctl() failed. sock = %d, sts = %d.\n", PROGRAM_NAME, sock, sts); show_errno( PROGRAM_NAME); } #endif /* def USE_FCNTL [else] */ return sts; /* -1, if error. */ } /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ #ifdef VMS # ifndef NO_OPER_PRIVILEGE /* set_priv_oper(): Try to set OPER privilege according to oper_new. * Set *oper_old_p to old value. */ int set_priv_oper( int oper_new, int *oper_old_p) { int sts; union prvdef priv_mask_old = { 0 }; /* Privilege masks. */ union prvdef priv_mask_new = { 0 }; oper_new = (oper_new == 0 ? 0 : 1); /* Ensure 0/1 flag value. */ priv_mask_new.prv$v_oper = 1; /* OPER privilege mask bit. */ sts = sys$setprv( oper_new, /* Enable/disable privileges. */ &priv_mask_new, /* New privilege mask. */ 0, /* Not permanent. */ &priv_mask_old); /* Previous privilege mask. */ if (sts == SS$_NORMAL) { sts = 0; if (oper_old_p != NULL) { *oper_old_p = priv_mask_old.prv$v_oper; } } else { errno = EVMSERR; vaxc$errno = sts; } return sts; } # endif /* ndef NO_OPER_PRIVILEGE */ #endif /* def VMS */ /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* form_msg_out(): Form an output message. */ size_t form_msg_out( int task_nr, unsigned char **msg_out, unsigned char *mac_addr) { size_t msg_out_len = 0; char *str; /* TSK_WT_SOCKET uses modified "rt" data from device, not a message * created here. TSK_WT_TIMING still not determined. */ if ((task_nr >= TSK_MIN) && (task_nr <= TSK_MAX)) { if ((task_nr == TSK_GLOB_DISC_B) || (task_nr == TSK_GLOB_DISC)) { /* Global discovery. */ str = "GLOB DISC"; *msg_out = malloc( sizeof( cmd_glob_disc)); if (*msg_out != NULL) { msg_out_len = sizeof( cmd_glob_disc); memcpy( *msg_out, cmd_glob_disc, msg_out_len); } } else if (task_nr == TSK_UNIT_DISC) { /* Unit discovery. */ str = "UNIT DISC"; *msg_out = malloc( sizeof( cmd_unit_disc)); if (*msg_out != NULL) { msg_out_len = sizeof( cmd_unit_disc); memcpy( *msg_out, cmd_unit_disc, msg_out_len); if (mac_addr != NULL) { memcpy( (*msg_out+ 6), mac_addr, MAC_ADDR_SIZE); /* MAC addr. */ } } } else if (task_nr == TSK_HEARTBEAT) { /* Heartbeat. */ str = "HEARTBEAT"; *msg_out = malloc( sizeof( cmd_heartbeat)); if (*msg_out != NULL) { msg_out_len = sizeof( cmd_heartbeat); memcpy( *msg_out, cmd_heartbeat, msg_out_len); if (mac_addr != NULL) { memcpy( (*msg_out+ 6), mac_addr, MAC_ADDR_SIZE); /* MAC addr. */ } } } else if (task_nr == TSK_SUBSCRIBE) { /* Subscribe. */ str = "SUBSCRIBE"; *msg_out = malloc( sizeof( cmd_subs)); if (*msg_out != NULL) { msg_out_len = sizeof( cmd_subs); memcpy( *msg_out, cmd_subs, msg_out_len); if (mac_addr != NULL) { memcpy( (*msg_out+ 6), mac_addr, MAC_ADDR_SIZE); /* MAC addr. */ revcpy( (*msg_out+ 18), mac_addr, MAC_ADDR_SIZE); /* MAC (rv). */ } } } else if ((task_nr == TSK_SW_OFF) || (task_nr == TSK_SW_ON)) { /* Switch off/on. */ int val; if (task_nr == TSK_SW_OFF) { str = "SWITCH OFF"; val = 0; } else /* (task_nr == TSK_SW_ON) */ { str = "SWITCH ON"; val = 1; } *msg_out = malloc( sizeof( cmd_switch)); if (*msg_out != NULL) { msg_out_len = sizeof( cmd_switch); memcpy( *msg_out, cmd_switch, msg_out_len); if (mac_addr != NULL) { memcpy( (*msg_out+ 6), mac_addr, MAC_ADDR_SIZE); /* MAC addr. */ (*msg_out)[ 22] = val; } } } else if ((task_nr == TSK_RT_SOCKET) || (task_nr == TSK_RT_TIMING)) { /* Read socket/timing data. */ unsigned short tbl; unsigned short vers; if (task_nr == TSK_RT_SOCKET) { str = "RT-SOCKET"; /* tbl = 0x0004; */ /* vers = 0x0003; */ tbl = 0x0004; vers = 0x0000; } else /* (task_nr == TSK_RT_TIMING) */ { str = "RT-TIMING"; tbl = 0x0003; vers = 0x0003; } *msg_out = malloc( sizeof( cmd_read_table)); if (*msg_out != NULL) { msg_out_len = sizeof( cmd_read_table); memcpy( *msg_out, cmd_read_table, msg_out_len); if (mac_addr != NULL) { memcpy( (*msg_out+ 6), mac_addr, MAC_ADDR_SIZE); /* MAC addr. */ } tbl = 0x0004; vers = 0x0000; (*msg_out)[ READ_TABLE_TABLE] = tbl% 256; (*msg_out)[ READ_TABLE_VERSION] = vers% 256; } } /* Insert message length into message. */ if (msg_out_len > 0) { (*msg_out)[ 2] = (unsigned short)msg_out_len/ 256; (*msg_out)[ 3] = (unsigned short)msg_out_len% 256; } if ((debug& DBG_MSO) != 0) { fprintf( stderr, " >> %s\n", str); fprintf( stderr, " msg_len = %ld.\n", msg_out_len); fprintf( stderr, " [2], [3] = %02x %02x\n", (*msg_out)[ 2], (*msg_out)[ 3]); /* Display message to be sent. */ if (msg_out_len >= 6) { fprintf( stderr, " Snd (%3ld) %c %c\n", msg_out_len, (*msg_out)[ 4], (*msg_out)[ 5]); } msg_dump( *msg_out, msg_out_len); } } return msg_out_len; } /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* task(): Perform a task: Send message, receive and process results. */ int task( int task_nr, /* Task number. */ int *rsp_p, /* Response type bit mask. */ unsigned char **tbl_p, /* Table data. */ orv_data_t *origin_p, /* orv_data origin. */ orv_data_t *target_p) /* orv_data target. */ { unsigned char mac_addr[ MAC_ADDR_SIZE]; /* Orvibo MAC address. */ SOCKET sock_orv = INVALID_SOCKET; /* Orvibo device socket. */ ssize_t bc; /* Byte count (send or receive). */ int sts; /* Status. */ int bcast = 0; /* Broadcast message flag. */ int mac_addr_ndx; unsigned char msg_inp[ 1024]; /* Receive message buffer. */ unsigned char *msg_out; /* Send message pointer. */ RECVFROM_6 sock_addr_len_rec; ssize_t msg_out_len = 0; struct sockaddr_in sock_addr_rec; struct sockaddr_in sock_addr_snd; fd_set fds_rec; struct timeval timeout_rec; unsigned short countdown; unsigned short countdown_sts; short icon_code; int record_len; int record_nr; int version_id; int hw_version; int fw_version; int cc_version; int server_port; time_t time_dev; unsigned int server_ip; unsigned int local_ip; unsigned int local_gw; unsigned int local_nm; int remote_port; char remote_name[ 84]; unsigned short table_nr; unsigned short unk_nr; char mac_addr_str[ 16]; char uid_str[ 16]; char remote_password[ PASSWORD_LEN+ 1]; char device_name[ DEV_NAME_LEN+ 1]; char device_type[ 12]; int save_orv_data; int state_new; int state_old; orv_data_t *orv_data_p; #ifdef VMS int oper_priv_save = -1; #endif /* def VMS */ sts = 0; if ((debug& DBG_MSI) != 0) { fprintf( stderr, " task(beg). task_nr = %d, tbl_p = %sNULL.\n", task_nr, ((tbl_p == NULL) ? "" : "non-")); } /* Form command message according to task_nr. */ if (sts == 0) { /* Broadcast IP, specific IP, or specific MAC address? */ if (task_nr == TSK_GLOB_DISC_B) { /* Broadcast IP. */ bcast = 1; } else if (task_nr != TSK_GLOB_DISC) { /* Specific MAC address. (Not TSK_GLOB_DISC[_B].) */ memcpy( mac_addr, target_p->mac_addr, MAC_ADDR_SIZE); } /* Form the message for this task_nr, or point to an already * existing message. */ if ((task_nr == TSK_WT_SOCKET) || (task_nr == TSK_WT_TIMING)) { if (*tbl_p != NULL) { /* Use an existing (Write-Table) message. */ msg_out = *tbl_p; msg_out_len = (unsigned short)msg_out[ 2]* 256+ (unsigned short)msg_out[ 3]; if ((debug& DBG_MSO) != 0) { fprintf( stderr, " task(non-f_m_o). m_o_l = %ld.\n", msg_out_len); } } } else { /* Form a new message. */ msg_out_len = form_msg_out( task_nr, &msg_out, mac_addr); if ((debug& DBG_MSO) != 0) { fprintf( stderr, " task(f_m_o). m_o_l = %ld.\n", msg_out_len); } if (msg_out_len <= 0) { errno = EINVAL; sts = -1; } } } #ifdef VMS # ifndef NO_OPER_PRIVILEGE /* On VMS, broadcast may require BYPASS, OPER, or SYSPRV privilege, * unless TCPIP SET PROTOCOL UDP /BROADCAST. We try to enable only * OPER, which may be relatively safe. * * As of TCPIP V5.7 - ECO 5 on Alpha, privilege must be adequate * (elevated) when the socket is created. If raised after socket(), * then setsockopt( SO_BROADCAST) fails (EACCES). */ if (sts == 0) { if (bcast != 0) { sts = set_priv_oper( 1, &oper_priv_save); if (sts != 0) { fprintf( stderr, "%s: Set privilege (OPER) failed. sts = %%x%08x .\n", PROGRAM_NAME, sts); show_errno( PROGRAM_NAME); sts = 0; /* Try to continue. */ } else if ((debug& DBG_VMS) != 0) { fprintf( stderr, " set_priv_oper(set). sts = %%x%08x , oper_old = %d.\n", sts, oper_priv_save); } } } # endif /* ndef NO_OPER_PRIVILEGE */ #endif /* def VMS */ state_new = -1; /* Clear device states. */ state_old = -1; if (sts == 0) { /* Fill receive socket addr structure. */ memset( &sock_addr_rec, 0, sizeof( sock_addr_rec)); sock_addr_rec.sin_family = AF_INET; sock_addr_rec.sin_port = htons( PORT_ORV); sock_addr_rec.sin_addr.s_addr = htons( INADDR_ANY); sock_orv = socket( AF_INET, /* Address family. */ SOCK_DGRAM, /* Type. */ IPPROTO_UDP); /* Protocol. */ if ((debug& DBG_SIO) != 0) { fprintf( stderr, " sock_orv = %d.\n", sock_orv); } if (BAD_SOCKET( sock_orv)) { fprintf( stderr, "%s: socket() failed.\n", PROGRAM_NAME); show_errno( PROGRAM_NAME); sts = -1; } else { #ifdef _WIN32 char sock_opt_rec = 1; #else /* def _WIN32 */ unsigned int sock_opt_rec = 1; #endif /* def _WIN32 [else] */ sts = setsockopt( sock_orv, /* Socket. */ SOL_SOCKET, /* Level. */ SO_REUSEADDR, /* Option name. */ &sock_opt_rec, /* Option value. */ sizeof( sock_opt_rec)); /* Option length. */ if (sts < 0) { fprintf( stderr, "%s: setsockopt(rec) failed.\n", PROGRAM_NAME); show_errno( PROGRAM_NAME); } else if ((debug& DBG_SIO) != 0) { fprintf( stderr, " setsockopt(rec) sts = %d.\n", sts); } } if (sts == 0) { sts = set_socket_noblock( sock_orv); } if (sts == 0) { sts = bind( sock_orv, (struct sockaddr *) &sock_addr_rec, /* Socket address. */ sizeof( sock_addr_rec)); /* Socket address length. */ if (sts < 0) { fprintf( stderr, "%s: bind(rec) failed.\n", PROGRAM_NAME); show_errno( PROGRAM_NAME); } else if ((debug& DBG_SIO) != 0) { fprintf( stderr, " bind(rec) sts = %d.\n", sts); } { #ifdef EARLY_RECVFROM /* Useful or not? */ if ((debug& DBG_SIO) != 0) { fprintf( stderr, " pre-recvfrom(e). sock_orv = %d, siz = %ld.\n", sock_orv, sizeof( msg_inp)); } /* Read a response. (Should be too soon.) */ sock_addr_len_rec = sizeof( sock_addr_rec); /* Socket addr len. */ bc = recvfrom( sock_orv, msg_inp, sizeof( msg_inp), 0, /* Flags (not OOB or PEEK). */ (struct sockaddr *) &sock_addr_rec, /* Socket address. */ &sock_addr_len_rec); /* Socket address length. */ if (bc < 0) { # ifdef _WIN32 if (WSAGetLastError() != WSAEWOULDBLOCK) # else /* def _WIN32 */ if (errno != EWOULDBLOCK) # endif /* def _WIN32 [else] */ { fprintf( stderr, "%s: recvfrom(e) failed.\n", PROGRAM_NAME); show_errno( PROGRAM_NAME); } } else if ((debug& DBG_SIO) != 0) { fprintf( stderr, " recvfrom(e) bc = %ld.\n", bc); } #endif /* def EARLY_RECVFROM */ } } } if (sts == 0) { bc = -1; /* Fill send socket addr structure. */ memset( &sock_addr_snd, 0, sizeof( sock_addr_snd)); sock_addr_snd.sin_family = AF_INET; sock_addr_snd.sin_port = htons( PORT_ORV); sock_addr_snd.sin_addr.s_addr = target_p->ip_addr.s_addr; if (bcast != 0) { /* Set socket broadcast flag. */ #ifdef _WIN32 char sock_opt_snd = 1; #else /* def _WIN32 */ unsigned int sock_opt_snd = 1; #endif /* def _WIN32 [else] */ sts = setsockopt( sock_orv, /* Socket. */ SOL_SOCKET, /* Level. */ SO_BROADCAST, /* Option name. */ &sock_opt_snd, /* Option value. */ sizeof( sock_opt_snd)); /* Option length. */ if ((debug& DBG_SIO) != 0) { fprintf( stderr, " setsockopt( snd-bc0) = %d .\n", sts); } if (sts < 0) { fprintf( stderr, "%s: setsockopt( snd-bc1) failed.\n", PROGRAM_NAME); show_errno( PROGRAM_NAME); } else { /* Disable multicast loopback. (Ineffective?) */ unsigned char sock_opt_snd = 0; sts = setsockopt( sock_orv, /* Socket. */ IPPROTO_IP, /* Level. */ IP_MULTICAST_LOOP, /* Option name. */ &sock_opt_snd, /* Option value. */ sizeof( sock_opt_snd)); /* Option length. */ if (sts < 0) { fprintf( stderr, "%s: setsockopt( snd-lb) failed.\n", PROGRAM_NAME); show_errno( PROGRAM_NAME); } } } if (sts == 0) { /* Send the command. */ bc = sendto( sock_orv, /* Socket. */ msg_out, /* Message. */ msg_out_len, /* Message length. */ 0, /* Flags (not MSG_OOB). */ (struct sockaddr *) &sock_addr_snd, /* Socket address. */ sizeof( sock_addr_snd)); /* Socket address length. */ if (bc < 0) { fprintf( stderr, "%s: sendto() failed.\n", PROGRAM_NAME); show_errno( PROGRAM_NAME); sts = -1; } else if ((debug& DBG_SIO) != 0) { fprintf( stderr, " sendto() = %ld.\n", bc); } } } if ((sts == 0) && (bc >= 0)) { /* Fill file-descriptor flags and time-out value for select(). */ memset( &fds_rec, 0, sizeof( fds_rec)); FD_SET( sock_orv, &fds_rec); timeout_rec.tv_sec = SOCKET_TIMEOUT/ 1000000; /* Seconds. */ timeout_rec.tv_usec = SOCKET_TIMEOUT% 1000000; /* Microseconds. */ if ((debug& DBG_SIO) != 0) { fprintf( stderr, " sock_orv = %d, FD_SETSIZE = %d,\n", sock_orv, FD_SETSIZE); fprintf( stderr, " FD_ISSET( sock_orv, &fds_rec) = %d.\n", FD_ISSET( sock_orv, &fds_rec)); } } /* Read responses until recvfrom()/select() times out. */ while (bc >= 0) { save_orv_data = 0; /* Clear good-data flag. */ if ((debug& DBG_SIO) != 0) { fprintf( stderr, " pre-select(1). sock_orv = %d.\n", sock_orv); } sts = select( FD_SETSIZE, &fds_rec, NULL, NULL, &timeout_rec); if (sts <= 0) { if (sts < 0) { fprintf( stderr, "%s: select(1) failed.\n", PROGRAM_NAME); show_errno( PROGRAM_NAME); } else if ((debug& DBG_SIO) != 0) { fprintf( stderr, " select(1) sts = %d.\n", sts); } break; } else { if ((debug& DBG_SIO) != 0) { fprintf( stderr, " pre-recvfrom(n). sock_orv = %d.\n", sock_orv); } /* Receive a response. */ sock_addr_len_rec = sizeof( sock_addr_rec); /* Socket addr len. */ bc = recvfrom( sock_orv, msg_inp, sizeof( msg_inp), 0, /* Flags (not OOB or PEEK). */ (struct sockaddr *) &sock_addr_rec, /* Socket address. */ &sock_addr_len_rec); /* Socket address length. */ if (bc < 0) { fprintf( stderr, "%s: recvfrom(n) failed.\n", PROGRAM_NAME); show_errno( PROGRAM_NAME); } else { mac_addr_ndx = -1; if ((debug& DBG_SIO) != 0) { if (sock_addr_rec.sin_family == AF_INET) { unsigned int ia4; fprintf( stderr, " s_addr: %08x .\n", sock_addr_rec.sin_addr.s_addr); ia4 = ntohl( sock_addr_rec.sin_addr.s_addr); fprintf( stderr, " recvfrom(n) addr: %u.%u.%u.%u\n", ((ia4/ 0x100/ 0x100/ 0x100)& 0xff), ((ia4/ 0x100/ 0x100)& 0xff), ((ia4/ 0x100)& 0xff), (ia4& 0xff)); } } if ((debug& DBG_MSI) != 0) { /* Display the response (hex, ASCII). */ if (bc >= 6) { fprintf( stderr, " Rec (%3ld) %c %c\n", bc, msg_inp[ 4], msg_inp[ 5]); } msg_dump( msg_inp, bc); } /* Find MAC. Determine Off/On state, if known. */ if (bc >= 6) { if ((msg_inp[ 4] == 'c') && (msg_inp[ 5] == 'l')) { /* Subscribe ("cl"). */ *rsp_p |= RSP_CL; if (bc >= 12) { mac_addr_ndx = 6; } if (bc >= 24) { state_old = msg_inp[ 23]; save_orv_data = RSP_CL; /* Found good data (cl). */ } } else if ((msg_inp[ 4] == 'd') && (msg_inp[ 5] == 'c')) { /* Switch Off/On (message) ("dc"). (No useful data?) */ *rsp_p |= RSP_DC; } else if ((msg_inp[ 4] == 'h') && (msg_inp[ 5] == 'b')) { /* Heartbeat Off/On ("hb"). (No useful data?) */ *rsp_p |= RSP_HB; } else if ((msg_inp[ 4] == 'q') && (msg_inp[ 5] == 'a')) { /* Global Discovery ("qa"). */ /* We may see the original (short) request, if broadcast, * so set the "qa" response bit only if the message is a * real response, that is, if it's long enough to include * a MAC address (which a "qa" request does not). */ if (bc >= 13) { *rsp_p |= RSP_QA; mac_addr_ndx = 7; } if (bc >= 41) { time_dev = /* Casts ensure that */ (((time_t)msg_inp[ 40]* 256+ /* arithmetic is done as */ (time_t)msg_inp[ 39])* 256+ /* time_t, which may be */ (time_t)msg_inp[ 38])* 256+ /* 32/64-bit, [un]signed */ (time_t)msg_inp[ 37]; /* on different systems. */ if ((debug& DBG_MSI) != 0) { fprintf( stderr, " time_dev: %lu (0x%08lx)\n", time_dev, time_dev); time_dev -= TIME_OFS; /* 1970 - 1900. */ fprintf( stderr, " ctime(adj) = %s", /* No '\n'. */ ctime( (time_t *)&time_dev)); } } if (bc >= 42) { state_old = msg_inp[ 41]; save_orv_data = RSP_QA; /* Found good data (qa). */ } } else if ((msg_inp[ 4] == 'q') && (msg_inp[ 5] == 'g')) { /* Unit Discovery ("qg"). */ *rsp_p |= RSP_QG; if (bc >= 13) { mac_addr_ndx = 7; } if (bc >= 41) { time_dev = /* Casts ensure that */ (((time_t)msg_inp[ 40]* 256+ /* arithmetic is done as */ (time_t)msg_inp[ 39])* 256+ /* time_t, which may be */ (time_t)msg_inp[ 38])* 256+ /* 32/64-bit, [un]signed */ (time_t)msg_inp[ 37]; /* on different systems. */ if ((debug& DBG_MSI) != 0) { fprintf( stderr, " time_dev: %lu (0x%08lx)\n", time_dev, time_dev); time_dev -= TIME_OFS; /* 1970 - 1900. */ fprintf( stderr, " ctime(adj) = %s\n", ctime( (time_t *)&time_dev)); } } if (bc >= 42) { state_old = msg_inp[ 41]; save_orv_data = RSP_QG; /* Found good data (qg). */ } } else if ((msg_inp[ 4] == 'r') && (msg_inp[ 5] == 't')) { /* Read Table ("rt"). */ *rsp_p |= RSP_RT; /* If caller wants them, then copy msg_inp data into user's * new buffer, and tell caller where to find them. (Size is * stored in the data.) */ if (tbl_p != NULL) { if (*tbl_p == NULL) /* First time. */ { unsigned short msg_len; /* Embedded msg len. */ msg_len = (unsigned short)msg_inp[ 2]* 256+ (unsigned short)msg_inp[ 3]; if (bc != msg_len) { fprintf( stderr, "%s: Unexpected message length. bc = %ld, m_l = %d.\n", PROGRAM_NAME, bc, msg_len); } else { *tbl_p = malloc( bc); if (*tbl_p == NULL) { fprintf( stderr, "%s: malloc() failed [x].\n", PROGRAM_NAME); } else { memcpy( *tbl_p, msg_inp, bc); } } } } if (bc >= 12) { mac_addr_ndx = 6; } #if 0 if (bc >= 20) { int record_id; record_id = /* Record ID. */ (unsigned int)msg_inp[ 19]* 256+ (unsigned int)msg_inp[ 18]; if ((debug& DBG_MSI) != 0) { fprintf( stderr, " Record ID: %u (0x%04x)\n", record_id, record_id); } } #endif /* 0 */ if (bc >= 25) /* Unk: 18, 19, 20, 21, 22. */ { table_nr = /* Table Nr. */ (unsigned int)msg_inp[ 24]* 256+ (unsigned int)msg_inp[ 23]; if ((debug& DBG_MSI) != 0) { fprintf( stderr, " Table Nr: %u (0x%04x)\n", table_nr, table_nr); } } if (bc >= 27) { unk_nr = /* Unk Nr. */ (unsigned int)msg_inp[ 26]* 256+ (unsigned int)msg_inp[ 25]; if ((debug& DBG_MSI) != 0) { fprintf( stderr, " Unk Nr: %u (0x%04x)\n", unk_nr, unk_nr); } } /* Unk: 27. */ if (bc >= 30) { /* (Record length is bytes to follow: total - 30.) */ record_len = /* Record length. */ (unsigned int)msg_inp[ 29]* 256+ (unsigned int)msg_inp[ 28]; if ((debug& DBG_MSI) != 0) { fprintf( stderr, " Record Len: %u (0x%04x)\n", record_len, record_len); } } if (bc >= 32) { record_nr = /* Record number. */ (unsigned int)msg_inp[ 31]* 256+ (unsigned int)msg_inp[ 30]; if ((debug& DBG_MSI) != 0) { fprintf( stderr, " Record Nr: %u (0x%04x)\n", record_nr, record_nr); } } if (bc >= 34) { version_id = /* Version ID. */ (unsigned int)msg_inp[ 33]* 256+ (unsigned int)msg_inp[ 32]; if ((debug& DBG_MSI) != 0) { fprintf( stderr, " Version ID: %u (0x%04x)\n", version_id, version_id); } } if (table_nr == 4) { if (bc >= 46) { /* 6-char UID (MAC address)+ 6* 0x20. */ memcpy( uid_str, &msg_inp[ 34], 12); uid_str[ 12] = '\0'; if ((debug& DBG_MSI) != 0) { fprintf( stderr, " MAC address (fwd): %02x:%02x:%02x:%02x:%02x:%02x\n", msg_inp[ 34], msg_inp[ 35], msg_inp[ 36], msg_inp[ 37], msg_inp[ 38], msg_inp[ 39]); } } if (bc >= 58) { /* 6-char MAC addr+ 6* 0x20. */ memcpy( mac_addr_str, &msg_inp[ 46], 12); mac_addr_str[ 12] = '\0'; if ((debug& DBG_MSI) != 0) { fprintf( stderr, " MAC address (rev): %02x:%02x:%02x:%02x:%02x:%02x\n", msg_inp[ 46], msg_inp[ 47], msg_inp[ 48], msg_inp[ 49], msg_inp[ 50], msg_inp[ 51]); } } if (bc >= 70) { /* 12-char remote password (0x20-padded). */ memcpy( remote_password, &msg_inp[ 58], PASSWORD_LEN); remote_password[ PASSWORD_LEN] = '\0'; if ((debug& DBG_MSI) != 0) { fprintf( stderr, " Remote password: >%s<\n", remote_password); } } if (bc >= 86) { /* 16-char device name (0x20 padded). */ memcpy( device_name, &msg_inp[ 70], DEV_NAME_LEN); device_name[ DEV_NAME_LEN] = '\0'; if ((debug& DBG_MSI) != 0) { fprintf( stderr, " Device name: >%s<\n", device_name); } } if (bc >= 88) { /* Device type ("icon_code"). */ icon_code = /* Icon code. */ (unsigned int)msg_inp[ 87]* 256+ (unsigned int)msg_inp[ 86]; if ((debug& DBG_MSI) != 0) { type_name( icon_code, device_type); fprintf( stderr, " Device type: %d (%s)\n", icon_code, device_type); } } if (bc >= 92) { hw_version = /* Hardware Version. */ (unsigned int)msg_inp[ 91]* 256* 256* 256+ (unsigned int)msg_inp[ 90]* 256* 256+ (unsigned int)msg_inp[ 89]* 256+ (unsigned int)msg_inp[ 88]; if ((debug& DBG_MSI) != 0) { fprintf( stderr, " Hardware version: 0x%08x\n", hw_version); } } if (bc >= 96) { fw_version = /* Firmware Version. */ (unsigned int)msg_inp[ 95]* 256* 256* 256+ (unsigned int)msg_inp[ 94]* 256* 256+ (unsigned int)msg_inp[ 93]* 256+ (unsigned int)msg_inp[ 92]; if ((debug& DBG_MSI) != 0) { fprintf( stderr, " Firmware version: 0x%08x\n", fw_version); } } if (bc >= 100) { cc_version = /* CC3300 Firmware Version. */ (unsigned int)msg_inp[ 99]* 256* 256* 256+ (unsigned int)msg_inp[ 98]* 256* 256+ (unsigned int)msg_inp[ 97]* 256+ (unsigned int)msg_inp[ 96]; if ((debug& DBG_MSI) != 0) { fprintf( stderr, " CC3300 Firmware version: 0x%08x\n", cc_version); } } if (bc >= 102) { server_port = /* Server port. */ (unsigned int)msg_inp[ 101]* 256+ (unsigned int)msg_inp[ 100]; if ((debug& DBG_MSI) != 0) { fprintf( stderr, " Server port: code: %d (0x%04x)\n", server_port, server_port); } } if (bc >= 106) { server_ip = /* Server IP address. */ (unsigned int)msg_inp[ 102]* 256* 256* 256+ (unsigned int)msg_inp[ 103]* 256* 256+ (unsigned int)msg_inp[ 104]* 256+ (unsigned int)msg_inp[ 105]; if ((debug& DBG_MSI) != 0) { fprintf( stderr, " Server IP address: 0x%08x %u.%u.%u.%u\n", server_ip, msg_inp[ 102], msg_inp[ 103], msg_inp[ 104], msg_inp[ 105]); } } if (bc >= 108) { remote_port = /* Remote port. */ (unsigned int)msg_inp[ 107]* 256+ (unsigned int)msg_inp[ 106]; if ((debug& DBG_MSI) != 0) { fprintf( stderr, " Remote port: %d (0x%04x)\n", remote_port, remote_port); } } if (bc >= 148) { memcpy( remote_name, &msg_inp[ 108], 40); remote_name[ 40] = '\0'; if ((debug& DBG_MSI) != 0) { fprintf( stderr, " Remote name: >%s<\n", remote_name); } } if (bc >= 152) { local_ip = /* Local IP address. */ (unsigned int)msg_inp[ 148]* 256* 256* 256+ (unsigned int)msg_inp[ 149]* 256* 256+ (unsigned int)msg_inp[ 150]* 256+ (unsigned int)msg_inp[ 151]; if ((debug& DBG_MSI) != 0) { fprintf( stderr, " Local IP address: 0x%08x %u.%u.%u.%u\n", local_ip, msg_inp[ 148], msg_inp[ 149], msg_inp[ 150], msg_inp[ 151]); } } if (bc >= 156) { local_gw = /* Local gateway address. */ (unsigned int)msg_inp[ 152]* 256* 256* 256+ (unsigned int)msg_inp[ 153]* 256* 256+ (unsigned int)msg_inp[ 154]* 256+ (unsigned int)msg_inp[ 155]; if ((debug& DBG_MSI) != 0) { fprintf( stderr, " Local GW address: 0x%08x %u.%u.%u.%u\n", local_gw, msg_inp[ 152], msg_inp[ 153], msg_inp[ 154], msg_inp[ 155]); } } if (bc >= 160) { local_nm = /* Local netmask. */ (unsigned int)msg_inp[ 156]* 256* 256* 256+ (unsigned int)msg_inp[ 157]* 256* 256+ (unsigned int)msg_inp[ 158]* 256+ (unsigned int)msg_inp[ 159]; if ((debug& DBG_MSI) != 0) { fprintf( stderr, " Local Netmask: 0x%08x %u.%u.%u.%u\n", local_nm, msg_inp[ 156], msg_inp[ 157], msg_inp[ 158], msg_inp[ 159]); } } if (bc >= 161) { if ((debug& DBG_MSI) != 0) { fprintf( stderr, " DHCP: %d (0x%02x)\n", msg_inp[ 160], msg_inp[ 160]); } } if (bc >= 162) { if ((debug& DBG_MSI) != 0) { fprintf( stderr, " Discoverable: %d (0x%02x)\n", msg_inp[ 161], msg_inp[ 161]); } } if (bc >= 163) { if ((debug& DBG_MSI) != 0) { fprintf( stderr, " Time zone set: %d (0x%02x)\n", msg_inp[ 162], msg_inp[ 162]); } } if (bc >= 164) { if ((debug& DBG_MSI) != 0) { fprintf( stderr, " Time zone: %d (0x%02x)\n", (char)msg_inp[ 163], msg_inp[ 163]); } } if (bc >= 166) { countdown_sts = /* Countdown status. */ (unsigned short)msg_inp[ 165]* 256+ (unsigned short)msg_inp[ 164]; if ((debug& DBG_MSI) != 0) { fprintf( stderr, " Countdown status: %d (0x%04x)\n", countdown_sts, countdown_sts); } } if (bc >= 168) { countdown = /* Countdown (s). */ (unsigned short)msg_inp[ 167]* 256+ (unsigned short)msg_inp[ 166]; if ((debug& DBG_MSI) != 0) { fprintf( stderr, " Countdown: %d (0x%04x)\n", countdown, countdown); } save_orv_data = RSP_RT; /* Found good data (rt). */ } } /* table_nr == 4 */ } else if ((msg_inp[ 4] == 's') && (msg_inp[ 5] == 'f')) { /* Device control (Switch Off/On) ("sf"). */ *rsp_p |= RSP_SF; if (bc >= 12) { mac_addr_ndx = 6; } if (bc >= 23) { state_new = msg_inp[ 22]; save_orv_data = RSP_SF; /* Found good data (sf). */ } } else if ((msg_inp[ 4] == 't') && (msg_inp[ 5] == 'm')) { /* Write Table ("tm"). */ *rsp_p |= RSP_TM; if (bc >= 12) { mac_addr_ndx = 6; } if (bc >= 23) { /* We expect 23 bytes. Can't really tell good from bad. */ #if 0 save_orv_data = RSP_TM; /* Found good data (tm). */ #endif /* 0 */ } } else { /* Unknown. */ *rsp_p |= RSP___; if ((debug& DBG_MSI) != 0) { fprintf( stderr, " Unexpected response: \"%c%c\" (%.1x%.1x).\n", msg_inp[ 4], msg_inp[ 5], msg_inp[ 4], msg_inp[ 5]); } } if ((debug& DBG_MSI) != 0) { if ((state_old >= 0) || (state_new >= 0)) { char state_new_str[ 16]; char state_old_str[ 16]; sprintf( state_new_str, "%2.2x", state_new); sprintf( state_old_str, "%2.2x", state_old); fprintf( stderr, " States: old = %s, new = %s.\n", ((state_old < 0) ? "??" : state_old_str), ((state_new < 0) ? "??" : state_new_str)); } if (mac_addr_ndx >= 0) { int i; fprintf( stderr, " MAC addr: "); for (i = mac_addr_ndx; i < mac_addr_ndx+ MAC_ADDR_SIZE; i++) { fprintf( stderr, "%02x", msg_inp[ i]); if (i < mac_addr_ndx+ MAC_ADDR_SIZE- 1) { fprintf( stderr, ":"); } if (i == mac_addr_ndx+ MAC_ADDR_SIZE- 1) { fprintf( stderr, "\n"); } } } } } } } if ((save_orv_data > 0) && (mac_addr_ndx >= 0)) { orv_data_p = orv_data_find_mac( origin_p, &msg_inp[ mac_addr_ndx]); if ((debug& DBG_MSI) != 0) { fprintf( stderr, " s_o_d = %d, o_f_d_m() = %sNULL.\n", save_orv_data, ((orv_data_p == NULL) ? "" : "non-")); } if (orv_data_p == NULL) { orv_data_p = orv_data_new( origin_p, ((origin_p->sort_key == SRT_IP) ? (void *)&sock_addr_rec.sin_addr : /* IP address. */ (void *)&msg_inp[ mac_addr_ndx])); /* MAC address. */ if (orv_data_p == NULL) { fprintf( stderr, "%s: malloc() failed [1].\n", PROGRAM_NAME); } else { memcpy( orv_data_p->mac_addr, &msg_inp[ mac_addr_ndx], MAC_ADDR_SIZE); orv_data_p->ip_addr.s_addr = sock_addr_rec.sin_addr.s_addr; } } else if (save_orv_data == RSP_RT) { /* Have Read Table (detailed) data. */ memcpy( orv_data_p->passwd, remote_password, PASSWORD_LEN); memcpy( orv_data_p->name, device_name, DEV_NAME_LEN); orv_data_p->type = icon_code; orv_data_p->port = server_port; } if (state_new >= 0) { orv_data_p->state = state_new; } else if (state_old >= 0) { orv_data_p->state = state_old; } } } #ifdef VMS # ifndef NO_OPER_PRIVILEGE /* Restore original OPER privilege state, if elevated. */ if (oper_priv_save == 0) /* Was set (not -1), and initial was zero. */ { sts = set_priv_oper( 0, &oper_priv_save); if (sts != 0) { fprintf( stderr, "%s: Remove privilege (OPER) failed. sts = %%x%08x .\n", PROGRAM_NAME, sts); show_errno( PROGRAM_NAME); } else if ((debug& DBG_VMS) != 0) { fprintf( stderr, " set_priv_oper(restore). sts = %%x%08x , oper_old = %d.\n", sts, oper_priv_save); } } # endif /* ndef NO_OPER_PRIVILEGE */ #endif /* def VMS */ if (!BAD_SOCKET( sock_orv)) { CLOSE_SOCKET( sock_orv); } if ((debug& DBG_MSI) != 0) { fprintf( stderr, " task(end). sts = %d.\n", sts); } return sts; } /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* msleep(): Suspend process for <arg> milliseconds. * <arg> < 1000 if using usleep(). */ #ifdef _WIN32 /* Windows: Use msleep(). */ int msleep( int msec) { Sleep( msec); return 0; } #else /* def _WIN32 */ /* Non-Windows: Use usleep(). */ int msleep( int msec) { int sts; if (msec >= 1000) { errno = EINVAL; sts = -1; } else { sts = usleep( msec* 1000); } return sts; } #endif /* def _WIN32 [else] */ /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* task_retry(): Execute task() with retries. * Retry until rsp_req condition is met, or retry limit is * reached. */ int task_retry( int rsp_req, /* Response requirement bit mask. */ int task_nr, /* Task number. */ int *rsp_p, /* Response type bit mask. */ unsigned char **tbl_p, /* Table data. */ orv_data_t *origin_p, /* orv_data origin. */ orv_data_t *target_p) /* orv_data target. */ { int retry_count = 0; int sts = 0; while ((sts == 0) && ((*rsp_p& rsp_req) == 0) && (retry_count < TASK_RETRY_MAX)) { if (retry_count > 0) { if (((debug& DBG_MSI) != 0) || ((debug& DBG_MSO) != 0)) { fprintf( stderr, " TASK RETRY (%d). N = %d, rsp = %08x , rsp_req = %08x .\n", task_nr, retry_count, *rsp_p, rsp_req); } msleep( TASK_RETRY_WAIT); /* Delay (ms) between retries. */ } sts = task( task_nr, rsp_p, tbl_p, origin_p, target_p); retry_count++; } return sts; } /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* catalog_devices_ddf(): Use file data to populate the orv_data LL. */ #define CLG_LINE_MAX 256 int catalog_devices_ddf( FILE *fp, /* File pointer. */ int *clg_line_nr, /* File line number. */ char *err_tkn, /* Bad token. */ orv_data_t *origin_p) /* LL origin. */ { int sts = 0; char clg_line[ CLG_LINE_MAX+ 1]; /* fgets() buffer. */ char *cp; /* fgets() result, ... */ char *ipa; /* IP address string. */ char *mac; /* MAC address string. */ char *nam; /* Device name string. */ int fl; /* file line length, ... */ struct in_addr ip_addr; /* IP address. */ unsigned char mac_b[ 6]; /* MAC address. */ orv_data_t *orv_data_p; *clg_line_nr = 0; /* File line number. */ while ((cp = fgets( clg_line, CLG_LINE_MAX, fp)) != NULL) { (*clg_line_nr)++; /* Count this line. */ ipa = NULL; /* Clear token pointers. */ mac = NULL; nam = NULL; clg_line[ CLG_LINE_MAX] = '\0'; /* Make buffer-end tidy. */ fl = strlen( clg_line); if ((fl > 0) && (clg_line[ fl- 1] == '\n')) { clg_line[ fl- 1] = '\0'; /* Strip off a new-line. */ } if ((cp = strchr( clg_line, '#')) != NULL) /* Trim comment. */ { *cp = '\0'; } if (strlen( clg_line) > 0) /* Trim leading white space. */ { cp = clg_line; while (isspace( *cp)) { cp++; } } if (strlen( cp) == 0) /* No data on line. */ { continue; } if (strlen( cp) > 0) { ipa = cp; /* IP address. */ while (!isspace( *cp)) { cp++; } *cp++ = '\0'; /* NUL-terminate at first space. */ } if (strlen( cp) > 0) /* Skip white space. */ { while (isspace( *cp)) { cp++; } mac = cp; /* MAC address. */ while (!isspace( *cp)) { cp++; } *cp++ = '\0'; /* NUL-terminate at first space. */ } if (strlen( cp) > 0) { while (isspace( *cp)) /* Skip white space. */ { cp++; } nam = cp; /* Device name. */ if (*cp == '>') /* Apparently, ">name<". */ { nam++; while ((*cp != '\0') && (*cp != '<')) { cp++; } *cp++ = '\0'; /* NUL-terminate at "<". */ } else { while (!isspace( *cp)) { cp++; } *cp++ = '\0'; /* NUL-terminate at first space. */ } } if (ipa == NULL) { sts = -2; break; } if (mac == NULL) { sts = -3; break; } if (nam == NULL) { sts = -4; break; } if ((debug& DBG_FIL) != 0) { fprintf( stderr, " ipa: >%s<, mac: >%s<, nam: >%s<\n", ipa, mac, nam); } sts = dns_resolve( ipa, &ip_addr); if (sts != 0) { sts = -5; fprintf( stderr, "%s: Bad IP address on line %d: >%s<.\n", PROGRAM_NAME, *clg_line_nr, ipa); break; } sts = parse_mac( mac, mac_b); if (sts != 0) { sts = -6; fprintf( stderr, "%s: Bad MAC address on line %d: >%s<.\n", PROGRAM_NAME, *clg_line_nr, mac); break; } fl = strlen( nam); if (fl > DEV_NAME_LEN) { sts = -7; fprintf( stderr, "%s: Name too long (len = %d > %d) on line %d: >%s<.\n", PROGRAM_NAME, fl, DEV_NAME_LEN, *clg_line_nr, nam); break; } /* (Check name for invalid characters? What's valid?) */ orv_data_p = orv_data_new( origin_p, ((origin_p->sort_key == SRT_IP) ? (void *)&ip_addr : (void *)mac_b)); if (orv_data_p == NULL) { fprintf( stderr, "%s: malloc() failed [2].\n", PROGRAM_NAME); break; } else { memcpy( orv_data_p->mac_addr, mac_b, MAC_ADDR_SIZE); /* MAC addr. */ orv_data_p->ip_addr.s_addr = ip_addr.s_addr; /* IP addr. */ if ((fl == strlen( UNSET_NAME)) && (memcmp( nam, UNSET_NAME, strlen( UNSET_NAME)) == 0)) { memset( orv_data_p->name, 0xff, DEV_NAME_LEN); /* Unset name. */ } else { memcpy( orv_data_p->name, nam, fl); /* Device name. */ memset( orv_data_p->name+ fl, 0x20, /* Blank fill. */ (DEV_NAME_LEN- fl)); } } } /* while */ if ((debug& DBG_FIL) != 0) { fprintf( stderr, " catalog_devices_ddf(end). sts = %d.\n", sts); fprintf_device_list( stdout, FDL_DDF, origin_p); } return sts; } /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* discover_devices(): Use Unit Discovery to populate the orv_data LL. */ int discover_devices( int single, orv_data_t *origin_p) { int rsp; int sts; orv_data_t *orv_data_p; if ((debug& DBG_DEV) != 0) { fprintf( stderr, " disc_devs(0). single = %08x .\n", single); } orv_data_p = origin_p->next; /* Start with first (real?) LL mmbr. */ while (orv_data_p != origin_p) /* Quit when back to the origin. */ { if ((debug& DBG_DEV) != 0) { fprintf( stderr, " disc_devs(1). cnt_flg = %d.\n", orv_data_p->cnt_flg); fprintf_device( stderr, orv_data_p); } if ((single == 0) || (orv_data_p->cnt_flg != 0)) { /* Send Unit Discovery message. Expect some "qg" response. */ rsp = 0; sts = task_retry( RSP_QG, TSK_UNIT_DISC, &rsp, NULL, origin_p, orv_data_p); if (sts != 0) { fprintf( stderr, "%s: Unit discovery. sts = %d.\n", PROGRAM_NAME, sts); break; } } orv_data_p = orv_data_p->next; /* Advance to the next member. */ } /* while */ if ((debug& DBG_DEV) != 0) { fprintf( stderr, " disc_devs(end). sts = %d.\n", sts); } return sts; } /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* query_devices(): Query devices to populate the orv_data LL. */ int query_devices( int single, orv_data_t *origin_p) { int rsp; int sts; orv_data_t *orv_data_p; if ((debug& DBG_DEV) != 0) { fprintf( stderr, " query_devs(0). single = %08x .\n", single); } orv_data_p = origin_p->next; /* Start with first (real?) LL mmbr. */ while (orv_data_p != origin_p) /* Quit when back to the origin. */ { if ((debug& DBG_DEV) != 0) { fprintf( stderr, " query_devs(1). cnt_flg = %d.\n", orv_data_p->cnt_flg); fprintf_device( stderr, orv_data_p); } if ((single == 0) || (orv_data_p->cnt_flg != 0)) { /* Send Subscribe message. Expect some "cl" response. */ rsp = 0; sts = task_retry( RSP_CL, TSK_SUBSCRIBE, &rsp, NULL, origin_p, orv_data_p); if (sts != 0) { fprintf( stderr, "%s: Read table: socket. sts = %d.\n", PROGRAM_NAME, sts); break; } if (sts == 0) { /* Send Read table: socket message. Expect some "rt" response. */ rsp = 0; sts = task_retry( RSP_RT, TSK_RT_SOCKET, &rsp, NULL, origin_p, orv_data_p); if (sts != 0) { fprintf( stderr, "%s: Read table: socket. sts = %d.\n", PROGRAM_NAME, sts); break; } } } orv_data_p = orv_data_p->next; /* Advance to the next member. */ } /* while */ if ((debug& DBG_DEV) != 0) { fprintf( stderr, " query_devs(end). sts = %d.\n", sts); } return sts; } /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* catalog_devices_live(): Use Global Discovery to populate the orv_data LL. */ int catalog_devices_live( orv_data_t *origin_p) { int rsp; int sts; /* Broadcast query (Global discovery). Expect some "qa" response. */ rsp = 0; sts = task_retry( RSP_QA, TSK_GLOB_DISC_B, &rsp, NULL, origin_p, origin_p); if (sts == 0) { if (origin_p->cnt_flg == 0) { fprintf( stderr, "%s: No devices found (loc=cdl).\n", PROGRAM_NAME); errno = ENXIO; sts = -1; } else { if ((debug& DBG_DEV) != 0) { fprintf( stderr, " Devices found: %d.\n", origin_p->cnt_flg); } sts = query_devices( 0, origin_p); /* Query all devs in the LL. */ } } if ((debug& DBG_DEV) != 0) { fprintf( stderr, " catalog_devices_live(end). sts = %d.\n", sts); } return sts; } /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* keyword_match(): Match abbreviated keyword against keyword array. */ int keyword_match( char *arg, int kw_cnt, char **kw_array) { int cmp_len; int kw_ndx; int match = -1; cmp_len = strlen( arg); for (kw_ndx = 0; kw_ndx < kw_cnt; kw_ndx++) { if (STRNCASECMP( arg, kw_array[ kw_ndx], cmp_len) == 0) { if (match < 0) { match = kw_ndx; /* Record first match. */ } else { match = -2; /* Record multiple match, */ break; /* and quit early. */ } } } return match; } /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* main(): Main program. */ int main( int argc, char **argv) { int brief; int expect_set = 0; int match_opr; int opts_ndx; int quiet; int rsp; int single; int specific_ip; int sts; int task_nr; size_t cmp_len; char *orv_data_file_name = NULL; FILE *fp; char *new_dev_name = NULL; char *new_password = NULL; size_t new_dev_name_len; size_t new_password_len; unsigned short msg_len; unsigned char *msg_tmp1_p; unsigned char *msg_tmp2_p; orv_data_t *orv_data_p; orv_data_t orv_data = /* orv_data LL origin. */ { &orv_data, /* next ptr. */ &orv_data, /* prev ptr. */ 0, /* cnt_flg. */ SRT_IP, /* sort_key. */ { 0 }, /* ip_addr. */ htons( PORT_ORV), /* port. */ -1, /* type. */ { 0, 0, 0, 0, 0, 0, 0, 0, /* (device) name. */ 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* passwd. */ { 0, 0, 0, 0, 0, 0 }, /* mac_addr */ -1, /* state. */ }; brief = 0; debug = 0; quiet = 0; single = 0; sts = 0; /* Check command-line arguments. */ if (sts == 0) { char *eqa_p; char *eqo_p; int opts_cnt = sizeof( opts)/ sizeof( *opts); int match_opt; while (argc > 1) { /* Parse/skip option arguments. */ match_opt = -1; eqa_p = strchr( argv[ 1], '='); /* Find "=" in arg. */ for (opts_ndx = 0; opts_ndx < opts_cnt; opts_ndx++) /* Try all opts. */ { eqo_p = strchr( opts[ opts_ndx], '='); /* Find "=" in opt. */ if (! ((eqa_p == NULL) ^ (eqo_p == NULL))) { /* "=" in both arg and opt, or neither. */ if (eqa_p == NULL) { /* No "=" in argument/option. Compare whole strings. */ cmp_len = OMIN( strlen( argv[ 1]), strlen( opts[ opts_ndx])); } else { /* "=". Compare strings before "=". */ cmp_len = (eqa_p- argv[ 1]); } if (STRNCASECMP( argv[ 1], opts[ opts_ndx], cmp_len) == 0) { if (match_opt < 0) { match_opt = opts_ndx; /* Record first match. */ } else { match_opt = -2; /* Record multiple match, */ break; /* and quit early. */ } } /* if arg-opt match */ } /* if "=" match */ } /* for opts_ndx */ /* All options checked. Act accordingly. */ if (match_opt < -1) { /* Multiple match. */ fprintf( stderr, "%s: Ambiguous option: %s\n", PROGRAM_NAME, argv[ 1]); errno = EINVAL; sts = EXIT_FAILURE; break; /* while */ } else if (match_opt < 0) /* Not a known option. Arg? */ { break; /* while */ } else /* Recognized option. */ { if (match_opt == OPT_BRIEF) /* "brief". */ { match_opt = -1; /* Consumed. */ brief = 1; } else if (match_opt == OPT_QUIET) /* "quiet". */ { match_opt = -1; /* Consumed. */ quiet = 1; } else if (match_opt == OPT_DDF) /* "ddf". */ { /* No "=file_spec". Use environment variable. */ match_opt = -1; /* Consumed. */ orv_data_file_name = getenv( ORVL_DDF); if (orv_data_file_name == NULL) { orv_data_file_name = ORVL_DDF; } } else if (match_opt == OPT_DDF_EQ) /* "ddf=file_spec". */ { match_opt = -1; /* Consumed. */ orv_data_file_name = argv[ 1]+ cmp_len+ 1; } else if (match_opt == OPT_DEBUG) /* "debug". */ { match_opt = -1; /* Consumed. */ debug = 0xffffffff; fprintf( stderr, " debug: 0x%08x .\n", debug); } else if (match_opt == OPT_DEBUG_EQ) /* "debug=". */ { match_opt = -1; /* Consumed. */ debug = strtol( (argv[ 1]+ cmp_len+ 1), NULL, 0); fprintf( stderr, " debug = 0x%08x .\n", debug); } else if (match_opt == OPT_NAME_EQ) /* "name=". */ { match_opt = -1; /* Consumed. */ expect_set = 1; /* Expect "set" op. */ new_dev_name = argv[ 1]+ cmp_len+ 1; new_dev_name_len = strlen( new_dev_name); if (new_dev_name_len > DEV_NAME_LEN) { fprintf( stderr, "%s: Device name too long (len = %ld > %d): %s\n", PROGRAM_NAME, new_dev_name_len, DEV_NAME_LEN, argv[ 1]); errno = EINVAL; sts = EXIT_FAILURE; break; /* while */ } } else if (match_opt == OPT_PASSWORD_EQ) /* "password=". */ { match_opt = -1; /* Consumed. */ expect_set = 1; /* Expect "set" op. */ new_password = argv[ 1]+ cmp_len+ 1; new_password_len = strlen( new_password); if (new_password_len > PASSWORD_LEN) { fprintf( stderr, "%s: Password too long (len = %ld > %d): %s\n", PROGRAM_NAME, new_password_len, PASSWORD_LEN, argv[ 1]); errno = EINVAL; sts = EXIT_FAILURE; break; /* while */ } } else if (match_opt == OPT_SORT_EQ) /* "sort=". */ { match_opt = -1; /* Consumed. */ /* Match sort-key keyword. */ orv_data.sort_key = keyword_match( (argv[ 1]+ cmp_len+ 1), (sizeof( sort_keys)/ sizeof( *sort_keys)), sort_keys); if (orv_data.sort_key < -1) { /* Multiple match. */ fprintf( stderr, "%s: Ambiguous sort key: >%s<\n", PROGRAM_NAME, (argv[ 1]+ cmp_len+ 1)); usage(); errno = EINVAL; sts = EXIT_FAILURE; } else if (orv_data.sort_key < 0) /* Not a known key. */ { /* No match. */ fprintf( stderr, "%s: Invalid sort key: >%s<.\n", PROGRAM_NAME, (argv[ 1]+ cmp_len+ 1)); usage(); errno = EINVAL; sts = EXIT_FAILURE; } } if (match_opt >= 0) /* Unexpected option. */ { /* Match, but no handler. */ fprintf( stderr, "%s: Unexpected option (bug), code = %d.\n", PROGRAM_NAME, match_opt); errno = EINVAL; sts = EXIT_FAILURE; break; /* while */ } argc--; /* Shift past this argument. */ argv++; } } /* while argc */ } if ((debug& DBG_OPT) != 0) { fprintf( stderr, " SET opts: dev_name: >%s<, password: >%s<\n", ((new_dev_name == NULL) ? "" : new_dev_name), ((new_password == NULL) ? "" : new_password)); } if (sts == 0) { if (argc < 2) { fprintf( stderr, "%s: Missing required operation. (Post-options arg count = %d.)\n", PROGRAM_NAME, (argc- 1)); usage(); errno = E2BIG; sts = EXIT_FAILURE; } else if (argc > 3) { fprintf( stderr, "%s: Excess arg(s), or bad opts. (Post-opts arg count = %d.)\n", PROGRAM_NAME, (argc- 1)); usage(); errno = E2BIG; sts = EXIT_FAILURE; } else { /* Match operation keyword. */ match_opr = keyword_match( argv[ 1], /* Opr keyword candidate. */ (sizeof( oprs)/ sizeof( *oprs)), /* Opr keyword array size. */ oprs); /* Opr keyword array. */ /* All operations checked. Act accordingly. */ if (match_opr < -1) { /* Multiple match. */ fprintf( stderr, "%s: Ambiguous operation: >%s<\n", PROGRAM_NAME, argv[ 1]); usage(); errno = EINVAL; sts = EXIT_FAILURE; } else if (match_opr < 0) /* Not a known option. Arg? */ { /* No match. */ fprintf( stderr, "%s: Invalid option/operation: >%s<.\n", PROGRAM_NAME, argv[ 1]); usage(); errno = EINVAL; sts = EXIT_FAILURE; } else if ((expect_set != 0) && (match_opr != OPR_SET)) { fprintf( stderr, "%s: \"name=\" or \"password=\" option, but operation not \"set\": %s\n", PROGRAM_NAME, oprs[ match_opr]); usage(); errno = EINVAL; sts = EXIT_FAILURE; } else if ((expect_set == 0) && (match_opr == OPR_SET)) { fprintf( stderr, "%s: Operation \"set\", but no \"name=\" or \"password=\" option.\n", PROGRAM_NAME); usage(); errno = EINVAL; sts = EXIT_FAILURE; } else if (argc < 3) { if ((match_opr == OPR_HEARTBEAT) || (match_opr == OPR_OFF) || (match_opr == OPR_ON) || (match_opr == OPR_SET)) { fprintf( stderr, "%s: Missing required device identifier for operation: %s\n", PROGRAM_NAME, oprs[ match_opr]); usage(); errno = EINVAL; sts = EXIT_FAILURE; } } } } /* Prepare for device communication. */ #ifdef _WIN32 /* Windows socket library, start-up, ... */ # pragma comment( lib, "ws2_32.lib") /* Arrange WinSock link library. */ if (sts == 0) { WORD ws_ver_req = MAKEWORD( 2, 2); /* Request WinSock version 2.2. */ WSADATA wsa_data; sts = WSAStartup( ws_ver_req, &wsa_data); if (sts != 0) { fprintf( stderr, "%s: Windows socket start-up failed. sts = %d.\n", PROGRAM_NAME, sts); show_errno( PROGRAM_NAME); } else if ((debug& DBG_WIN) != 0) { /* LOBYTE = MSB, HIBYTE = LSB. */ fprintf( stderr, " wVersion = %d.%d, wHighVersion = %d.%d.\n", LOBYTE( wsa_data.wVersion), HIBYTE( wsa_data.wVersion), LOBYTE( wsa_data.wHighVersion), HIBYTE( wsa_data.wHighVersion)); } } #endif /* def _WIN32 */ if (sts == 0) { /* Assume broadcast, but use argv[ 2] if it can be resolved. */ specific_ip = 0; orv_data.ip_addr.s_addr = htonl( INADDR_BROADCAST); if (argc >= 3) { int sts2; struct in_addr ip_addr; single = 1; /* User-specified device (DNS, IP, name). */ sts2 = dns_resolve( argv[ 2], &ip_addr); /* Try to resolve the name. */ if ((debug& DBG_DNS) != 0) { fprintf( stderr, " dns_resolve() sts = %d.\n", sts2); } if (sts2 == 0) { specific_ip = 1; orv_data.ip_addr.s_addr = ip_addr.s_addr; } } } if (sts == 0) { /* Open/read the data file, if specified. Otherwise, broadcast query. */ if (orv_data_file_name != NULL) { fp = fopen( orv_data_file_name, "r"); if (fp == NULL) { sts = -1; fprintf( stderr, "%s: Open (read) failed: %s\n", PROGRAM_NAME, orv_data_file_name); show_errno( PROGRAM_NAME); } else { int line_nr; char err_tkn[ CLG_LINE_MAX]; sts = catalog_devices_ddf( fp, &line_nr, err_tkn, &orv_data); if (sts == -2) { fprintf( stderr, "%s: IP address not found on line %d.\n", PROGRAM_NAME, line_nr); } else if (sts == -3) { fprintf( stderr, "%s: MAC address not found on line %d.\n", PROGRAM_NAME, line_nr); } else if (sts == -4) { fprintf( stderr, "%s: Device name not found on line %d.\n", PROGRAM_NAME, line_nr); } else if (sts == -5) { fprintf( stderr, "%s: Bad IP address on line %d: >%s<.\n", PROGRAM_NAME, line_nr, err_tkn); } else if (sts == -6) { fprintf( stderr, "%s: Bad MAC address on line %d: >%s<.\n", PROGRAM_NAME, line_nr, err_tkn); } else if (sts == -7) { fprintf( stderr, "%s: Name too long (len > %d) on line %d: >%s<.\n", PROGRAM_NAME, line_nr, DEV_NAME_LEN, err_tkn); } else if (sts != 0) { fprintf( stderr, "%s: Unknown error (%d) reading file at line %d.\n", PROGRAM_NAME, sts, line_nr); } fclose( fp); } } } if (sts == 0) { if (match_opr == OPR_HEARTBEAT) { /* "Heartbeat". */ if (specific_ip == 0) { /* Unknown IP address. Use broadcast query. */ if (orv_data_file_name == NULL) { sts = catalog_devices_live( &orv_data); } } else { /* Specific IP address. Use specific query. */ /* Send Global discovery message. Expect some "qa" response. */ rsp = 0; sts = task_retry( RSP_QA, TSK_GLOB_DISC, &rsp, NULL, &orv_data, &orv_data); } if (sts == 0) { if (specific_ip == 0) { /* Compare device names (name arg v. real LL data). */ orv_data_p = orv_data_find_name( &orv_data, argv[ 2]); } else { /* Compare IP addresses (LL origin v. real LL data). */ orv_data_p = orv_data_find_ip_addr( &orv_data); } if (orv_data_p == NULL) { fprintf( stderr, "%s: Device name not matched (loc=%d): >%s<.\n", PROGRAM_NAME, 2, argv[ 2]); errno = ENXIO; sts = EXIT_FAILURE; } } if (sts == 0) { /* Send Heartbeat message. Expect some "hb" response. */ rsp = 0; sts = task_retry( RSP_HB, TSK_HEARTBEAT, &rsp, NULL, &orv_data, orv_data_p); if ((sts == 0) && ((rsp& RSP_HB) == 0)) { fprintf( stderr, "%s: No heartbeat response received.\n", PROGRAM_NAME); errno = ENOMSG; sts = -1; } } } else if (match_opr == OPR_LIST) { /* "list". List device(s), without query, if possible. */ if (orv_data_file_name == NULL) { /* No DDF data available. */ if ((single != 0) && (specific_ip == 0)) { /* Have a device name (if anything valid). Need full inventory. */ sts = catalog_devices_live( &orv_data); } else { /* General or specific IP address. Discovery is enough. */ task_nr = (specific_ip == 0) ? TSK_GLOB_DISC_B : TSK_GLOB_DISC; /* Send the appropriate (Global or Unit) discovery message. * Expect some "qa" response. */ rsp = 0; sts = task_retry( RSP_QA, task_nr, &rsp, NULL, &orv_data, &orv_data); if ((specific_ip == 0) && (orv_data.cnt_flg == 0)) { fprintf( stderr, "%s: No devices found (loc=list).\n", PROGRAM_NAME); errno = ENXIO; sts = -1; } else { if ((debug& DBG_DEV) != 0) { fprintf( stderr, " Devices found: %d.\n", orv_data.cnt_flg); } } } } if ((sts == 0) && (single != 0)) { /* Locate the specific device in the orv_data LL. */ sts = orv_data_find_dev( &orv_data, specific_ip, argv[ 2], 0); } if ((sts == 0) && (orv_data_file_name != NULL)) { /* DDF data available. Use Unit discovery to sense. */ sts = discover_devices( single, &orv_data); } } else if (match_opr == OPR_QLIST) { /* "qlist". List device(s), with query. */ if (orv_data_file_name == NULL) { /* No DDF data available. Must query devices.*/ if (specific_ip == 0) { /* Do all, or could have a device name. Need full inventory. */ sts = catalog_devices_live( &orv_data); if ((sts == 0) && (single != 0)) { /* Match device name. */ sts = orv_data_find_dev( &orv_data, specific_ip, argv[ 2], 1); } } else { /* Have IP address. Do specific Global Discovery and query. */ rsp = 0; sts = task_retry( RSP_QA, TSK_GLOB_DISC, &rsp, NULL, &orv_data, &orv_data); if (sts == 0) { /* Match specific IP address. */ sts = orv_data_find_dev( &orv_data, specific_ip, argv[ 2], 1); if (sts == 0) { /* Query the single device. */ sts = query_devices( single, &orv_data); } } } } else { /* Using DDF. Query the significant devices. */ if (single != 0) { /* Match specific IP address or device name. */ sts = orv_data_find_dev( &orv_data, specific_ip, argv[ 2], 1); } if (sts == 0) { sts = query_devices( single, &orv_data); } } } else if ((match_opr == OPR_OFF) || (match_opr == OPR_ON)) { /* "Off", "On". Device control: Switch Off/On. */ if (specific_ip == 0) { /* Unknown IP address. Use broadcast query. */ if (orv_data_file_name == NULL) { sts = catalog_devices_live( &orv_data); } } else { /* Specific IP address. Use specific query. */ /* Send Global discovery message. Expect some "qa" response. */ rsp = 0; sts = task_retry( RSP_QA, TSK_GLOB_DISC, &rsp, NULL, &orv_data, &orv_data); } if (sts == 0) { if (specific_ip == 0) { /* Compare device names (name arg v. real LL data). */ orv_data_p = orv_data_find_name( &orv_data, argv[ 2]); } else { /* Compare IP addresses (LL origin v. real LL data). */ orv_data_p = orv_data_find_ip_addr( &orv_data); } if (orv_data_p == NULL) { fprintf( stderr, "%s: Device name not matched (loc=%d): >%s<.\n", PROGRAM_NAME, 2, argv[ 2]); errno = ENXIO; sts = EXIT_FAILURE; } else { orv_data_p->cnt_flg = 1; /* Mark this member for reportng. */ } } if (sts == 0) { /* Send Subscribe message. Expect some "cl" response. */ rsp = 0; single = 1; sts = task_retry( RSP_CL, TSK_SUBSCRIBE, &rsp, NULL, &orv_data, orv_data_p); if (sts == 0) { /* Send Device control message. Expect some "dc" response. */ /* (Use one loop for both Subscribe and Device control? */ rsp = 0; task_nr = (match_opr == OPR_OFF) ? TSK_SW_OFF : TSK_SW_ON; sts = task_retry( RSP_DC, task_nr, &rsp, NULL, &orv_data, orv_data_p); } } } else if (match_opr == OPR_SET) { /* "set". Set device parameter(s). */ if (specific_ip == 0) { /* Unknown IP address. Use broadcast query. */ if (orv_data_file_name == NULL) { sts = catalog_devices_live( &orv_data); } } else { /* Specific IP address. Use specific query. */ /* Send Global discovery message. Expect some "qa" response. */ rsp = 0; sts = task_retry( RSP_QA, TSK_GLOB_DISC, &rsp, NULL, &orv_data, &orv_data); } if (sts == 0) { if (specific_ip == 0) { /* Compare device names (name arg v. real LL data). */ orv_data_p = orv_data_find_name( &orv_data, argv[ 2]); } else { /* Compare IP addresses (LL origin v. real LL data). */ orv_data_p = orv_data_find_ip_addr( &orv_data); } if (orv_data_p == NULL) { fprintf( stderr, "%s: Device name not matched (loc=%d): >%s<.\n", PROGRAM_NAME, 2, argv[ 2]); errno = ENXIO; sts = EXIT_FAILURE; } else { orv_data_p->cnt_flg = 1; /* Mark this member for reportng. */ } } if (sts == 0) { /* Send Subscribe message. Expect some "cl" response. */ rsp = 0; single = 1; sts = task_retry( RSP_CL, TSK_SUBSCRIBE, &rsp, NULL, &orv_data, orv_data_p); if (sts == 0) { /* Send Read table: socket message. Expect some "rt" response. * Save the "rt" response for use (after modification) as the * "tm" message. */ rsp = 0; msg_tmp1_p = NULL; msg_tmp2_p = NULL; sts = task_retry( RSP_RT, TSK_RT_SOCKET, &rsp, &msg_tmp1_p, &orv_data, orv_data_p); if (sts != 0) { fprintf( stderr, "%s: Read table: socket. sts = %d.\n", PROGRAM_NAME, sts); } else if (msg_tmp1_p == NULL) { fprintf( stderr, "%s: Read table: socket. NULL ptr.\n", PROGRAM_NAME); sts = -1; } else { /* Extract response message length. */ msg_len = (unsigned short)msg_tmp1_p[ 2]* 256+ (unsigned short)msg_tmp1_p[ 3]; if ((debug& DBG_MSI) != 0) { /* Display the response (hex, ASCII). */ fprintf( stderr, " %c %c msg_len = %d\n", (msg_tmp1_p)[ 4], (msg_tmp1_p)[ 5], msg_len); msg_dump( msg_tmp1_p, msg_len); } } } if (sts == 0) { /* Form a new "tm" message from the saved "rt" response. * Overlay reduced message length and "tm" op-code onto the * saved "rt" response. Leave the initial "hd" (2 bytes) and * the MAC address and 0x20 padding (12 bytes). */ msg_tmp1_p[ 2] = (unsigned short)(msg_len- 3)/ 256; msg_tmp1_p[ 3] = (unsigned short)(msg_len- 3)% 256; memcpy( (msg_tmp1_p+ 4), (cmd_write_table+ 4), 2); /* Discard byte 18. Shift bytes 19:25 (including the table * and version numbers) left one byte (18:24). */ memmove( (msg_tmp1_p+ 18), (msg_tmp1_p+ 19), 7); /* Discard bytes 26, 27. Shift the remaining bytes (28:end) * left three bytes (25:(end-3)). */ memmove( (msg_tmp1_p+ 25), (msg_tmp1_p+ 28), (msg_len- 28)); /* Overlay "name=" option value onto the message. */ if (new_dev_name != NULL) { /* Option value plus blank fill. */ if (new_dev_name_len == 0) { /* No name specified. Reset to factory: 16* 0xff. */ memset( (msg_tmp1_p+ 67), 0xff, DEV_NAME_LEN); } else { /* Normal name. */ memcpy( (msg_tmp1_p+ 67), new_dev_name, new_dev_name_len); memset( (msg_tmp1_p+ 67+ new_dev_name_len), 0x20, (DEV_NAME_LEN- new_dev_name_len)); } } /* Overlay "password=" option value onto the message. */ if (new_password != NULL) { /* Option value plus blank fill. */ if (new_password_len == 0) { /* No password specified. Reset to factory: "888888". */ new_password = "888888"; new_password_len = strlen( new_password); } memcpy( (msg_tmp1_p+ 55), new_password, new_password_len); memset( (msg_tmp1_p+ 55+ new_password_len), 0x20, (PASSWORD_LEN- new_password_len)); } if ((debug& DBG_MSI) != 0) { if (msg_tmp1_p != NULL) { fprintf( stderr, " %c %c msg_len-3 = %d\n", (msg_tmp1_p)[ 4], (msg_tmp1_p)[ 5], (msg_len-3)); msg_dump( msg_tmp1_p, (msg_len-3)); } } /* Send Write table: socket message. Expect some "tm" response. */ rsp = 0; sts = task_retry( RSP_TM, TSK_WT_SOCKET, &rsp, &msg_tmp1_p, &orv_data, orv_data_p); if (sts != 0) { fprintf( stderr, "%s: Write table: socket. sts = %d.\n", PROGRAM_NAME, sts); } else if ((rsp& RSP_TM) == 0) { fprintf( stderr, "%s: No Write table: socket response received.\n", PROGRAM_NAME); errno = ENOMSG; sts = -1; } else { /* Got "tm" response. Re-query device to update data. */ /* Send Read table: socket message. Expect some "rt" response. * Save the "rt" response to check against requested data. */ rsp = 0; sts = task_retry( RSP_RT, TSK_RT_SOCKET, &rsp, &msg_tmp2_p, &orv_data, orv_data_p); if (sts != 0) { fprintf( stderr, "%s: Read table: socket. sts = %d.\n", PROGRAM_NAME, sts); } else { int cmp; /* If used, check requested device name against new "rt" data. */ if (new_dev_name != NULL) { cmp = memcmp( (msg_tmp1_p+ 67), (msg_tmp2_p+ 70), DEV_NAME_LEN); if (cmp != 0) { fprintf( stderr, "%s: Device name NOT set.\n", PROGRAM_NAME); errno = EINVAL; sts = -1; } else if ((debug& DBG_ACT) != 0) { fprintf( stderr, " New device name: >%*s<\n", DEV_NAME_LEN, (msg_tmp2_p+ 70)); } } /* If used, check requested password against new "rt" data. */ if (new_password != NULL) { cmp = memcmp( (msg_tmp1_p+ 55), (msg_tmp2_p+ 58), DEV_NAME_LEN); if (cmp != 0) { fprintf( stderr, "%s: Password NOT set.\n", PROGRAM_NAME); errno = EINVAL; sts = -1; } else if ((debug& DBG_ACT) != 0) { fprintf( stderr, " New password: >%*s<\n", PASSWORD_LEN, (msg_tmp2_p+ 58)); } } } } } } } else if ((match_opr == OPR_HELP) || (match_opr == OPR_USAGE)) { /* "help", "usage". */ usage(); } else if (match_opr == OPR_VERSION) { /* "version". */ fprintf( stdout, "%s %d.%d\n", PROGRAM_NAME, PROGRAM_VERSION_MAJ, PROGRAM_VERSION_MIN); } else { fprintf( stderr, "%s: Unexpected operation (bug), code = %d.\n", PROGRAM_NAME, match_opr); errno = EINVAL; sts = EXIT_FAILURE; } } if ((debug& DBG_SEL) != 0) { fprintf( stderr, " Pre-fdl(). sts = %d, brief = %d, quiet = %d, single = %d.\n", sts, brief, quiet, single); } /* Display any useful device data. */ if (sts == 0) { fprintf_device_list( stdout, (((orv_data_file_name == NULL) ? 0 : FDL_DDF) | /* Flags: ddf */ ((brief == 0) ? 0 : FDL_BRIEF) | /* brief */ ((quiet == 0) ? 0 : FDL_QUIET) | /* quiet */ ((single == 0) ? 0 : FDL_SINGLE)), /* one dev. */ &orv_data); } #ifndef NO_STATE_IN_EXIT_STATUS /* If success == status, then include a valid single-device state * (stored in the LL origin) in the exit status value (second lowest * hex digit). 0 -> 0x20, 1 -> 0x30, unknown -> 0x00. */ if ((sts == 0) && (orv_data.state >= 0)) { sts = (sts& (~0xf0))| (((orv_data.state == 0) ? 2 : 3)* 16); # ifdef VMS sts |= STS$K_SUCCESS; /* Retain success severity. */ # endif } #endif /* ndef NO_STATE_IN_EXIT_STATUS */ /* We could free the orv_data LL, output message, getaddrinfo(), and * various other malloc()'d storage, but why bother? */ exit( sts); } /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ #ifdef VMS /* LIB$INITIALIZE for DECC$ARGV_PARSE_STYLE on non-VAX systems. */ # ifdef __CRTL_VER # if !defined(__VAX) && (__CRTL_VER >= 70301000) # include <unixlib.h> /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* Global storage. */ /* Flag to sense if decc_init() was called. */ static int decc_init_done = -1; /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* decc_init() * * Uses LIB$INITIALIZE to set a collection of C RTL features without * requiring the user to define the corresponding logical names. */ /* Structure to hold a DECC$* feature name and its desired value. */ typedef struct { char *name; int value; } decc_feat_t; /* Array of DECC$* feature names and their desired values. */ decc_feat_t decc_feat_array[] = { /* Preserve command-line case with SET PROCESS/PARSE_STYLE=EXTENDED */ { "DECC$ARGV_PARSE_STYLE", 1 }, /* Preserve case for file names on ODS5 disks. */ { "DECC$EFS_CASE_PRESERVE", 1 }, /* Enable multiple dots (and most characters) in ODS5 file names, * while preserving VMS-ness of ";version". */ { "DECC$EFS_CHARSET", 1 }, /* List terminator. */ { (char *)NULL, 0 } }; /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* LIB$INITIALIZE initialization function. */ void decc_init(void) { int feat_index; int feat_value; int feat_value_max; int feat_value_min; int i; int sts; /* Set the global flag to indicate that LIB$INITIALIZE worked. */ decc_init_done = 1; /* Loop through all items in the decc_feat_array[]. */ for (i = 0; decc_feat_array[i].name != NULL; i++) { /* Get the feature index. */ feat_index = decc$feature_get_index(decc_feat_array[i].name); if (feat_index >= 0) { /* Valid item. Collect its properties. */ feat_value = decc$feature_get_value(feat_index, 1); feat_value_min = decc$feature_get_value(feat_index, 2); feat_value_max = decc$feature_get_value(feat_index, 3); if ((decc_feat_array[i].value >= feat_value_min) && (decc_feat_array[i].value <= feat_value_max)) { /* Valid value. Set it if necessary. */ if (feat_value != decc_feat_array[i].value) { sts = decc$feature_set_value( feat_index, 1, decc_feat_array[i].value); } } else { /* Invalid DECC feature value. */ printf(" INVALID DECC FEATURE VALUE, %d: %d <= %s <= %d.\n", feat_value, feat_value_min, decc_feat_array[i].name, feat_value_max); } } else { /* Invalid DECC feature name. */ printf(" UNKNOWN DECC FEATURE: %s.\n", decc_feat_array[i].name); } } } /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* Get "decc_init()" into a valid, loaded LIB$INITIALIZE PSECT. */ # pragma nostandard /* Establish the LIB$INITIALIZE PSECT, with proper alignment and * attributes. */ globaldef {"LIB$INITIALIZ"} readonly _align (LONGWORD) int spare[8] = { 0 }; globaldef {"LIB$INITIALIZE"} readonly _align (LONGWORD) void (*x_decc_init)() = decc_init; /* Fake reference to ensure loading the LIB$INITIALIZE PSECT. */ # pragma extern_model save /* The declaration for LIB$INITIALIZE() is missing in the VMS system header * files. Addionally, the lowercase name "lib$initialize" is defined as a * macro, so that this system routine can be reference in code using the * traditional C-style lowercase convention of function names for readability. * (VMS system functions declared in the VMS system headers are defined in a * similar way to allow using lowercase names within the C code, whereas the * "externally" visible names in the created object files are uppercase.) */ # ifndef lib$initialize /* Note: This "$" may annoy Sun compilers. */ # define lib$initialize LIB$INITIALIZE # endif int lib$initialize(void); # pragma extern_model strict_refdef int dmy_lib$initialize = (int)lib$initialize; # pragma extern_model restore # pragma standard # endif /* !defined(__VAX) && (__CRTL_VER >= 70301000) */ # endif /* __CRTL_VER */ #endif /* VMS */ /*--------------------------------------------------------------------*/
the_stack_data/26700660.c
#include <pthread.h> #include <semaphore.h> #include <stdio.h> #define N 5 #define THINKING 2 #define HUNGRY 1 #define EATING 0 #define LEFT (phnum + 4) % N #define RIGHT (phnum + 1) % N int state[N]; int phil[N] = { 0, 1, 2, 3, 4 }; sem_t mutex; sem_t S[N]; void test(int phnum) { if (state[phnum] == HUNGRY && state[LEFT] != EATING && state[RIGHT] != EATING) { // state that eating state[phnum] = EATING; sleep(2); printf("Philosopher %d takes fork %d and %d\n", phnum + 1, LEFT + 1, phnum + 1); printf("Philosopher %d is Eating\n", phnum + 1); // sem_post(&S[phnum]) has no effect // during takefork // used to wake up hungry philosophers // during putfork sem_post(&S[phnum]); } } // take up chopsticks void take_fork(int phnum) { sem_wait(&mutex); // state that hungry state[phnum] = HUNGRY; printf("Philosopher %d is Hungry\n", phnum + 1); // eat if neighbours are not eating test(phnum); sem_post(&mutex); // if unable to eat wait to be signalled sem_wait(&S[phnum]); sleep(1); } // put down chopsticks void put_fork(int phnum) { sem_wait(&mutex); // state that thinking state[phnum] = THINKING; printf("Philosopher %d putting fork %d and %d down\n", phnum + 1, LEFT + 1, phnum + 1); printf("Philosopher %d is thinking\n", phnum + 1); test(LEFT); test(RIGHT); sem_post(&mutex); } void* philospher(void* num) { while (1) { int* i = num; sleep(1); take_fork(*i); sleep(0); put_fork(*i); } } int main() { int i; pthread_t thread_id[N]; // initialize the semaphores sem_init(&mutex, 0, 1); for (i = 0; i < N; i++) sem_init(&S[i], 0, 0); for (i = 0; i < N; i++) { // create philosopher processes pthread_create(&thread_id[i], NULL, philospher, &phil[i]); printf("Philosopher %d is thinking\n", i + 1); } for (i = 0; i < N; i++) pthread_join(thread_id[i], NULL); }
the_stack_data/117329313.c
#include<stdio.h> #include<string.h> #include<stdlib.h> int main() { char *(*p[2])(char *,const char *); char a[10]="I Love ",b[10]="Program!",c[10],*p1,*p2; p[0]=strcpy; p[1]=strcat; p1=p[0](c,b); p2=p[1](a,b); printf("%s\n%s\n",p1,p2); return 0; }
the_stack_data/165769624.c
#include <stdio.h> // para printf() #include <stdlib.h> // para exit() int lista[]={1,2,10, 1,2,0b10, 1,2,0x10}; int longlista= sizeof(lista)/sizeof(int); int resultado=-1; int suma(int* array, int len) { int i, res=0; for (i=0; i<len; i++) res += array[i]; return res; } int main() { resultado = suma(lista, longlista); printf("resultado = %d = %0x hex\n", resultado,resultado); exit(0); }
the_stack_data/25137507.c
#include <stdint.h> #include <stdio.h> #include <inttypes.h> int8_t a; int32_t x; void b() { x = (uint64_t)4073709551607 > a || a != 0; } int main() { int32_t val_2; int8_t val_1; val_1 = -7; val_2 = 1695154176; x = val_2; a = val_1; b(); printf("a = %" PRIi8 "\n", a); printf("x = %" PRIi32 "\n", x); return 0; }
the_stack_data/31386767.c
#include<stdio.h> int main(){ int in; scanf("%d", &in); for (int i = 1; i <= in; i++) { if (i % 4 == 0) printf("PUM\n"); else printf("%d ", i); } } //https://pt.stackoverflow.com/q/138471/101
the_stack_data/184517798.c
#include <stdio.h> int main (void) { int a, b; scanf("%d %d", &a, &b); printf("%d", a + b); return 0; }
the_stack_data/26615.c
#include <stdio.h> #include <stdlib.h> #include <string.h> void Menu() { printf("::::::::::::::::::::::::::::::::::::: MENU ::::::::::::::::::::::::::::::::::::: \n"); printf("\n"); printf(" [01] Inserir uma pessoa na agenda [02] Busca por nome \n"); printf("\n"); printf(" [03] Busca por data de nascimento [04] Imprimir agenda \n"); printf("\n"); printf(" [05] SAIR \n"); printf("\n"); printf(":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: \n"); } struct Endereco { char Rua[50]; char Bairro[50]; char Cidade[50]; char Estado[50]; char Pais[50]; int Numero; int CEP; }; struct Nascimento { int Dia; int Mes; int Ano; }; struct Telefone { int DDD; int Numero; }; struct Pessoa { char Nome[100]; char Email[50]; char Obs[200]; struct Telefone Telefone_pessoa; struct Nascimento Nascimento_pessoa; struct Endereco Endereco_pessoa; }; int main() { int Escolha, i; int Flag; struct Pessoa Registro_de_pessoas[100]; i = 0; Flag = 1; while (Flag == 1){ Menu(); scanf("%d", &Escolha); if (Escolha == 01 || Escolha == 1){ i = i + 1; //contador para rodar o vetor de structs printf(":: Insira o nome da pessoa a ser cadastrada na agenda :: \n"); gets(Registro_de_pessoas[i].Nome); printf(":: Insira o e-mail da pessoa a ser cadastrada na agenda :: \n"); gets(Registro_de_pessoas[i].Email); printf(":: Insira a data de nascimento da pessoa a ser cadastrada na agenda :: \n"); printf(":: Dia :: \n"); scanf("%d", &Registro_de_pessoas[i].Nascimento_pessoa.Dia); printf(":: Mês :: \n"); scanf("%d", &Registro_de_pessoas[i].Nascimento_pessoa.Mes); printf(":: Ano :: \n"); scanf("%d", &Registro_de_pessoas[i].Nascimento_pessoa.Ano); printf(":: Insira o telefone da pessoa a ser cadastrada na agenda ::\n"); scanf("%d", &Registro_de_pessoas[i].Telefone_pessoa.Numero); printf(":: Insira o DDD do telefone :: \n"); scanf("%d", &Registro_de_pessoas[i].Telefone_pessoa.DDD); printf(":: Dados sobre o endereço :: \n"); printf(":: Insira o nome da rua :: \n"); gets(Registro_de_pessoas[i].Endereco_pessoa.Rua); printf(":: Insira o número da residencia :: \n"); gets(Registro_de_pessoas[i].Endereco_pessoa.Numero); printf(":: Insira o bairro :: \n"); gets(Registro_de_pessoas[i].Endereco_pessoa.Bairro); printf(":: Insira o nome da cidade :: \n"); gets(Registro_de_pessoas[i].Endereco_pessoa.Cidade); printf(":: Insira o CEP da cidade :: \n"); scanf("%d", &Registro_de_pessoas[i].Endereco_pessoa.CEP); printf(":: Insira o estado :: \n"); gets(Registro_de_pessoas[i].Endereco_pessoa.Estado); printf(":: Insira o pais :: \n"); gets(Registro_de_pessoas[i].Endereco_pessoa.Pais); } if (Escolha == 02 || Escolha == 2){ int j; char Nome_requisitado; printf(":: Insira o nome a ser buscado na agenda :: \n"); gets(Nome_requisitado); for (j = 0; j < 100; j ++){ if (strcmp(Nome_requisitado, Registro_de_pessoas[j].Nome) == 1){ printf(":: Nome encontrado :: \n"); printf("\n"); printf(":: Exibindo informações :: \n"); printf("\n"); printf("Nome : %s \n", Registro_de_pessoas[j].Nome); printf("E-mail : %s \n", Registro_de_pessoas[j].Email); printf("Nascimento : %d / %d / %d \n", Registro_de_pessoas[j].Nascimento_pessoa.Dia, Registro_de_pessoas[j].Nascimento_pessoa.Mes, Registro_de_pessoas[j].Nascimento_pessoa.Ano); printf("Telefone : %d %d",Registro_de_pessoas[j].Telefone_pessoa.DDD, Registro_de_pessoas[j].Telefone_pessoa.Numero); printf("\n"); printf(":: Dados do endereço :: \n"); printf("\n"); printf("Rua: %s \n", Registro_de_pessoas[j].Endereco_pessoa.Rua); printf("Numero da residencia : %d \n", Registro_de_pessoas[j].Endereco_pessoa.Numero); printf("Bairro : %s \n", Registro_de_pessoas[j].Endereco_pessoa.Bairro); printf("Cidade : %s \n", Registro_de_pessoas[j].Endereco_pessoa.Cidade); printf("CEP : %d \n", Registro_de_pessoas[j].Endereco_pessoa.CEP); printf("Estado : %s \n", Registro_de_pessoas[j].Endereco_pessoa.Estado); printf("Pais : %s \n", Registro_de_pessoas[j].Endereco_pessoa.Pais); } } } if (Escolha == 03 || Escolha == 3){ int Dia_requisitado, Mes_requisitado, Ano_requisitado; int k; scanf("%d/%d/%d", &Dia_requisitado, &Mes_requisitado, &Ano_requisitado); for (k = 0; k < 100; k ++){ if (Dia_requisitado == Registro_de_pessoas[k].Nascimento_pessoa.Dia && Mes_requisitado == Registro_de_pessoas[k].Nascimento_pessoa.Mes && Ano_requisitado == Registro_de_pessoas[k].Nascimento_pessoa.Ano); printf(":: Data de nascimento encontrada :: \n"); printf("\n"); printf(":: Exibindo informações :: \n"); printf("\n"); printf("Nome : %s \n", Registro_de_pessoas[k].Nome); printf("E-mail : %s \n", Registro_de_pessoas[k].Email); printf("Nascimento : %d / %d / %d \n", Registro_de_pessoas[k].Nascimento_pessoa.Dia, Registro_de_pessoas[k].Nascimento_pessoa.Mes, Registro_de_pessoas[k].Nascimento_pessoa.Ano); printf("Telefone : %d %d",Registro_de_pessoas[k].Telefone_pessoa.DDD, Registro_de_pessoas[k].Telefone_pessoa.Numero); printf("\n"); printf(":: Dados do endereço :: \n"); printf("\n"); printf("Rua: %s \n", Registro_de_pessoas[k].Endereco_pessoa.Rua); printf("Numero da residencia : %d \n", Registro_de_pessoas[k].Endereco_pessoa.Numero); printf("Bairro : %s \n", Registro_de_pessoas[k].Endereco_pessoa.Bairro); printf("Cidade : %s \n", Registro_de_pessoas[k].Endereco_pessoa.Cidade); printf("CEP : %d \n", Registro_de_pessoas[k].Endereco_pessoa.CEP); printf("Estado : %s \n", Registro_de_pessoas[k].Endereco_pessoa.Estado); printf("Pais : %s \n", Registro_de_pessoas[k].Endereco_pessoa.Pais); } } } }
the_stack_data/68899.c
#include <stdbool.h> #include <string.h> bool backTracking(char* bottom, int bottomSize, int index, char* nextbottom, int nextbottomSize, int (*triangle)[7][7]) { if (bottomSize == 1) return true; if (nextbottomSize == bottomSize - 1) { char next[8] = {0}, newbottom[8] = {0}; strcpy(newbottom, nextbottom); return backTracking(newbottom, nextbottomSize, 0, next, 0, triangle); } for (int i = 0; i < 7; ++i) { if (triangle[bottom[index] - 'A'][bottom[index + 1] - 'A'][i] == 1) { nextbottom[nextbottomSize] = 'A' + i; if (backTracking(bottom, bottomSize, index + 1, nextbottom, nextbottomSize + 1, triangle)) return true; } } return false; } bool pyramidTransition(char* bottom, char** allowed, int allowedSize) { int triangle[7][7][7] = {{{0}}}; for (int i = 0; i < allowedSize; ++i) triangle[allowed[i][0] - 'A'][allowed[i][1] - 'A'][allowed[i][2] - 'A'] = 1; char nextbottom[8]; return backTracking(bottom, strlen(bottom), 0, nextbottom, 0, triangle); }
the_stack_data/86074495.c
/* * Title: There are 9,870 people in a town whose population increases by 10% each year. * Description: Write a loop that displays the annual population and determines how many years (count_years) it will take for the population to surpass 30,000. * Assignment: Page 261 Programming Project 1 * Link to assignment: Book * * Programmer: Sebastian Livoni Larsen * Date completed: September 21, 2021 * Instructor: Kurt Nørmark * Class: AAL E21 */ #include <stdio.h> #define POPULATION 9870 #define MAX_POPULATION 30000 #define ANNUAL_INCREASE_IN_DECIMAL 1.1 int main(void) { int current_population = POPULATION, count_years = 0; while (current_population <= MAX_POPULATION) { current_population *= ANNUAL_INCREASE_IN_DECIMAL; count_years += 1; } printf("It will take %d years to surpass a population of %d people with an increase of %.0lf procent each year\n", count_years, MAX_POPULATION, ANNUAL_INCREASE_IN_DECIMAL * 10 - 1); }
the_stack_data/117626.c
// Copyright © 2020 CSJ From SJ Project.All rights reserved. // Keep your hand shining plz #include <stdio.h> #include <stdlib.h> int target, counter, result = 1; int calc() { for (counter = 1; counter <= target; counter++) { result = result * counter; } } int main() { system("color 0a"); system("mode 55, 10"); printf("Please input a number to calculation it's factorial :\n"); scanf("%d", &target); calc(); printf("The answer of %d's fatorial is %d!\n===Please enter any key to continue.===", target, result); system("pause > nul"); }
the_stack_data/130160.c
#include <stdio.h> #include <stdlib.h> #include <math.h> //#include <complex.h> #include <string.h> //#include <malloc.h> /* miscellaneous constants */ #define VNULL ((VEC *)NULL) #define MNULL ((MAT *)NULL) /* macros that also check types and sets pointers to NULL */ #define M_FREE(mat) (m_free(mat), (mat)=(MAT *)NULL) #define V_FREE(vec) (v_free(vec), (vec)=(VEC *)NULL) #define MACHEPS 2.22045e-16 #define m_output(mat) m_foutput(stdout, mat) static const char *format = "%14.9g "; #ifndef ANSI_C #define ANSI_C 1 #endif #define SEGMENTED #ifndef THREADSAFE /* for use as a shared library */ #define THREADSAFE 1 #endif #define TYPE_MAT mem_bytes(0, 0, sizeof(MAT)) #define TYPE_VEC mem_bytes(0, 0, sizeof(VEC)) #define v_chk_idx(x, i) ((i)>=0 && (i)<(x)->dim) #define v_get_val(x, i) (v_chk_idx(x, i) ? (x)->ve[(i)] : \ (printf("Error!\n"))) #define v_entry(x, i) v_get_val(x, i) #define v_set_val(x, i, val) (x->ve[i] = val) #define m_set_val(A, i, j, val) ((A)->me[(i)][(j)] = (val)) #define m_add_val(A, i, j, val) ((A)->me[(i)][(j)] += (val)) #define m_chk_idx(A, i, j) ((i)>=0 && (i)<(A)->m && (j)>=0 && (j)<=(A)->n) #define m_get_val(A, i, j) (m_chk_idx(A, i, j) ? \ (A)->me[(i)][(j)] : (printf("Error!"))) #define m_entry(A, i, j) m_get_val(A, i, j) #define printfc(c) printf("%f%c%fi\n", c.real, (c.imag>=0.0f)? '+':'\0', c.imag) /* standard copy & zero functions */ #define MEM_COPY(from, to, size) memmove((to), (from), (size)) #define MEM_ZERO(where, size) memset((where), '\0', (size)) /* allocate one object of given type */ #define NEW(type) ((type *)calloc((size_t)1, (size_t)sizeof(type))) /* allocate num objects of given type */ #define NEW_A(num, type) ((type *)calloc((size_t)(num), (size_t)sizeof(type))) #define MEMCOPY(from, to, n_items, type) \ MEM_COPY((char *)(from), (char *)(to), (unsigned)(n_items)*sizeof(type)) /* type independent min and max operations */ #ifndef max #define max(a, b) ((a) > (b) ? (a) : (b)) #endif /* max */ #ifndef min #define min(a, b) ((a) > (b) ? (b) : (a)) #endif /* min */ #ifndef THREADSAFE #define MEM_STAT_REG(var, type) mem_stat_reg_list((void **)&(var), type, 0, __FILE__, __LINE__) #else #define MEM_STAT_REG(var, type) #endif /* matrix definition */ typedef struct { unsigned int m, n; unsigned int max_m, max_n, max_size; double **me, *base; /* base is base of alloc'd mem */ } MAT; /* vector definition */ typedef struct { unsigned int dim, max_dim; double *ve; } VEC; /* complex number definition */ typedef struct { double real, imag; } CMPLX; /******************************Matrix Functions******************************/ /* m_add -- matrix addition -- may be in-situ */ #ifndef ANSI_C MAT *m_add(mat1, mat2, out) MAT *mat1, *mat2, *out; #else MAT *m_add(const MAT *mat1, const MAT *mat2, MAT *out) #endif { unsigned int m, n, i, j; m = mat1->m; n = mat1->n; for(i=0; i<m; i++ ) { for(j = 0; j < n; j++) out->me[i][j] = mat1->me[i][j]+mat2->me[i][j]; } return (out); } /* m_sub -- matrix subtraction -- may be in-situ */ #ifndef ANSI_C MAT *m_sub(mat1, mat2, out) MAT *mat1, *mat2, *out; #else MAT *m_sub(const MAT *mat1, const MAT *mat2, MAT *out) #endif { unsigned int m, n, i, j; m = mat1->m; n = mat1->n; for(i=0; i<m; i++) { for(j=0; j<n; j++) out->me[i][j] = mat1->me[i][j]-mat2->me[i][j]; } return (out); } /* m_get -- gets an mxn matrix (in MAT form) by dynamic memory allocation -- normally ALL matrices should be obtained this way -- if either m or n is negative this will raise an error -- note that 0 x n and m x 0 matrices can be created */ MAT *m_get(int m, int n) { MAT *matrix = malloc(sizeof *matrix); int i, j; if(m < 0 || n < 0) printf("The matrix dimensions must be positive!\n"); if((matrix=NEW(MAT)) == (MAT *)NULL) printf("The matrix is NULL!\n"); matrix->m = m; matrix->n = matrix->max_n = n; matrix->max_m = m; matrix->max_size = m*n; matrix->me = (double **)malloc(m * sizeof(double*)); for(int i = 0; i < m; i++) matrix->me[i] = (double *)malloc(n * sizeof(double)); return (matrix); } /* m_resize -- returns the matrix A of size new_m x new_n; A is zeroed -- if A == NULL on entry then the effect is equivalent to m_get() */ MAT *m_resize(MAT *A, int new_m, int new_n) { int i; int new_max_m, new_max_n, old_m, old_n, add_rows; double **tmp; if(new_m < 0 || new_n < 0) printf("The size must be positive!"); if(!A) return m_get(new_m, new_n); // nothing was changed if(new_m == A->m && new_n == A->n) return A; old_m = A->m; old_n = A->n; add_rows = new_m-old_m; if( new_m > A->max_m ) { // re-allocate A->me tmp = realloc(A->me, sizeof *A->me * (new_m)); if(tmp) { A->me = tmp; for(i = 0; i < add_rows; i++) { A->me[old_m + i] = malloc( sizeof *A->me[old_m + i] * old_n ); } } if(new_n > A->max_n) { double *tmp; for(int i = 0; i < old_m; i++) { tmp = realloc(A->me[i], sizeof *A->me[i] * (new_n)); if(tmp) { A->me[i] = tmp; } } } else if(new_n < A->max_n) { double *tmp; for(int i = 0; i < old_n; i++) { tmp = realloc(A->me[i], sizeof *A->me[i] * (new_n)); if(tmp) A->me[i] = tmp; } } } else if(new_m < A->max_m) { int del_rows = old_m-new_m; double *tmp; for(int i = 1; i <= del_rows; i++) { free(A->me[old_m - i]); tmp = realloc(A->me, old_m - del_rows); if(tmp) A->me[i] = tmp; } if(new_n > A->max_n) { double *tmp; for(int i = 0; i < old_m; i++) { tmp = realloc( A->me[i], sizeof *A->me[i] * (new_n) ); if(tmp) { A->me[i] = tmp; } } } else if(new_n < A->max_n) { double *tmp; for(int i = 0; i < old_n; i++) { tmp = realloc(A->me[i], sizeof *A->me[i] * (new_n)); if(tmp) A->me[i] = tmp; } } } new_max_m = max(new_m, A->max_m); new_max_n = max(new_n, A->max_n); A->max_m = new_max_m; A->max_n = new_max_n; A->max_size = A->max_m*A->max_n; A->m = new_m; A->n = new_n; return A; } /* m_zero -- zero the matrix A */ #ifndef ANSI_C MAT *m_zero(A) MAT *A; #else MAT *m_zero(MAT *A) #endif { int i, j, A_m, A_n; double **A_me; A_m = A->m; A_n = A->n; A_me = A->me; for(i = 0; i < A_m; i++) for( j = 0; j < A_n; j++) A_me[i][j] = 0.0; return A; } /* __mltadd__ -- scalar multiply and add c.f. v_mltadd() */ #ifndef ANSI_C void __mltadd__(dp1, dp2, s, len) register double *dp1, *dp2; register double s; register int len; #else void __mltadd__(double *dp1, const double *dp2, double s, int len) #endif { register int i; #ifdef VUNROLL register int len4; len4 = len / 4; len = len % 4; for(i = 0; i < len4; i++) { dp1[4*i] += s*dp2[4*i]; dp1[4*i+1] += s*dp2[4*i+1]; dp1[4*i+2] += s*dp2[4*i+2]; dp1[4*i+3] += s*dp2[4*i+3]; } dp1 += 4*len4; dp2 += 4*len4; #endif for(i = 0; i < len; i++) dp1[i] += s*dp2[i]; } /* m_mlt -- matrix-matrix multiplication */ #ifndef ANSI_C MAT *m_mlt(A, B, OUT) MAT *A, *B, *OUT; #else MAT *m_mlt(const MAT *A, const MAT *B, MAT *OUT) #endif { unsigned int i, /* j, */ k, m, n, p; double **A_v, **B_v, *B_row, *OUT_row, sum, tmp; m = A->m; n = A->n; p = B->n; A_v = A->me; B_v = B->me; if(OUT==(MAT *)NULL || OUT->m != A->m || OUT->n != B->n) OUT = m_resize(OUT, A->m, B->n); m_zero(OUT); for(i=0; i<m; i++) for( k=0; k<n; k++) { if(A_v[i][k] != 0.0) __mltadd__(OUT->me[i], B_v[k], A_v[i][k], (int)p); } return OUT; } /* m_foutput -- prints a representation of the matrix a onto file/stream fp */ #ifndef ANSI_C void m_foutput(fp, a) FILE *fp; MAT *a; #else void m_foutput(FILE *fp, const MAT *a) #endif { unsigned int i, j, tmp; if( a == (MAT *)NULL ) { fprintf(fp, "Matrix: NULL\n"); return; } fprintf(fp, "Matrix: %d by %d\n", a->m, a->n); if(a->me == (double **)NULL) { fprintf(fp, "NULL\n"); return; } for(i = 0; i < a->m; i++) /* for each row... */ { fprintf(fp, "row %u: ", i); for(j = 0, tmp = 2; j < a->n; j++, tmp++) { /* for each col in row... */ fprintf(fp, format, a->me[i][j]); if(!(tmp % 5)) putc('\n', fp); } if(tmp % 5 != 1) putc('\n', fp); } } /* m_copy -- copies matrix into new area -- out(i0:m,j0:n) <- in(i0:m,j0:n) */ #ifndef ANSI_C MAT *m_copy(in, out) MAT *in, *out; #else MAT *m_copy(const MAT *in, MAT *out) #endif { unsigned int i0 = 0, j0 = 0; unsigned int i, j; if(in == out) return (out); if(out == MNULL || out->m < in->m || out->n < in->n ) out = m_resize(out, in->m, in->n); for(i=i0; i < in->m; i++) { MEM_COPY(&(in->me[i][j0]), &(out->me[i][j0]), (in->n - j0)*sizeof(double)); } return (out); } /* v_zero -- zero the vector x */ #ifndef ANSI_C VEC *v_zero(x) VEC *x; #else VEC *v_zero(VEC *x) #endif { for(int i = 0; i < x->dim; i++) x->ve[i] = 0.0; return x; } /* v_get -- gets a VEC of dimension 'size' -- Note: initialized to zero */ #ifndef ANSI_C VEC *v_get(size) int size; #else VEC *v_get(int size) #endif { VEC *vector = malloc(sizeof *vector); int i, j; vector->dim = vector->max_dim = size; if(size < 0) printf("The vector dimension must be positive!\n"); if((vector->ve = NEW_A(size, double)) == (double *)NULL ) { free(vector); } else { vector->ve = (double *)malloc(size * sizeof(double)); } return (vector); } /* v_resize -- returns the vector x with dim new_dim -- x is set to the zero vector */ #ifndef ANSI_C VEC *v_resize(x, new_dim) VEC *x; int new_dim; #else VEC *v_resize(VEC *x, int new_dim) #endif { double *ptr; if(!x) return v_get(new_dim); /* nothing is changed */ if(new_dim == x->dim) return x; if( x->max_dim == 0 ) /* assume that it's from sub_vec */ return v_get(new_dim); ptr = x->ve; if(new_dim > x->max_dim) { ptr = realloc(ptr, new_dim * sizeof *ptr); } if( new_dim > x->dim ) { for(int i = 1; i < (new_dim - x->dim); i++) x->ve[new_dim-i] = 0.0; } else if(new_dim < x->dim) { ptr = realloc(ptr, new_dim * sizeof *ptr); } x->dim = new_dim; return x; } /* set_col -- sets column of matrix to values given in vec (in situ) -- that is, mat(i0:lim,col) <- vec(i0:lim) */ #ifndef ANSI_C MAT *set_col(mat, col, vec) MAT *mat; VEC *vec; unsigned int col; #else MAT *set_col(MAT *mat, unsigned int col, const VEC *vec/*, unsigned int i0*/) #endif { unsigned int i, lim, i0; lim = min(mat->m, vec->dim); for(i=i0; i<lim; i++) mat->me[i][col] = vec->ve[i]; return (mat); } /* m_free -- returns MAT & associated memory back to memory heap */ #ifndef ANSI_C int m_free(mat) MAT *mat; #else int m_free(MAT *mat) #endif { #ifdef SEGMENTED int i; #endif if(mat == (MAT *)NULL || (int)(mat->m) < 0 || (int)(mat->n) < 0) return (-1); #ifndef SEGMENTED if(mat->base != (double *)NULL) { mat->base = (double *)malloc(mat->max_m*mat->max_n * sizeof(double)); free((char *)(mat->base)); } #else for( i = 0; i < mat->max_m; i++ ) if(mat->me[i] != (double *)NULL) { mat->me[i] = (double *)malloc(mat->max_n * sizeof(double)); free((char *)(mat->me[i])); } #endif if(mat->me != (double **)NULL) { mat->me = (double **)malloc(mat->max_m * sizeof(double*)); free((char *)(mat->me)); } mat = malloc(sizeof *mat); free((char *)mat); return (0); } /* v_free -- returns VEC & associated memory back to memory heap */ #ifndef ANSI_C int v_free(vec) VEC *vec; #else int v_free(VEC *vec) #endif { if( vec==(VEC *)NULL || (int)(vec->dim) < 0 ) /* don't trust it */ return (-1); if( vec->ve == (double *)NULL ) { vec = malloc(sizeof *vec); free((char *)vec); } else { vec = malloc(sizeof *vec); vec->ve = (double *)malloc(vec->max_dim*sizeof(double)); free((char *)vec->ve); free((char *)vec); } return (0); } /* v_copy -- copies vector into new area -- out(i0:dim) <- in(i0:dim) */ #ifndef ANSI_C VEC *v_copy(in, out) VEC *in, *out; #else VEC *v_copy(const VEC *in, VEC *out) #endif { unsigned int i0 = 0; if(in == out) return (out); if(out == VNULL || out->dim < in->dim) out = v_resize(out, in->dim); MEM_COPY(&(in->ve[i0]), &(out->ve[i0]), (in->dim - i0)*sizeof(double)); return (out); } /* __ip__ -- inner product */ #ifndef ANSI_C double __ip__(dp1, dp2, len) register double *dp1, *dp2; int len; #else double __ip__(const double *dp1, const double *dp2, int len) #endif { #ifdef VUNROLL register int len4; register double sum1, sum2, sum3; #endif register int i; register double sum; sum = 0.0; #ifdef VUNROLL sum1 = sum2 = sum3 = 0.0; len4 = len / 4; len = len % 4; for(i = 0; i < len4; i++) { sum += dp1[4*i]*dp2[4*i]; sum1 += dp1[4*i+1]*dp2[4*i+1]; sum2 += dp1[4*i+2]*dp2[4*i+2]; sum3 += dp1[4*i+3]*dp2[4*i+3]; } sum += sum1 + sum2 + sum3; dp1 += 4*len4; dp2 += 4*len4; #endif for(i = 0; i < len; i++) sum += dp1[i]*dp2[i]; return sum; } /* m_inverse -- returns inverse of A, provided A is not too rank deficient -- uses Gauss - Jordan */ #ifndef ANSI_C MAT *m_inverse(A, out) MAT *A, *out; #else MAT *m_inverse(const MAT *A, MAT *out) #endif { int i, j, k, matsize; float temp; MAT *AUX = m_copy(A, MNULL); matsize = AUX->m; // automatically initialize the unit matrix, e.g. for(i = 0; i < matsize; i++) { for(j = 0; j < matsize; j++) { if(i == j) { out->me[i][j]=1; } else out->me[i][j]=0; } } /*---------------Logic starts here------------------*/ /* procedure to make the matrix A to unit matrix --by some row operations,and the same row operations of --Unit mat. I gives the inverse of matrix A --'temp' stores the A[k][k] value so that A[k][k] will not change --during the operation A[i][j]/=A[k][k] when i=j=k --*/ for(k = 0; k < matsize; k++) { // it performs the following row operations to make A to unit matrix // R0=R0/A[0][0],similarly for I also R0=R0/A[0][0] // R1=R1-R0*A[1][0] similarly for I // R2=R2-R0*A[2][0] temp = AUX->me[k][k]; for(j = 0; j < matsize; j++) { AUX->me[k][j] /= temp; out->me[k][j] /= temp; } for(i = 0; i < matsize; i++) { // R1=R1/A[1][1] // R0=R0-R1*A[0][1] // R2=R2-R1*A[2][1] temp = AUX->me[i][k]; for(j = 0; j < matsize; j++) { if(i == k) break; // R2=R2/A[2][2] // R0=R0-R2*A[0][2] // R1=R1-R2*A[1][2] AUX->me[i][j] -= AUX->me[k][j]*temp; out->me[i][j] -= out->me[k][j]*temp; } } } /*---------------Logic ends here--------------------*/ return out; } /* mat_id -- set A to being closest to identity matrix as possible -- i.e. A[i][j] == 1 if i == j and 0 otherwise */ #ifndef ANSI_C MAT *m_ident(A) MAT *A; #else MAT *m_ident(MAT *A) #endif { int i, size; m_zero(A); size = min(A->m, A->n); for(i = 0; i < size; i++) A->me[i][i] = 1.0; return A; } /* _m_pow -- computes integer powers of a square matrix A, A^p -- uses tmp as temporary workspace */ #ifndef ANSI_C MAT *_m_pow(A, p, tmp, out) MAT *A, *tmp, *out; int p; #else MAT *_m_pow(const MAT *A, int p, MAT *tmp, MAT *out) #endif { int it_cnt, k, max_bit; #define Z(k) (((k) & 1) ? tmp : out) out = m_resize(out, A->m, A->n); tmp = m_resize(tmp, A->m, A->n); if(p == 0) out = m_ident(out); else if(p > 0) { it_cnt = 1; for(max_bit = 0; ; max_bit++) if((p >> (max_bit+1)) == 0) break; tmp = m_copy(A, tmp); for(k = 0; k < max_bit; k++) { m_mlt(Z(it_cnt), Z(it_cnt), Z(it_cnt+1)); it_cnt++; if(p & (1 << (max_bit-1))) { m_mlt(A, Z(it_cnt), Z(it_cnt+1)); it_cnt++; } p <<= 1; } if(it_cnt & 1) out = m_copy(Z(it_cnt), out); } return out; #undef Z } /* m_same_elements -- fills matrix with one's */ #ifndef ANSI_C MAT *m_same_elements(A, u) MAT *A; double u; #else MAT *m_same_elements(MAT *A, double u) #endif { int i, j; for(i = 0; i < A->m; i++) for ( j = 0; j < A->n; j++ ) A->me[i][j] = u; return A; } /* m_pow -- computes integer powers of a square matrix A, A^p */ #ifndef ANSI_C MAT *m_pow(A, p, out) MAT *A, *out; int p; #else MAT *m_pow(const MAT *A, int p, MAT *out) #endif { static MAT *wkspace=MNULL, *tmp=MNULL; wkspace = m_resize(wkspace, A->m, A->n); MEM_STAT_REG(wkspace, TYPE_MAT); if(p < 0) { tmp = m_resize(tmp, A->m, A->n); MEM_STAT_REG(tmp, TYPE_MAT); tmp = m_inverse(A, tmp); out = _m_pow(tmp, -p, wkspace, out); } else out = _m_pow(A, p, wkspace, out); #ifdef THREADSAFE M_FREE(wkspace); M_FREE(tmp); #endif return out; } /* get_col -- gets a specified column of a matrix and retruns it as a vector */ #ifndef ANSI_C VEC *get_col(mat, col, vec) unsigned int col; MAT *mat; VEC *vec; #else VEC *get_col(const MAT *mat, unsigned int col, VEC *vec) #endif { unsigned int i; if(vec == (VEC *)NULL || vec->dim < mat->m) vec = v_resize(vec, mat->m); for(i = 0; i < mat->m; i++) vec->ve[i] = mat->me[i][col]; return (vec); } /* _v_copy -- copies vector into new area -- out(i0:dim) <- in(i0:dim) */ #ifndef ANSI_C VEC *_v_copy(in, out, i0) VEC *in, *out; unsigned int i0; #else VEC *_v_copy(const VEC *in, VEC *out, unsigned int i0) #endif { if(in == out) return (out); if(out==VNULL || out->dim < in->dim) out = v_resize(out, in->dim); MEM_COPY(&(in->ve[i0]), &(out->ve[i0]), (in->dim - i0)*sizeof(double)); return (out); } /* _in_prod -- inner product of two vectors from i0 downwards -- that is, returns a(i0:dim)^T.b(i0:dim) */ #ifndef ANSI_C double _in_prod(a, b, i0) VEC *a, *b; unsigned int i0; #else double _in_prod(const VEC *a, const VEC *b, unsigned int i0) #endif { unsigned int limit; return __ip__(&(a->ve[i0]), &(b->ve[i0]), (int)(limit-i0)); } /* hhvec -- calulates Householder vector to eliminate all entries after the i0 entry of the vector vec. It is returned as out. May be in-situ */ #ifndef ANSI_C VEC *hhvec(vec, i0, beta, out, newval) VEC *vec, *out; unsigned int i0; double *beta, *newval; #else VEC *hhvec(const VEC *vec, unsigned int i0, double *beta, VEC *out, double *newval) #endif { double norm, temp; out = _v_copy(vec, out, i0); temp = (double)_in_prod(out, out, i0); norm = sqrt(temp); if(norm <= 0.0) { *beta = 0.0; return (out); } *beta = 1.0/(norm * (norm+fabs(out->ve[i0]))); if(out->ve[i0] > 0.0) *newval = -norm; else *newval = norm; out->ve[i0] -= *newval; return (out); } /* _hhtrcols -- transform a matrix by a Householder vector by columns starting at row i0 from column j0 -- that is, M(i0:m,j0:n) <- (I-beta.hh(i0:m).hh(i0:m)^T)M(i0:m,j0:n) -- in-situ -- scratch vector w passed as argument -- raises error if w == NULL */ #ifndef ANSI_C MAT *_hhtrcols(M, i0, j0, hh, beta, w) MAT *M; unsigned int i0, j0; VEC *hh; double beta; VEC *w; #else MAT *_hhtrcols(MAT *M, unsigned int i0, unsigned int j0, const VEC *hh, double beta, VEC *w) #endif { int i; if(beta == 0.0) return (M); if(w->dim < M->n) w = v_resize(w, M->n); v_zero(w); for(i = i0; i < M->m; i++) if(hh->ve[i] != 0.0) __mltadd__(&(w->ve[j0]), &(M->me[i][j0]), hh->ve[i], (int)(M->n-j0)); for(i = i0; i < M->m; i++) if(hh->ve[i] != 0.0) __mltadd__(&(M->me[i][j0]), &(w->ve[j0]), -beta*hh->ve[i], (int)(M->n-j0)); return (M); } /* hhtrrows -- transform a matrix by a Householder vector by rows starting at row i0 from column j0 -- in-situ -- that is, M(i0:m,j0:n) <- M(i0:m,j0:n)(I-beta.hh(j0:n).hh(j0:n)^T) */ #ifndef ANSI_C MAT *hhtrrows(M, i0, j0, hh, beta) MAT *M; unsigned int i0, j0; VEC *hh; double beta; #else MAT *hhtrrows(MAT *M, unsigned int i0, unsigned int j0, const VEC *hh, double beta) #endif { double ip, scale; int i; if(beta == 0.0) return (M); /* for each row ... */ for(i = i0; i < M->m; i++) { /* compute inner product */ ip = __ip__(&(M->me[i][j0]), &(hh->ve[j0]), (int)(M->n-j0)); scale = beta*ip; if(scale == 0.0) continue; /* do operation */ __mltadd__(&(M->me[i][j0]), &(hh->ve[j0]), -scale, (int)(M->n-j0)); } return (M); } /* Hfactor -- compute Hessenberg factorization in compact form. -- factorization performed in situ */ #ifndef ANSI_C MAT *Hfactor(A, diag, beta) MAT *A; VEC *diag, *beta; #else MAT *Hfactor(MAT *A, VEC *diag, VEC *beta) #endif { static VEC *hh = VNULL, *w = VNULL; int k, limit; double b; limit = A->m - 1; hh = v_resize(hh, A->m); w = v_resize(w, A->n); MEM_STAT_REG(hh, TYPE_VEC); MEM_STAT_REG(w, TYPE_VEC); for(k = 0; k < limit; k++) { /* compute the Householder vector hh */ get_col(A, (unsigned int)k, hh); hhvec(hh, k+1, &beta->ve[k], hh, &A->me[k+1][k]); v_set_val(diag, k, v_entry(hh, k+1)); /* apply Householder operation symmetrically to A */ b = v_entry(beta, k); _hhtrcols(A, k+1, k+1, hh, b, w); hhtrrows(A, 0, k+1, hh, b); } #ifdef THREADSAFE V_FREE(hh); V_FREE(w); #endif return (A); } /* hhtrvec -- apply Householder transformation to vector -- that is, out <- (I-beta.hh(i0:n).hh(i0:n)^T).in -- may be in-situ */ #ifndef ANSI_C VEC *hhtrvec(hh, beta, i0, in, out) VEC *hh, *in, *out; /* hh = Householder vector */ unsigned int i0; double beta; #else VEC *hhtrvec(const VEC *hh, double beta, unsigned int i0, const VEC *in, VEC *out) #endif { double scale, temp; temp = (double)_in_prod(hh, in, i0); scale = beta*temp; out = v_copy(in, out); __mltadd__(&(out->ve[i0]), &(hh->ve[i0]), -scale, (int)(in->dim-i0)); return (out); } /* makeHQ -- construct the Hessenberg orthogonalising matrix Q; -- i.e. Hess M = Q.M.Q' */ #ifndef ANSI_C MAT *makeHQ(H, diag, beta, Qout) MAT *H, *Qout; VEC *diag, *beta; #else MAT *makeHQ(MAT *H, VEC *diag, VEC *beta, MAT *Qout) #endif { int i, j, limit; static VEC *tmp1 = VNULL, *tmp2 = VNULL; Qout = m_resize(Qout, H->m, H->m); tmp1 = v_resize(tmp1, H->m); tmp2 = v_resize(tmp2, H->m); MEM_STAT_REG(tmp1, TYPE_VEC); MEM_STAT_REG(tmp2, TYPE_VEC); for(i = 0; i < H->m; i++) { /* tmp1 = i'th basis vector */ for(j = 0; j < H->m; j++) v_set_val(tmp1, j, 0.0); v_set_val(tmp1, i, 1.0); /* apply H/h transforms in reverse order */ for(j = limit-1; j >= 0; j--) { get_col(H, (unsigned int)j, tmp2); v_set_val(tmp2, j+1, v_entry(diag, j)); hhtrvec(tmp2, beta->ve[j], j+1, tmp1, tmp1); } /* insert into Qout */ set_col(Qout, (unsigned int)i, tmp1); } #ifdef THREADSAFE V_FREE(tmp1); V_FREE(tmp2); #endif return (Qout); } /* makeH -- construct actual Hessenberg matrix */ #ifndef ANSI_C MAT *makeH(H, Hout) MAT *H, *Hout; #else MAT *makeH(const MAT *H, MAT *Hout) #endif { int i, j, limit; Hout = m_resize(Hout, H->m, H->m); Hout = m_copy(H, Hout); limit = H->m; for(i = 1; i < limit; i++) for(j = 0; j < i-1; j++) m_set_val(Hout, i, j, 0.0); return (Hout); } /* rot_cols -- postmultiply mat by givens rotation described by c, s */ #ifndef ANSI_C MAT *rot_cols(mat, i, k, c, s, out) MAT *mat, *out; unsigned int i, k; double c, s; #else MAT *rot_cols(const MAT *mat, unsigned int i, unsigned int k, double c, double s, MAT *out) #endif { unsigned int j; double temp; if(mat != out) out = m_copy(mat, m_resize(out, mat->m, mat->n)); for(j=0; j<mat->m; j++) { temp = c*m_entry(out, j, i) + s*m_entry(out, j, k); m_set_val(out, j, k, -s*m_entry(out, j, i) + c*m_entry(out, j, k)); m_set_val(out, j, i, temp); } return (out); } /* rot_rows -- premultiply mat by givens rotation described by c, s */ #ifndef ANSI_C MAT *rot_rows(mat, i, k, c, s, out) MAT *mat, *out; unsigned int i, k; double c, s; #else MAT *rot_rows(const MAT *mat, unsigned int i, unsigned int k, double c, double s, MAT *out) #endif { unsigned int j; double temp; if(mat != out) out = m_copy(mat, m_resize(out, mat->m, mat->n)); for(j=0; j<mat->n; j++) { temp = c*m_entry(out, i, j) + s*m_entry(out, k, j); m_set_val(out, k, j, -s*m_entry(out, i, j) + c*m_entry(out, k, j)); m_set_val(out, i, j, temp); } return (out); } /* hhldr3 -- computes */ #ifndef ANSI_C static void hhldr3(x, y, z, nu1, beta, newval) double x, y, z; double *nu1, *beta, *newval; #else static void hhldr3(double x, double y, double z, double *nu1, double *beta, double *newval) #endif { double alpha; if(x >= 0.0) alpha = sqrt(x*x+y*y+z*z); else alpha = -sqrt(x*x+y*y+z*z); *nu1 = x + alpha; *beta = 1.0/(alpha*(*nu1)); *newval = alpha; } /*hhldr3rows */ #ifndef ANSI_C static void hhldr3rows(A, k, i0, beta, nu1, nu2, nu3) MAT *A; int k, i0; double beta, nu1, nu2, nu3; #else static void hhldr3rows(MAT *A, int k, int i0, double beta, double nu1, double nu2, double nu3) #endif { double **A_me, ip, prod; int i, m; A_me = A->me; m = A->m; i0 = min(i0, m-1); for(i = 0; i <= i0; i++) { ip = nu1*m_entry(A, i, k) + nu2*m_entry(A, i, k+1)+nu3 * m_entry(A, i, k+2); prod = ip*beta; m_add_val(A, i, k, -prod*nu1); m_add_val(A, i, k+1, -prod*nu2); m_add_val(A, i, k+2, -prod*nu3); } } /* givens -- returns c,s parameters for Givens rotation to eliminate y in the vector [ x y ]' */ #ifndef ANSI_C void givens(x, y, c, s) double x, y; double *c, *s; #else void givens(double x, double y, double *c, double *s) #endif { double norm; norm = sqrt(x*x+y*y); if(norm == 0.0) { *c = 1.0; *s = 0.0; } /* identity */ else { *c = x/norm; *s = y/norm; } } /* schur -- computes the Schur decomposition of the matrix A in situ -- optionally, gives Q matrix such that Q^T.A.Q is upper triangular -- returns upper triangular Schur matrix */ #ifndef ANSI_C MAT *schur(A, Q) MAT *A, *Q; #else MAT *schur(MAT *A, MAT *Q) #endif { int i, j, iter, k, k_min, k_max, k_tmp, n, split; double beta2, c, discrim, dummy, nu1, s, t, tmp, x, y, z; double **A_me; double sqrt_macheps; static VEC *diag=VNULL, *beta=VNULL; n = A->n; diag = v_resize(diag, A->n); beta = v_resize(beta, A->n); MEM_STAT_REG(diag, TYPE_VEC); MEM_STAT_REG(beta, TYPE_VEC); /* compute Hessenberg form */ Hfactor(A, diag, beta); /* save Q if necessary */ if(Q) Q = makeHQ(A, diag, beta, Q); makeH(A, A); sqrt_macheps = sqrt(MACHEPS); k_min = 0; A_me = A->me; while(k_min < n) { double a00, a01, a10, a11; double scale, t, numer, denom; /* find k_max to suit: submatrix k_min..k_max should be irreducible */ k_max = n-1; for(k = k_min; k < k_max; k++) if(m_entry(A, k+1, k) == 0.0) { k_max = k; break; } if(k_max <= k_min) { k_min = k_max + 1; continue; /* outer loop */ } /* check to see if we have a 2 x 2 block with complex eigenvalues */ if(k_max == k_min + 1) { a00 = m_entry(A, k_min, k_min); a01 = m_entry(A, k_min, k_max); a10 = m_entry(A, k_max, k_min); a11 = m_entry(A, k_max, k_max); tmp = a00 - a11; discrim = tmp*tmp + 4*a01*a10; if(discrim < 0.0) { /* yes -- e-vals are complex -- put 2 x 2 block in form [a b; c a]; then eigenvalues have real part a & imag part sqrt(|bc|) */ numer = - tmp; denom = (a01+a10 >= 0.0) ? (a01+a10) + sqrt((a01+a10)*(a01+a10)+tmp*tmp) : (a01+a10) - sqrt((a01+a10)*(a01+a10)+tmp*tmp); if(denom != 0.0) { /* t = s/c = numer/denom */ t = numer/denom; scale = c = 1.0/sqrt(1+t*t); s = c*t; } else { c = 1.0; s = 0.0; } rot_cols(A, k_min, k_max, c, s, A); rot_rows(A, k_min, k_max, c, s, A); if(Q != MNULL) rot_cols(Q, k_min, k_max, c, s, Q); k_min = k_max + 1; continue; } else { /* discrim >= 0; i.e. block has two real eigenvalues */ /* no -- e-vals are not complex; split 2 x 2 block and continue */ /* s/c = numer/denom */ numer = (tmp >= 0.0) ? - tmp - sqrt(discrim) : - tmp + sqrt(discrim); denom = 2*a01; if(fabs(numer) < fabs(denom)) { /* t = s/c = numer/denom */ t = numer/denom; scale = c = 1.0/sqrt(1+t*t); s = c*t; } else if(numer != 0.0) { /* t = c/s = denom/numer */ t = denom/numer; scale = 1.0/sqrt(1+t*t); c = fabs(t)*scale; s = (t >= 0.0) ? scale : -scale; } else /* numer == denom == 0 */ { c = 0.0; s = 1.0; } rot_cols(A, k_min, k_max, c, s, A); rot_rows(A, k_min, k_max, c, s, A); if(Q != MNULL) rot_cols(Q, k_min, k_max, c, s, Q); k_min = k_max + 1; /* go to next block */ continue; } } /* now have r x r block with r >= 2: apply Francis QR step until block splits */ split = 0; iter = 0; while(!split) { iter++; /* set up Wilkinson/Francis complex shift */ k_tmp = k_max - 1; a00 = m_entry(A, k_tmp, k_tmp); a01 = m_entry(A, k_tmp, k_max); a10 = m_entry(A, k_max, k_tmp); a11 = m_entry(A, k_max, k_max); /* treat degenerate cases differently -- if there are still no splits after five iterations and the bottom 2 x 2 looks degenerate, force it to split */ #ifdef DEBUG printf("# schur: bottom 2 x 2 = [%lg, %lg; %lg, %lg]\n", a00, a01, a10, a11); #endif if(iter >= 5 && fabs(a00-a11) < sqrt_macheps*(fabs(a00)+fabs(a11)) && (fabs(a01) < sqrt_macheps*(fabs(a00)+fabs(a11)) || fabs(a10) < sqrt_macheps*(fabs(a00)+fabs(a11))) ) { if(fabs(a01) < sqrt_macheps*(fabs(a00)+fabs(a11))) m_set_val(A, k_tmp, k_max, 0.0); if(fabs(a10) < sqrt_macheps*(fabs(a00)+fabs(a11))) { m_set_val(A, k_max, k_tmp, 0.0); split = 1; continue; } } s = a00 + a11; t = a00*a11 - a01*a10; /* break loop if a 2 x 2 complex block */ if(k_max == k_min + 1 && s*s < 4.0*t) { split = 1; continue; } /* perturb shift if convergence is slow */ if((iter % 10) == 0) { s += iter*0.02; t += iter*0.02; } /* set up Householder transformations */ k_tmp = k_min + 1; a00 = m_entry(A, k_min, k_min); a01 = m_entry(A, k_min, k_tmp); a10 = m_entry(A, k_tmp, k_min); a11 = m_entry(A, k_tmp, k_tmp); x = a00*a00 + a01*a10 - s*a00 + t; y = a10*(a00+a11-s); if(k_min + 2 <= k_max) z = a10*A->me[k_min+2][k_tmp]; else z = 0.0; for(k = k_min; k <= k_max-1; k++) { if(k < k_max - 1) { hhldr3(x, y, z, &nu1, &beta2, &dummy); if(Q != MNULL) hhldr3rows(Q, k, n-1, beta2, nu1, y, z); } else { givens(x, y, &c, &s); rot_cols(A, k, k+1, c, s, A); rot_rows(A, k, k+1, c, s, A); if(Q) rot_cols(Q, k, k+1, c, s, Q); } x = m_entry(A, k+1, k); if(k <= k_max - 2) y = m_entry(A, k+2, k); else y = 0.0; if(k <= k_max - 3) z = m_entry(A, k+3, k); else z = 0.0; } for(k = k_min; k <= k_max-2; k++) { /* zero appropriate sub-diagonals */ m_set_val(A, k+2, k, 0.0); if(k < k_max-2) m_set_val(A, k+3, k, 0.0); } /* test to see if matrix should split */ for(k = k_min; k < k_max; k++) if(fabs(A_me[k+1][k]) < MACHEPS* (fabs(A_me[k][k])+fabs(A_me[k+1][k+1]))) { A_me[k+1][k] = 0.0; split = 1; } } } /* polish up A by zeroing strictly lower triangular elements and small sub-diagonal elements */ for(i = 0; i < A->m; i++) for(j = 0; j < i-1; j++) A_me[i][j] = 0.0; for(i = 0; i < A->m - 1; i++) if(fabs(A_me[i+1][i]) < MACHEPS* (fabs(A_me[i][i])+fabs(A_me[i+1][i+1]))) A_me[i+1][i] = 0.0; #ifdef THREADSAFE V_FREE(diag); V_FREE(beta); #endif return A; } /* schur_vals -- compute real & imaginary parts of eigenvalues -- assumes T contains a block upper triangular matrix as produced by schur() -- real parts stored in real_pt, imaginary parts in imag_pt */ #ifndef ANSI_C void schur_evals(T, real_pt, imag_pt) MAT *T; VEC *real_pt, *imag_pt; #else void schur_evals(MAT *T, VEC *real_pt, VEC *imag_pt) #endif { int i, n; double discrim, **T_me; double diff, sum, tmp; n = T->n; T_me = T->me; real_pt = v_resize(real_pt, (unsigned int)n); imag_pt = v_resize(imag_pt, (unsigned int)n); i = 0; while(i < n) { if(i < n-1 && T_me[i+1][i] != 0.0) { /* should be a complex eigenvalue */ sum = 0.5*(T_me[i][i]+T_me[i+1][i+1]); diff = 0.5*(T_me[i][i]-T_me[i+1][i+1]); discrim = diff*diff + T_me[i][i+1]*T_me[i+1][i]; if(discrim < 0.0) { /* yes -- complex e-vals */ real_pt->ve[i] = real_pt->ve[i+1] = sum; imag_pt->ve[i] = sqrt(-discrim); imag_pt->ve[i+1] = - imag_pt->ve[i]; } else { /* no -- actually both real */ tmp = sqrt(discrim); real_pt->ve[i] = sum + tmp; real_pt->ve[i+1] = sum - tmp; imag_pt->ve[i] = imag_pt->ve[i+1] = 0.0; } i += 2; } else { /* real eigenvalue */ real_pt->ve[i] = T_me[i][i]; imag_pt->ve[i] = 0.0; i++; } } } /* m_get_eigenvalues -- get the eigenvalues of a matrix A -- */ CMPLX *m_get_eigenvalues(MAT *A) { MAT *T = MNULL, *Q = MNULL; VEC *evals_re = VNULL, *evals_im = VNULL; CMPLX *z; Q = m_get(A->m, A->n); T = m_copy(A, MNULL); /* compute Schur form: A = Q.T.Q^T */ schur(T, Q); /* extract eigenvalues */ evals_re = v_get(A->m); evals_im = v_get(A->m); schur_evals(T, evals_re, evals_im); z = malloc(evals_re->dim*sizeof(CMPLX)); for(int i = 0; i < evals_re->dim; i++) { // z[i] = evals_re->ve[i] + I*evals_im->ve[i]; z[i].real = evals_re->ve[i]; z[i].imag = evals_im->ve[i]; } return z; } double cmplx_mag(double real, double imag) { return sqrt(real * real + imag * imag); } /* max_mag_eigenvalue -- extracts the magnitude of the maximum eigenvalue -- */ double max_mag_eigenvalue(CMPLX *z, int size) { double maximum = 0, aux; for(int c = 1; c < size; c++) { aux = cmplx_mag(z[c].real, z[c].imag); if(aux > maximum) { maximum = aux; } } return (double)maximum; } /* is_same_sign -- check if a has the same sign as b -- */ int is_same_sign(double a, double b) { if(((a >= 0) && (b >= 0)) || ((a <= 0) && (b <= 0))) return 1; else return 0; } /* y_k -- computes the output signal in the k-th sample -- */ double y_k(MAT *A, MAT *B, MAT *C, MAT *D, double u, int k, MAT *x0) { MAT *y = MNULL/* *U*/, *Ak = MNULL, *AUX = MNULL, *AUX2 = MNULL; MAT *AUX3 = MNULL, *AUX4 = MNULL, *AUX5 = MNULL; // U = m_get(A->m, A->n); // U = m_same_elements(U,u); // y = C * A.pow(k) * x0; Ak = m_get(A->m, A->n); Ak = m_pow(A, k, MNULL); AUX = m_get(A->m, A->n); AUX = m_mlt(C, Ak, MNULL); y = m_get(A->m, A->n); y = m_mlt(AUX, x0, MNULL); AUX2 = m_get(A->m, A->n); for(int m = 0; m <= (k - 1); m++) { // y += (C * A.pow(k - m - 1) * B * u) + D * u; Ak = m_pow(A, (k-m-1), MNULL); AUX = m_mlt(C, Ak, MNULL); AUX2 = m_mlt(AUX, B, MNULL); // AUX3 = m_mlt(AUX2, U, MNULL); // AUX4 = m_mlt(D, U, MNULL); AUX5 = m_add(AUX2, D, MNULL); y = m_add(y, AUX5, MNULL); } return y->me[0][0]*u; } /* peak_output -- computes the biggest peak value of a signal (Mp) -- */ void peak_output(MAT *A, MAT *B, MAT *C, MAT *D, MAT *x0, double *out, double yss, double u) { double greater; int i = 0; greater = fabs(y_k(A, B, C, D, u, i, x0)); while((fabs(y_k(A, B, C, D, u, i+1, x0)) >= fabs(yss))) { if(greater < fabs(y_k(A, B, C, D, u, i+1, x0))) { greater = fabs(y_k(A, B, C, D, u, i+1, x0)); out[1] = y_k(A, B, C, D, u, i+1, x0); out[0] = i+2; } if(!is_same_sign(yss, out[1])) { greater = 0; } i++; } } double y_ss(MAT *A, MAT *B, MAT *C, MAT *D, double u) { double yss; MAT *AUX, *AUX2, *AUX3, *AUX4, *AUX5; MAT *Id; // get the expression y_ss=(C(I-A)^(-1)B+D)u Id = m_get(A->m, A->n); Id = m_ident(Id); AUX = m_get(A->m, A->n); // Id - A AUX = m_sub(Id, A, MNULL); AUX2 = m_get(A->m, A->n); AUX2 = m_inverse(AUX, MNULL); AUX3 = m_get(A->m, A->n); AUX3 = m_mlt(C, AUX2, MNULL); AUX4 = m_get(A->m, A->n); AUX4 = m_mlt(AUX3, B, MNULL); AUX5 = m_get(A->m, A->n); AUX5 = m_add(AUX4, D, MNULL); yss = AUX5->me[0][0] * u; return yss; } double c_bar(double mp, double yss, double lambmax, int kp) { double cbar; cbar = (mp-yss)/(pow(lambmax, kp)); return cbar; } double log_b(double base, double x) { return (double) (log(x) / log(base)); } int k_bar(double lambdaMax, double p, double cbar, double yss, int order) { double k_ss, x; x = (p * yss) / (100 * cbar); k_ss = log_b(lambdaMax, x); return ceil(k_ss)+order; } double max_mag_eigenvalue2(MAT *A) { double maximum = 0, aux; CMPLX *z; z = m_get_eigenvalues(A); for(int i = 0; i < A->m; i++) { aux = cmplx_mag(z[i].real, z[i].imag); if(aux > maximum) { maximum = aux; } } return maximum; } int check_settling_time(MAT *A, MAT *B, MAT *C, MAT *D, MAT *x0, double u, double tsr, double p, double ts) { double peakV[2]; double yss, mp, lambMax, cbar, output; int kbar, kp, i; yss = y_ss(A, B, C, D, u); peak_output(A, B, C, D, x0, peakV, yss, u); mp = (double) peakV[1]; kp = (int) peakV[0]; lambMax = max_mag_eigenvalue2(A); printf("Mp=%f", mp); printf("yss=%f", yss); printf("lambMax=%f", lambMax); printf("kp=%d", kp); cbar = c_bar(mp, yss, lambMax, kp); kbar = k_bar(lambMax, p, cbar, yss, A->m); printf("cbar=%f", cbar); if(kbar * ts < tsr) { //printf("kbar=%f", kbar); return 1; } i = ceil(tsr / ts); while(i <= kbar) { output = y_k(A, B, C, D, u, i, x0); if(!(output > (yss - (yss * (p/100))) && (output < (yss * (p/100) + yss)))) { //printf("kbar=%f", kbar); return 0; } i++; } //printf("kbar=%f", kbar); return 1; } int main(){ MAT *A = MNULL, *A2 = MNULL, *A3 = MNULL, *A4 = MNULL, *A5 = MNULL, *A6 = MNULL, *B = MNULL, *C = MNULL, *D = MNULL, *T = MNULL, *Q = MNULL, *X_re = MNULL, *X_im = MNULL, *Q1 = MNULL, *Q1_inv = MNULL; MAT *Q1_temp, *Test = MNULL; // VEC *evals_re = VNULL, *evals_im = VNULL; MAT *F = MNULL, *G = MNULL, *H = MNULL; int k=3; double y, x0; CMPLX *z; //ZMAT *ZQ = ZMNULL, *ZQ_temp, *ZQ_inv = ZMNULL, *ZH, *ZF; //setting up A matrix // A=m_get(4,4); // A->me[0][0]=-0.5000;A->me[0][1]=0.6000;A->me[0][2]=0;A->me[0][3]=0; // A->me[1][0]=-0.6000;A->me[1][1]=-0.5000;A->me[1][2]=0;A->me[1][3]=0; // A->me[2][0]=0;A->me[2][1]=0;A->me[2][2]=0.2000;A->me[2][3]=0.8000; // A->me[3][0]=0;A->me[3][1]=0;A->me[3][2]=-0.8000;A->me[3][3]=0.2000;printf("A ");m_output(A); A=m_get(5,5); A->me[0][0]=-0.5000;A->me[0][1]=0.6000;A->me[0][2]=0;A->me[0][3]=0;A->me[0][4]=0; A->me[1][0]=-0.6000;A->me[1][1]=-0.5000;A->me[1][2]=0;A->me[1][3]=0;A->me[1][4]=0; A->me[2][0]=0;A->me[2][1]=0;A->me[2][2]=0.2000;A->me[2][3]=0.8000;A->me[2][4]=0; A->me[3][0]=0;A->me[3][1]=0;A->me[3][2]=-0.8000;A->me[3][3]=0.2000;A->me[3][4]=0; A->me[4][0]=0;A->me[4][1]=0;A->me[4][2]=0;A->me[4][3]=0;A->me[4][4]=0.6;printf("A "); m_output(A); A2=m_get(5,5); A2 = m_add(A, A, A2);printf("A+A=\n"); m_output(A2); A3=m_get(5,5); A3 = m_sub(A, A, A3);printf("A-A=\n"); m_output(A3); A4=m_get(5,5); A4 = m_mlt(A, A, A4);printf("A*A=\n"); m_output(A4); A5=m_get(5,5); A5 = m_inverse(A,A5);printf("inv(A)=\n"); m_output(A5); A6=m_get(5,5); A6 = m_pow(A,50,A6);printf("pow(A)=\n"); m_output(A6); z = m_get_eigenvalues(A); int size = A->m; printf("size=%d\n",size); for(int i=0;i<size;i++){ // printf("%f+%f i", z[i].real, z[i].imag); printfc(z[i]); } printf("Maximum:%f\n", max_mag_eigenvalue(z, size)); // printf("testing /n"); //setting up B matrix // B=m_get(4,1); // B->me[0][0]=0; // B->me[1][0]=0; // B->me[2][0]=2.5; // B->me[3][0]=1;printf("B ");m_output(B); /*B=m_get(5,1); B->me[0][0]=0; B->me[1][0]=0; B->me[2][0]=2.5; B->me[3][0]=1; B->me[4][0]=0;printf("B ");m_output(B);*/ //setting up C matrix // C=m_get(1,4); // C->me[0][0]=0;C->me[0][1]=2.6;C->me[0][2]=0.5;C->me[0][3]=1.2;printf("C ");m_output(C); /*C=m_get(1,5); C->me[0][0]=0;C->me[0][1]=2.6;C->me[0][2]=0.5;C->me[0][3]=1.2;C->me[0][4]=0;printf("C ");m_output(C);*/ //setting up D matrix /*D=m_get(1,1); D->me[0][0]=0;printf("D ");m_output(D); printf("-----------------------------------------------------------\n"); printf("k_ss=%d\n",k_ss(A,B,C,D,5,1.0f)); Test = m_pow(A,2,Test); m_output(Test);*/ // /* read in A matrix */ // printf("Input A matrix:\n"); // // A = m_input(MNULL); /* A has whatever size is input */ // //B = m_input(MNULL); /* B has whatever size is input */ // // if ( A->m < A->n ) // { // printf("Need m >= n to obtain least squares fit\n"); // exit(0); // } // printf("# A =\n"); m_output(A); // // //zm_output(zm_A_bar(A)); // // Q = m_get(A->m,A->n); // T = m_copy(A,MNULL); // printf("A=:%f\n",A->me[0][0]); // printf("T=:%f\n",T->me[0][0]); // /* compute Schur form: A = Q.T.Q^T */ // schur(T,Q); // /* extract eigenvalues */ // evals_re = v_get(A->m); // evals_im = v_get(A->m); // printf("A=:%f\n",A->me[0][0]); // printf("T=:%f\n",T->me[0][0]); // schur_evals(T,evals_re,evals_im); // printf("A=:%f\n",A->me[0][0]); // printf("T=:%f\n",T->me[0][0]); // printf("test=:%f\n",evals_re->ve[0]); // printf("test=:%f\n",evals_re->ve[1]); // printf("test=:%f\n",evals_re->ve[2]); // printf("test=:%f\n",evals_re->ve[3]); // printf("test=:%f\n",evals_re->ve[4]); // // z=malloc(evals_re->dim*sizeof(complex double)); // for(int i=0;i<evals_re->dim;i++){ // z[i]=evals_re->ve[i]+I*evals_im->ve[i]; // printf("Z[%d]=%f + i%f\n", i, creal(z[i]), cimag(z[i])); // } // // size_t size=(size_t)sizeof(z); // printf("Maximum:%f\n",max_mag_eigenvalue(z,size)); return 0; }
the_stack_data/40762419.c
int bar = 0; f (p) int *p; { int foo = 2; while (foo > bar) { foo -= bar; *p++ = foo; bar = 1; } } main () { int tab[2]; tab[0] = tab[1] = 0; f (tab); if (tab[0] != 2 || tab[1] != 1) abort (); exit (0); }
the_stack_data/154826901.c
#define NULL ((void*)0) typedef unsigned long size_t; // Customize by platform. typedef long intptr_t; typedef unsigned long uintptr_t; typedef long scalar_t__; // Either arithmetic or pointer type. /* By default, we understand bool (as a convenience). */ typedef int bool; #define false 0 #define true 1 /* Forward declarations */ /* Type definitions */ typedef int /*<<< orphan*/ u8 ; /* Variables and functions */ int /*<<< orphan*/ os_free (char*) ; char* os_realloc (char*,size_t) ; int os_snprintf (char*,int,char*,...) ; scalar_t__ os_snprintf_error (int,int) ; size_t os_strlen (char const*) ; int /*<<< orphan*/ wpa_snprintf_hex (char*,int,int /*<<< orphan*/ const*,size_t) ; __attribute__((used)) static void eap_fast_write(char **buf, char **pos, size_t *buf_len, const char *field, const u8 *data, size_t len, int txt) { size_t i, need; int ret; char *end; if (data == NULL || buf == NULL || *buf == NULL || pos == NULL || *pos == NULL || *pos < *buf) return; need = os_strlen(field) + len * 2 + 30; if (txt) need += os_strlen(field) + len + 20; if (*pos - *buf + need > *buf_len) { char *nbuf = os_realloc(*buf, *buf_len + need); if (nbuf == NULL) { os_free(*buf); *buf = NULL; return; } *pos = nbuf + (*pos - *buf); *buf = nbuf; *buf_len += need; } end = *buf + *buf_len; ret = os_snprintf(*pos, end - *pos, "%s=", field); if (os_snprintf_error(end - *pos, ret)) return; *pos += ret; *pos += wpa_snprintf_hex(*pos, end - *pos, data, len); ret = os_snprintf(*pos, end - *pos, "\n"); if (os_snprintf_error(end - *pos, ret)) return; *pos += ret; if (txt) { ret = os_snprintf(*pos, end - *pos, "%s-txt=", field); if (os_snprintf_error(end - *pos, ret)) return; *pos += ret; for (i = 0; i < len; i++) { ret = os_snprintf(*pos, end - *pos, "%c", data[i]); if (os_snprintf_error(end - *pos, ret)) return; *pos += ret; } ret = os_snprintf(*pos, end - *pos, "\n"); if (os_snprintf_error(end - *pos, ret)) return; *pos += ret; } }
the_stack_data/150142273.c
extern void exit (int); long long f (long long x) { return x / 10000000000LL; } main () { if (f (10000000000LL) != 1 || f (100000000000LL) != 10) abort (); exit (0); }