file
stringlengths
18
26
data
stringlengths
2
1.05M
the_stack_data/133077.c
/** * @file frdmk20dx.c * @brief board ID for the NXP FRDM-K20DX board * * DAPLink Interface Firmware * Copyright (c) 2009-2016, ARM Limited, 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. */ const char *board_id = "0230";
the_stack_data/200144328.c
#include <stdio.h> char lin[10][10]; char col[10][10]; char reg[10][10]; int main() { int n, k; int i, j, m; int num; char nao; scanf("%d", &n); for (k = 1; k <= n; k++) { for (i = 1; i <= 9; i++) for (j = 1; j <= 9; j++) lin[i][j] = col[i][j] = reg[i][j] = 0; nao = 0; for (i = 1; i <= 9; i++) { for (j = 1; j <= 9; j++) { scanf("%d", &num); if (nao) continue; m = ((i-1)/3)*3 + ((j-1)/3) + 1; if (lin[i][num] || col[j][num] || reg[m][num]) nao = 1; lin[i][num] = col[j][num] = reg[m][num] = 1; } } printf("Instancia %d\n", k); if (nao) puts("NAO\n"); else puts("SIM\n"); } return 0; }
the_stack_data/150141364.c
#include<stdio.h> #include<string.h> int main ( void ) { char string1[10]; char string2[10]; printf("Digite a string 1: "); scanf("%s", string1); printf("Digite a string 2: "); scanf("%s", string2); if(strcmp(string1, string2) == 0) printf("Iguais"); else if ( strcmp(string1, string2) < 0 ) printf("Conteudo da string 1 e menor do que da string 2"); else printf("Conteudo da string 1 e maior do que da string 2"); }
the_stack_data/179830987.c
/* * Copyright (C) 2015-2018 Alibaba Group Holding Limited */ void hal_reboot(void) { }
the_stack_data/393763.c
/* Unwinder test program. Copyright 2006-2020 Free Software Foundation, Inc. This file is part of GDB. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ void tpcs_frame (void); void switch_stack_to_same (void); void switch_stack_to_other (void); int main (void) { tpcs_frame (); switch_stack_to_same (); switch_stack_to_other (); return 0; } /* Normally Thumb functions use r7 as the frame pointer. However, with the GCC option -mtpcs-frame, they may use fp instead. Make sure that the prologue analyzer can handle this. */ asm(".text\n" " .align 2\n" " .thumb_func\n" " .code 16\n" "tpcs_frame_1:\n" " sub sp, #16\n" " push {r7}\n" " add r7, sp, #20\n" " str r7, [sp, #8]\n" " mov r7, pc\n" " str r7, [sp, #16]\n" " mov r7, fp\n" " str r7, [sp, #4]\n" " mov r7, lr\n" " str r7, [sp, #12]\n" " add r7, sp, #16\n" " mov fp, r7\n" " mov r7, sl\n" " push {r7}\n" /* We'll set a breakpoint at this call. We can't hardcode a trap instruction; the right instruction to use varies too much. And we can't use a global label, because GDB will think that's the start of a new function. So, this slightly convoluted technique. */ ".Ltpcs:\n" " nop\n" " pop {r2}\n" " mov sl, r2\n" " pop {r7}\n" " pop {r1, r2}\n" " mov fp, r1\n" " mov sp, r2\n" " bx lr\n" " .align 2\n" " .type tpcs_offset, %object\n" "tpcs_offset:\n" " .word .Ltpcs - tpcs_frame_1\n" " .align 2\n" " .thumb_func\n" " .code 16\n" "tpcs_frame:\n" " sub sp, #16\n" " push {r7}\n" " add r7, sp, #20\n" " str r7, [sp, #8]\n" " mov r7, pc\n" " str r7, [sp, #16]\n" " mov r7, fp\n" " str r7, [sp, #4]\n" " mov r7, lr\n" " str r7, [sp, #12]\n" " add r7, sp, #16\n" " mov fp, r7\n" " mov r7, sl\n" " push {r7}\n" /* Clobber saved regs around the call. */ " mov r7, #0\n" " mov lr, r7\n" " bl tpcs_frame_1\n" " pop {r2}\n" " mov sl, r2\n" " pop {r7}\n" " pop {r1, r2, r3}\n" " mov fp, r1\n" " mov sp, r2\n" " mov lr, r3\n" " bx lr\n" ); asm(".text\n" " .align 2\n" " .thumb_func\n" " .code 16\n" "write_sp:\n" " mov sp, r0\n" " bx lr\n" " .align 2\n" " .thumb_func\n" " .code 16\n" "switch_stack_to_same:\n" " push {lr}\n" " mov r0, sp\n" " bl write_sp\n" " pop {r1}\n" " bx r1\n" " .align 2\n" " .thumb_func\n" " .code 16\n" "switch_stack_to_other:\n" " push {lr}\n" " mov r7, sp\n" " mov r0, #128\n" " bl write_sp\n" " mov sp, r7\n" " pop {r1}\n" " bx r1\n");
the_stack_data/23576244.c
#include <stdio.h> int main(void){ for (int i = 1; i<=100; i--){ printf("hello world"); } return 0; }
the_stack_data/827323.c
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #define MAX_LINE 128 int main(int argc, char* argv[]) { FILE* read_fp, * write_fp; int line = 0; char buffer[MAX_LINE]; if (argc <= 2) { fprintf(stderr, "argument error!!\nThis program requires 2 arguments!!\n"); fprintf(stderr, "usage : %s file_name1(r) file_name2(w)\n", argv[0]); exit(-1); } read_fp = fopen(argv[1], "r"); if (read_fp != NULL) { if (write_fp = fopen(argv[2], "w") == NULL) { printf("%s file open error!!!\n", argv[2]); exit(-1); } while (fgets(buffer, MAX_LINE, read_fp) != NULL) { fprintf(write_fp, "%3d %s", ++line, buffer); } fclose(read_fp); fclose(write_fp); printf("%s 파일에 저장 완료.\n", argv[2]); } else { printf("file open error!!!\n"); exit(-1); } return 0; }
the_stack_data/463462.c
/* * exercise_9.c * * 复制输入到输出 * 将连续的空格用一个空格代替 */ #include <stdio.h> #include <stdlib.h> #include <stdbool.h> int main(int argc, char **argv) { int c; bool prev_is_space; prev_is_space = false; while ((c = getchar()) != EOF) { if (c == ' ' && prev_is_space) { continue; } else { putchar(c); if (c == ' ') prev_is_space = true; else prev_is_space = false; } } return EXIT_SUCCESS; }
the_stack_data/178264527.c
/** * https://www.codewars.com/kata/555624b601231dc7a400017a/train/c * @param n amount of people in a circle * @param k every kth person is going to be eliminated until one remains * @return the last surviving person */ int josephus_survivor(int n, int k) { int x = 2; int i = 0; while (i < n) { i = i + 1; x = x + k - 1; x = x % i + 1; } return x; }
the_stack_data/45450154.c
/* * Copyright (c) 2002-2007 Niels Provos <[email protected]> * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson * * 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. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR 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 "event2/event-config.h" #ifdef WIN32 #include <winsock2.h> #else #include <unistd.h> #endif #include <sys/types.h> #include <sys/stat.h> #ifdef _EVENT_HAVE_SYS_TIME_H #include <sys/time.h> #endif #ifdef _EVENT_HAVE_SYS_SOCKET_H #include <sys/socket.h> #endif #include <fcntl.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <errno.h> #include <event.h> #include <evutil.h> #ifdef _EVENT___func__ #define __func__ _EVENT___func__ #endif int test_okay = 1; int called = 0; struct timeval timeout = {60, 0}; static void read_cb(evutil_socket_t fd, short event, void *arg) { char buf[256]; int len; if (EV_TIMEOUT & event) { printf("%s: Timeout!\n", __func__); exit(1); } len = recv(fd, buf, sizeof(buf), 0); printf("%s: read %d%s\n", __func__, len, len ? "" : " - means EOF"); if (len) { if (!called) event_add(arg, &timeout); } else if (called == 1) test_okay = 0; called++; } #ifndef SHUT_WR #define SHUT_WR 1 #endif int main(int argc, char **argv) { struct event ev; const char *test = "test string"; evutil_socket_t pair[2]; #ifdef WIN32 WORD wVersionRequested; WSADATA wsaData; int err; wVersionRequested = MAKEWORD(2, 2); err = WSAStartup(wVersionRequested, &wsaData); #endif if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1) return (1); send(pair[0], test, (int)strlen(test)+1, 0); shutdown(pair[0], SHUT_WR); /* Initalize the event library */ event_init(); /* Initalize one event */ event_set(&ev, pair[1], EV_READ | EV_TIMEOUT, read_cb, &ev); event_add(&ev, &timeout); event_dispatch(); return (test_okay); }
the_stack_data/89199228.c
#define BONES_MIN(a,b) ((a<b) ? a : b) #define BONES_MAX(a,b) ((a>b) ? a : b) #define DIV_CEIL(a,b) ((a+b-1)/b) #define DIV_FLOOR(a,b) (a/b) #include <math.h>
the_stack_data/25702.c
/* Problem: The prime factors of 13195 are 5,7,13 and 29. What is the largest prime factor of a given number N? e.g. for 10, largest prime factor = 5. For 17, largest prime factor = 17. */ #include <stdio.h> #include <math.h> int isprime(int no) { int sq; if (no == 2) { return 1; } else if (no%2 == 0) { return 0; } sq = ((int)(sqrt(no))) + 1; for (int i = 3; i < sq; i + 2) { if (no%i == 0) { return 0; } } return 1; } int main() { int maxNumber = 0; int n = 0; int n1; scanf("%d", &n); if (isprime(n) == 1) printf("%d", n); else { while (n % 2 == 0) { n = n / 2; } if (isprime(n) == 1) { printf("%d\n", n); } else { n1 = ((int)(sqrt(n))) + 1; for (int i = 3; i < n1; i + 2) { if (n%i == 0) { if (isprime((int)(n / i)) == 1) { maxNumber = n / i; break; } else if (isprime(i) == 1) { maxNumber = i; } } } printf("%d\n", maxNumber); } } }
the_stack_data/240909.c
/* PR rtl-optimization/17099 */ extern void exit (int); extern void abort (void); void check (int a) { if (a != 1) abort (); } void test (int a, int b) { check ((a ? 1 : 0) | (b ? 2 : 0)); } int main (void) { test (1, 0); exit (0); }
the_stack_data/25136943.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <CL/cl.h> unsigned char *read_buffer(char *file_name, size_t *size_ptr) { FILE *f; unsigned char *buf; size_t size; /* Open file */ f = fopen(file_name, "rb"); if (!f) return NULL; /* Obtain file size */ fseek(f, 0, SEEK_END); size = ftell(f); fseek(f, 0, SEEK_SET); /* Allocate and read buffer */ buf = malloc(size + 1); fread(buf, 1, size, f); buf[size] = '\0'; /* Return size of buffer */ if (size_ptr) *size_ptr = size; /* Return buffer */ return buf; } void write_buffer(char *file_name, const char *buffer, size_t buffer_size) { FILE *f; /* Open file */ f = fopen(file_name, "w+"); /* Write buffer */ if(buffer) fwrite(buffer, 1, buffer_size, f); /* Close file */ fclose(f); } int main(int argc, char const *argv[]) { /* Get platform */ cl_platform_id platform; cl_uint num_platforms; cl_int ret = clGetPlatformIDs(1, &platform, &num_platforms); if (ret != CL_SUCCESS) { printf("error: call to 'clGetPlatformIDs' failed\n"); exit(1); } printf("Number of platforms: %d\n", num_platforms); printf("platform=%p\n", platform); /* Get platform name */ char platform_name[100]; ret = clGetPlatformInfo(platform, CL_PLATFORM_NAME, sizeof(platform_name), platform_name, NULL); if (ret != CL_SUCCESS) { printf("error: call to 'clGetPlatformInfo' failed\n"); exit(1); } printf("platform.name='%s'\n\n", platform_name); /* Get device */ cl_device_id device; cl_uint num_devices; ret = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &device, &num_devices); if (ret != CL_SUCCESS) { printf("error: call to 'clGetDeviceIDs' failed\n"); exit(1); } printf("Number of devices: %d\n", num_devices); printf("device=%p\n", device); /* Get device name */ char device_name[100]; ret = clGetDeviceInfo(device, CL_DEVICE_NAME, sizeof(device_name), device_name, NULL); if (ret != CL_SUCCESS) { printf("error: call to 'clGetDeviceInfo' failed\n"); exit(1); } printf("device.name='%s'\n", device_name); printf("\n"); /* Create a Context Object */ cl_context context; context = clCreateContext(NULL, 1, &device, NULL, NULL, &ret); if (ret != CL_SUCCESS) { printf("error: call to 'clCreateContext' failed\n"); exit(1); } printf("context=%p\n", context); /* Create a Command Queue Object*/ cl_command_queue command_queue; command_queue = clCreateCommandQueue(context, device, 0, &ret); if (ret != CL_SUCCESS) { printf("error: call to 'clCreateCommandQueue' failed\n"); exit(1); } printf("command_queue=%p\n", command_queue); printf("\n"); /* Program source */ unsigned char *source_code; size_t source_length; /* Read program from 'relational_less_than_or_equal_to_float16float16.cl' */ source_code = read_buffer("relational_less_than_or_equal_to_float16float16.cl", &source_length); /* Create a program */ cl_program program; program = clCreateProgramWithSource(context, 1, (const char **)&source_code, &source_length, &ret); if (ret != CL_SUCCESS) { printf("error: call to 'clCreateProgramWithSource' failed\n"); exit(1); } printf("program=%p\n", program); /* Build program */ ret = clBuildProgram(program, 1, &device, NULL, NULL, NULL); if (ret != CL_SUCCESS ) { size_t size; char *log; /* Get log size */ clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG,0, NULL, &size); /* Allocate log and print */ log = malloc(size); clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG,size, log, NULL); printf("error: call to 'clBuildProgram' failed:\n%s\n", log); /* Free log and exit */ free(log); exit(1); } printf("program built\n"); printf("\n"); /* Create a Kernel Object */ cl_kernel kernel; kernel = clCreateKernel(program, "relational_less_than_or_equal_to_float16float16", &ret); if (ret != CL_SUCCESS) { printf("error: call to 'clCreateKernel' failed\n"); exit(1); } /* Create and allocate host buffers */ size_t num_elem = 10; /* Create and init host side src buffer 0 */ cl_float16 *src_0_host_buffer; src_0_host_buffer = malloc(num_elem * sizeof(cl_float16)); for (int i = 0; i < num_elem; i++) src_0_host_buffer[i] = (cl_float16){{2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0}}; /* Create and init device side src buffer 0 */ cl_mem src_0_device_buffer; src_0_device_buffer = clCreateBuffer(context, CL_MEM_READ_ONLY, num_elem * sizeof(cl_float16), NULL, &ret); if (ret != CL_SUCCESS) { printf("error: could not create source buffer\n"); exit(1); } ret = clEnqueueWriteBuffer(command_queue, src_0_device_buffer, CL_TRUE, 0, num_elem * sizeof(cl_float16), src_0_host_buffer, 0, NULL, NULL); if (ret != CL_SUCCESS) { printf("error: call to 'clEnqueueWriteBuffer' failed\n"); exit(1); } /* Create and init host side src buffer 1 */ cl_float16 *src_1_host_buffer; src_1_host_buffer = malloc(num_elem * sizeof(cl_float16)); for (int i = 0; i < num_elem; i++) src_1_host_buffer[i] = (cl_float16){{2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0}}; /* Create and init device side src buffer 1 */ cl_mem src_1_device_buffer; src_1_device_buffer = clCreateBuffer(context, CL_MEM_READ_ONLY, num_elem * sizeof(cl_float16), NULL, &ret); if (ret != CL_SUCCESS) { printf("error: could not create source buffer\n"); exit(1); } ret = clEnqueueWriteBuffer(command_queue, src_1_device_buffer, CL_TRUE, 0, num_elem * sizeof(cl_float16), src_1_host_buffer, 0, NULL, NULL); if (ret != CL_SUCCESS) { printf("error: call to 'clEnqueueWriteBuffer' failed\n"); exit(1); } /* Create host dst buffer */ cl_int16 *dst_host_buffer; dst_host_buffer = malloc(num_elem * sizeof(cl_int16)); memset((void *)dst_host_buffer, 1, num_elem * sizeof(cl_int16)); /* Create device dst buffer */ cl_mem dst_device_buffer; dst_device_buffer = clCreateBuffer(context, CL_MEM_WRITE_ONLY, num_elem *sizeof(cl_int16), NULL, &ret); if (ret != CL_SUCCESS) { printf("error: could not create dst buffer\n"); exit(1); } /* Set kernel arguments */ ret = CL_SUCCESS; ret |= clSetKernelArg(kernel, 0, sizeof(cl_mem), &src_0_device_buffer); ret |= clSetKernelArg(kernel, 1, sizeof(cl_mem), &src_1_device_buffer); ret |= clSetKernelArg(kernel, 2, sizeof(cl_mem), &dst_device_buffer); if (ret != CL_SUCCESS) { printf("error: call to 'clSetKernelArg' failed\n"); exit(1); } /* Launch the kernel */ size_t global_work_size = num_elem; size_t local_work_size = num_elem; ret = clEnqueueNDRangeKernel(command_queue, kernel, 1, NULL, &global_work_size, &local_work_size, 0, NULL, NULL); if (ret != CL_SUCCESS) { printf("error: call to 'clEnqueueNDRangeKernel' failed\n"); exit(1); } /* Wait for it to finish */ clFinish(command_queue); /* Read results from GPU */ ret = clEnqueueReadBuffer(command_queue, dst_device_buffer, CL_TRUE,0, num_elem * sizeof(cl_int16), dst_host_buffer, 0, NULL, NULL); if (ret != CL_SUCCESS) { printf("error: call to 'clEnqueueReadBuffer' failed\n"); exit(1); } /* Dump dst buffer to file */ char dump_file[100]; sprintf((char *)&dump_file, "%s.result", argv[0]); write_buffer(dump_file, (const char *)dst_host_buffer, num_elem * sizeof(cl_int16)); printf("Result dumped to %s\n", dump_file); /* Free host dst buffer */ free(dst_host_buffer); /* Free device dst buffer */ ret = clReleaseMemObject(dst_device_buffer); if (ret != CL_SUCCESS) { printf("error: call to 'clReleaseMemObject' failed\n"); exit(1); } /* Free host side src buffer 0 */ free(src_0_host_buffer); /* Free device side src buffer 0 */ ret = clReleaseMemObject(src_0_device_buffer); if (ret != CL_SUCCESS) { printf("error: call to 'clReleaseMemObject' failed\n"); exit(1); } /* Free host side src buffer 1 */ free(src_1_host_buffer); /* Free device side src buffer 1 */ ret = clReleaseMemObject(src_1_device_buffer); if (ret != CL_SUCCESS) { printf("error: call to 'clReleaseMemObject' failed\n"); exit(1); } /* Release kernel */ ret = clReleaseKernel(kernel); if (ret != CL_SUCCESS) { printf("error: call to 'clReleaseKernel' failed\n"); exit(1); } /* Release program */ ret = clReleaseProgram(program); if (ret != CL_SUCCESS) { printf("error: call to 'clReleaseProgram' failed\n"); exit(1); } /* Release command queue */ ret = clReleaseCommandQueue(command_queue); if (ret != CL_SUCCESS) { printf("error: call to 'clReleaseCommandQueue' failed\n"); exit(1); } /* Release context */ ret = clReleaseContext(context); if (ret != CL_SUCCESS) { printf("error: call to 'clReleaseContext' failed\n"); exit(1); } return 0; }
the_stack_data/68755.c
/* This file was automatically generated by CasADi. The CasADi copyright holders make no ownership claim of its contents. */ #ifdef __cplusplus extern "C" { #endif /* How to prefix internal symbols */ #ifdef CASADI_CODEGEN_PREFIX #define CASADI_NAMESPACE_CONCAT(NS, ID) _CASADI_NAMESPACE_CONCAT(NS, ID) #define _CASADI_NAMESPACE_CONCAT(NS, ID) NS ## ID #define CASADI_PREFIX(ID) CASADI_NAMESPACE_CONCAT(CODEGEN_PREFIX, ID) #else #define CASADI_PREFIX(ID) long_cost_y_e_fun_jac_ut_xt_ ## ID #endif #include <math.h> #ifndef casadi_real #define casadi_real double #endif #ifndef casadi_int #define casadi_int int #endif /* Add prefix to internal symbols */ #define casadi_f0 CASADI_PREFIX(f0) #define casadi_s0 CASADI_PREFIX(s0) #define casadi_s1 CASADI_PREFIX(s1) #define casadi_s2 CASADI_PREFIX(s2) #define casadi_s3 CASADI_PREFIX(s3) #define casadi_sq CASADI_PREFIX(sq) /* Symbol visibility in DLLs */ #ifndef CASADI_SYMBOL_EXPORT #if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) #if defined(STATIC_LINKED) #define CASADI_SYMBOL_EXPORT #else #define CASADI_SYMBOL_EXPORT __declspec(dllexport) #endif #elif defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY) #define CASADI_SYMBOL_EXPORT __attribute__ ((visibility ("default"))) #else #define CASADI_SYMBOL_EXPORT #endif #endif casadi_real casadi_sq(casadi_real x) { return x*x;} static const casadi_int casadi_s0[7] = {3, 1, 0, 3, 0, 1, 2}; static const casadi_int casadi_s1[3] = {0, 0, 0}; static const casadi_int casadi_s2[9] = {5, 1, 0, 5, 0, 1, 2, 3, 4}; static const casadi_int casadi_s3[14] = {3, 5, 0, 2, 3, 4, 5, 6, 0, 1, 0, 1, 2, 2}; /* long_cost_y_e_fun_jac_ut_xt:(i0[3],i1[],i2[5])->(o0[5],o1[3x5,6nz]) */ static int casadi_f0(const casadi_real** arg, casadi_real** res, casadi_int* iw, casadi_real* w, int mem) { casadi_real a0, a1, a2, a3, a4, a5, a6; a0=arg[2]? arg[2][2] : 0; a1=arg[0]? arg[0][0] : 0; a0=(a0-a1); a2=2.; a3=arg[2]? arg[2][4] : 0; a2=(a2*a3); a3=arg[0]? arg[0][1] : 0; a4=(a2*a3); a5=casadi_sq(a3); a6=1.9620000000000001e+01; a5=(a5/a6); a4=(a4+a5); a5=4.; a4=(a4+a5); a0=(a0-a4); a4=10.; a4=(a3+a4); a0=(a0/a4); if (res[0]!=0) res[0][0]=a0; if (res[0]!=0) res[0][1]=a1; if (res[0]!=0) res[0][2]=a3; a1=arg[0]? arg[0][2] : 0; if (res[0]!=0) res[0][3]=a1; a5=20.; a6=arg[2]? arg[2][3] : 0; a1=(a1-a6); a1=(a5*a1); if (res[0]!=0) res[0][4]=a1; a1=(1./a4); a1=(-a1); if (res[1]!=0) res[1][0]=a1; a1=5.0968399592252800e-02; a3=(a3+a3); a1=(a1*a3); a2=(a2+a1); a2=(a2/a4); a0=(a0/a4); a2=(a2+a0); a2=(-a2); if (res[1]!=0) res[1][1]=a2; a2=1.; if (res[1]!=0) res[1][2]=a2; if (res[1]!=0) res[1][3]=a2; if (res[1]!=0) res[1][4]=a2; if (res[1]!=0) res[1][5]=a5; return 0; } CASADI_SYMBOL_EXPORT int long_cost_y_e_fun_jac_ut_xt(const casadi_real** arg, casadi_real** res, casadi_int* iw, casadi_real* w, int mem){ return casadi_f0(arg, res, iw, w, mem); } CASADI_SYMBOL_EXPORT int long_cost_y_e_fun_jac_ut_xt_alloc_mem(void) { return 0; } CASADI_SYMBOL_EXPORT int long_cost_y_e_fun_jac_ut_xt_init_mem(int mem) { return 0; } CASADI_SYMBOL_EXPORT void long_cost_y_e_fun_jac_ut_xt_free_mem(int mem) { } CASADI_SYMBOL_EXPORT int long_cost_y_e_fun_jac_ut_xt_checkout(void) { return 0; } CASADI_SYMBOL_EXPORT void long_cost_y_e_fun_jac_ut_xt_release(int mem) { } CASADI_SYMBOL_EXPORT void long_cost_y_e_fun_jac_ut_xt_incref(void) { } CASADI_SYMBOL_EXPORT void long_cost_y_e_fun_jac_ut_xt_decref(void) { } CASADI_SYMBOL_EXPORT casadi_int long_cost_y_e_fun_jac_ut_xt_n_in(void) { return 3;} CASADI_SYMBOL_EXPORT casadi_int long_cost_y_e_fun_jac_ut_xt_n_out(void) { return 2;} CASADI_SYMBOL_EXPORT casadi_real long_cost_y_e_fun_jac_ut_xt_default_in(casadi_int i){ switch (i) { default: return 0; } } CASADI_SYMBOL_EXPORT const char* long_cost_y_e_fun_jac_ut_xt_name_in(casadi_int i){ switch (i) { case 0: return "i0"; case 1: return "i1"; case 2: return "i2"; default: return 0; } } CASADI_SYMBOL_EXPORT const char* long_cost_y_e_fun_jac_ut_xt_name_out(casadi_int i){ switch (i) { case 0: return "o0"; case 1: return "o1"; default: return 0; } } CASADI_SYMBOL_EXPORT const casadi_int* long_cost_y_e_fun_jac_ut_xt_sparsity_in(casadi_int i) { switch (i) { case 0: return casadi_s0; case 1: return casadi_s1; case 2: return casadi_s2; default: return 0; } } CASADI_SYMBOL_EXPORT const casadi_int* long_cost_y_e_fun_jac_ut_xt_sparsity_out(casadi_int i) { switch (i) { case 0: return casadi_s2; case 1: return casadi_s3; default: return 0; } } CASADI_SYMBOL_EXPORT int long_cost_y_e_fun_jac_ut_xt_work(casadi_int *sz_arg, casadi_int* sz_res, casadi_int *sz_iw, casadi_int *sz_w) { if (sz_arg) *sz_arg = 3; if (sz_res) *sz_res = 2; if (sz_iw) *sz_iw = 0; if (sz_w) *sz_w = 0; return 0; } #ifdef __cplusplus } /* extern "C" */ #endif
the_stack_data/184517854.c
// RUN: %clang_cc1 -fsanitize=implicit-integer-truncation -fsanitize-recover=implicit-integer-truncation -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_implicit_conversion" --check-prefixes=CHECK // CHECK-DAG: @[[LINE_100_TRUNCATION:.*]] = {{.*}}, i32 100, i32 10 }, {{.*}}, {{.*}}, i8 0 } // CHECK-DAG: @[[LINE_300_TRUNCATION:.*]] = {{.*}}, i32 300, i32 10 }, {{.*}}, {{.*}}, i8 0 } //----------------------------------------------------------------------------// // Unsigned case. //----------------------------------------------------------------------------// // CHECK-LABEL: @blacklist_0_convert_unsigned_int_to_unsigned_char __attribute__((no_sanitize("undefined"))) unsigned char blacklist_0_convert_unsigned_int_to_unsigned_char(unsigned int x) { // We are not in "undefined" group, so that doesn't work. // CHECK: call void @__ubsan_handle_implicit_conversion(i8* bitcast ({ {{{.*}}}, {{{.*}}}*, {{{.*}}}*, i8 }* @[[LINE_100_TRUNCATION]] to i8*) #line 100 return x; } // CHECK-LABEL: @blacklist_1_convert_unsigned_int_to_unsigned_char __attribute__((no_sanitize("integer"))) unsigned char blacklist_1_convert_unsigned_int_to_unsigned_char(unsigned int x) { return x; } // CHECK-LABEL: @blacklist_2_convert_unsigned_int_to_unsigned_char __attribute__((no_sanitize("implicit-conversion"))) unsigned char blacklist_2_convert_unsigned_int_to_unsigned_char(unsigned int x) { return x; } // CHECK-LABEL: @blacklist_3_convert_unsigned_int_to_unsigned_char __attribute__((no_sanitize("implicit-integer-truncation"))) unsigned char blacklist_3_convert_unsigned_int_to_unsigned_char(unsigned int x) { return x; } //----------------------------------------------------------------------------// // Signed case. //----------------------------------------------------------------------------// // CHECK-LABEL: @blacklist_0_convert_signed_int_to_signed_char __attribute__((no_sanitize("undefined"))) signed char blacklist_0_convert_signed_int_to_signed_char(signed int x) { // We are not in "undefined" group, so that doesn't work. // CHECK: call void @__ubsan_handle_implicit_conversion(i8* bitcast ({ {{{.*}}}, {{{.*}}}*, {{{.*}}}*, i8 }* @[[LINE_300_TRUNCATION]] to i8*) #line 300 return x; } // CHECK-LABEL: @blacklist_1_convert_signed_int_to_signed_char __attribute__((no_sanitize("integer"))) signed char blacklist_1_convert_signed_int_to_signed_char(signed int x) { return x; } // CHECK-LABEL: @blacklist_2_convert_signed_int_to_signed_char __attribute__((no_sanitize("implicit-conversion"))) signed char blacklist_2_convert_signed_int_to_signed_char(signed int x) { return x; } // CHECK-LABEL: @blacklist_3_convert_signed_int_to_signed_char __attribute__((no_sanitize("implicit-integer-truncation"))) signed char blacklist_3_convert_signed_int_to_signed_char(signed int x) { return x; }
the_stack_data/175142150.c
#include <string.h> int strcmp(const char *s1, const char *s2) { while (*s1 == *s2) { if (*s1 == 0) { return 0; } ++s1; ++s2; } return (unsigned char)*s1 < (unsigned char)*s2 ? -1 : 1; }
the_stack_data/527440.c
// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s extern void abort(void) __attribute__((noreturn)); void f1(void) { abort(); } // CHECK-LABEL: define {{.*}}void @f1() // CHECK-NEXT: entry: // CHECK-NEXT: call void @abort() // CHECK-NEXT: unreachable // CHECK-NEXT: } void *f2(void) { abort(); return 0; } // CHECK-LABEL: define {{.*}}i8* @f2() // CHECK-NEXT: entry: // CHECK-NEXT: call void @abort() // CHECK-NEXT: unreachable // CHECK-NEXT: }
the_stack_data/237642157.c
/* $NetBSD: Lint___clone.c,v 1.2 2003/01/18 11:32:58 thorpej Exp $ */ /* * This file placed in the public domain. * Jason R. Thorpe, July 16, 2001. */ #include <sched.h> /*ARGSUSED*/ pid_t __clone(int (*func)(void *), void *stack, int flags, void *arg) { return (0); }
the_stack_data/88213.c
#include<stdio.h> int any(char s1[], char s2[]); main() { int c, i; char s1[1000], s2[500]; for (i = 0; (c = getchar()) != EOF && c!='\n'; ++i) s1[i] = c; for (i = 0; (c = getchar()) != EOF && c!='\n'; ++i) s2[i] = c; printf ("The position found is: %i", any(s1, s2)); } int any(char s1[], char s2[]) { int i, j; for (i = 0; s1[i] != '\0'; ++i) for (j = 0; s2[j] != '\0'; ++j) if (s1[i] == s2[j]) return i; return -1; }
the_stack_data/61075255.c
/* { dg-do compile } */ /* { dg-options "-O2 -mno-indirect-branch-register -mfunction-return=keep -mindirect-branch=thunk-inline -fno-pic" } */ typedef void (*dispatch_t)(long offset); dispatch_t dispatch; void male_indirect_jump (long offset) { dispatch(offset); } /* { dg-final { scan-assembler "mov(?:l|q)\[ \t\]*_?dispatch" { target *-*-linux* } } } */ /* { dg-final { scan-assembler "jmp\[ \t\]*\.LIND" } } */ /* { dg-final { scan-assembler "call\[ \t\]*\.LIND" } } */ /* { dg-final { scan-assembler {\tpause} } } */ /* { dg-final { scan-assembler {\tlfence} } } */ /* { dg-final { scan-assembler-not "__x86_indirect_thunk" } } */ /* { dg-final { scan-assembler-not "pushq\[ \t\]%rax" { target x32 } } } */
the_stack_data/1009384.c
/* Zbadaj jak zachowuje się Sigma w sytuacji przepełnienia zmiennej całkowitej, przepełnienia zmiennej zmiennoprzecinkowej i niedomiaru zmiennej zmiennoprzecinkowej. Zastosuj metodę doświadczalną, czyli napisz programy, w których wystąpią te przepełnienia i niedomiary. Wskazówka: zajrzyj do plików limits.h oraz float.h w których zdefiniowano stałe symboliczne dla wszystkich rozmiarów danych oraz dla innych właściwości komputera i kompilatora. (Są też strony manuala limits.h i float.h.) */ #include <stdio.h> int main() { int i = 2147483647; unsigned int j = 4294967295; printf("%d %d %d\n", i, i+1, i+2); printf("%u %u %u\n", j, j+1, j+2); return 0; } /* zmienna j po osiągnięciu wartości max rozpoczyna liczenie od początku, podobnie zmienna i, ale podczas gdy zmienna j typu unsigned int rozpoczyna liczenie od zera, zmienna i typu int zaczyna je od wartości -2 147 483 647.*/
the_stack_data/154827545.c
#include<stdio.h> int main(void) { return 0; }
the_stack_data/206394291.c
/* Copyright 2020 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ /* This tests GDB's handling of the DWARF is-stmt field in the line table. This field is used when many addresses all represent the same source line. The address(es) at which it is suitable to place a breakpoint for a line are marked with is-stmt true, while address(es) that are not good places to place a breakpoint are marked as is-stmt false. In order to build a reproducible test and exercise GDB's is-stmt support, we will be generating our own DWARF. The test will contain a series of C source lines, ensuring that we get a series of assembler instructions. Each C source line will be given an assembler label, which we use to generate a fake line table. In this fake line table each assembler block is claimed to represent a single C source line, however, we will toggle the is-stmt flag. We can then debug this with GDB and test the handling of is-stmt. */ /* Used to insert labels with which we can build a fake line table. */ #define LL(N) asm ("line_label_" #N ": .globl line_label_" #N) volatile int var; volatile int bar; int main () { /* main prologue */ asm ("main_label: .globl main_label"); LL (1); var = 99; /* main, set var to 99 */ bar = 99; LL (2); var = 0; /* main, set var to 0 */ bar = 0; LL (3); var = 1; /* main, set var to 1 */ bar = 1; LL (4); var = 2; /* main, set var to 2 */ bar = 2; LL (5); return 0; /* main end */ }
the_stack_data/944447.c
#define STATIC_ASSERT(condition) \ int some_array##__LINE__[(condition) ? 1 : -1]; #define G(X) _Generic((X), \ long double: 1, \ default: 10, \ float: 2, \ int: 3, \ char: 4, \ struct some: 5 \ ) struct some { } s; int i; char ch; long double ld; short sh; #ifdef __GNUC__ STATIC_ASSERT(G(i)==3); STATIC_ASSERT(G(sh)==10); STATIC_ASSERT(G(ld)==1); STATIC_ASSERT(G(ch)==4); STATIC_ASSERT(G(s)==5); #else // Visual Studio doesn't have it. #endif int main() { }
the_stack_data/77619.c
#include <stdio.h> #include <string.h> #include <stdlib.h> /* TO-DOs 1. Modificar el push para que agregue en orden de carnet 2. Modificar el eliminar para que elimine por carnet */ typedef struct node { char nombre[20]; int carnet; int nota; struct node * next; } Alumno; Alumno * head = NULL; void push(Alumno * head, int carnet,char* nombre,int nota) { Alumno * current = head; while (current->next != NULL) { current = current->next; } /* now we can add a new variable */ current->next = malloc(sizeof(Alumno)); current->next->carnet=carnet; strcpy(current->next->nombre, nombre); current->next->nota=nota; current->next->next = NULL; } void print_list(Alumno * head) { printf("***Listado de alumnos:\n"); Alumno * current = head; while (current != NULL) { printf("%s\n", current->nombre); current = current->next; } } void init(int carnet,char* nombre,int nota) { head = malloc(sizeof(Alumno)); head->carnet=carnet; strcpy( head->nombre, nombre); head->nota = nota; head->next = NULL; } int pop(Alumno ** head) { char retval[20]; Alumno * next_node = NULL; if (*head == NULL) { return -1; } next_node = (*head)->next; strcpy(retval, (*head)->nombre); free(*head); *head = next_node; printf("Alumno eliminado: %s \n",retval); return 0; } int remove_by_index(Alumno ** head, int n) { int i = 0; int retval = -1; Alumno * current = *head; Alumno * temp_node = NULL; if (n == 0) { return pop(head); } for (i = 0; i < n-1; i++) { if (current->next == NULL) { return -1; } current = current->next; } temp_node = current->next; retval = temp_node->carnet; current->next = temp_node->next; free(temp_node); return retval; } int remove_by_value(Alumno ** head, int carnet){ int i = 0; char retval[20]; Alumno * current = *head; Alumno * temp_node = NULL; if (current->carnet == carnet) { return pop(head); } while (current->next->carnet != carnet) { if (current->next == NULL) { return -1; } current = current->next; } temp_node = current->next; strcpy(retval, temp_node->nombre); current->next = temp_node->next; free(temp_node); printf("Alumno eliminado: %s \n",retval); return 0; } int main() { /*init(1,"Victor",90); push(head,2,"Andres",80); push(head,3,"Gaby",80); print_list(head); remove_by_value(&head,1); print_list(head); remove_by_value(&head,3); print_list(head);*/ for (;;) { int choice; printf("Para agregar un alumno ingrese 1. Para eliminar un alumno ingrese 2:\n"); scanf(" %d", &choice); if (choice==1) { int carnet; printf("Ingrese el carnet: \n"); scanf("%d", &carnet); char nombre[20]; printf("Ingrese el nombre: \n"); scanf("%s", &nombre); int nota; printf("Ingrese la nota: \n"); scanf("%d", &nota); if (head==NULL){ init(carnet,nombre,nota); } else { push(head,carnet,nombre,nota); } } if (choice==2) { int carnet; printf("Ingrese el carnet que desea eliminar: \n"); scanf("%d", &carnet); remove_by_value(&head,carnet); } print_list(head); } return 0; }
the_stack_data/62637624.c
#include <stdio.h> #include <math.h> void main() { int x=1,y,n1=0,n2=0,n3=0,j1=0,j2=0,j3=0; while (x != 0) { printf("enter first number \n"); scanf("%d", &x); printf("enter second number \n"); scanf("%d", &y); if (x > 100) { n1 = x / 100; n2 = (x / 10) % 10; n3 = x % 10; j1 = y / 100; j2 = (y / 10) % 10; j3 = y % 10; printf("Your answer is %d%d%d%d%d%d\n", n1, j3, n2, j2, n3, j1); } if (x < 100) { n1 = x / 10; n2 = x % 10; j1 = y / 10; j2 = y % 10; printf("Your answer is %d%d%d%d\n", n1, j2,n2,j1); } } }
the_stack_data/8058.c
/* Bug: side effects ignored in modulo based expressions. see modulo_to_transformer(). */ #include <stdio.h> int main() { int i=4; int j, k; j = (i++)%2; k = (++i)%2; printf("i=%d, j=%d, k=%d\n", i, j, k); return 0; }
the_stack_data/39895.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strncmp.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jwinthei <[email protected]> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/11/20 18:30:08 by jwinthei #+# #+# */ /* Updated: 2018/11/26 14:06:04 by jwinthei ### ########.fr */ /* */ /* ************************************************************************** */ #include <string.h> int ft_strncmp(const char *src1, const char *src2, size_t n) { size_t i; int diff; i = 0; diff = 0; while (i < n) { diff = ((unsigned char *)src1)[i] - ((unsigned char *)src2)[i]; if (diff != 0 || src1[i] == '\0' || src2[i] == '\0') break ; i++; } return (diff); }
the_stack_data/167330248.c
int main() { int a = 1; int b = 2; int c = 3; if(a == b) { c = 2; } return c; }
the_stack_data/170452532.c
#include<stdio.h> main() { int mesec = 4; int steviloDni; switch (mesec) { case 2: steviloDni=28; case 4: case 6: case 9: case 11: steviloDni=30; default: steviloDni=31; } printf("Mesec %d ima %d dni\n", mesec, steviloDni); }
the_stack_data/76591.c
#include <stdio.h> #include <string.h> // strlen #define TRUE 1 #define FALSE 0 void squeeze(char t[], char skip[], int n) { int i, j ,k, ignore; for (i = j = 0; t[i] != '\0'; i++) { ignore = FALSE; for (k = 0; k < n; k++) { if (t[i] == skip[k]) { ignore = TRUE; break; } } if (!ignore) { t[j++] = t[i]; } } t[j] = '\0'; return; } int main(int count, char** a) { int i = 2; char* s = a[1]; int k = strlen(s); for (; i < count; i++) { squeeze(a[i], s, k); printf("%s\n", a[i]); } return 0; }
the_stack_data/198579604.c
#include <stdint.h> #include <stdlib.h> #include <stdio.h> #include <dirent.h> #include <unistd.h> int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size); const char * cs_fuzz_arch(uint8_t arch); int main(int argc, char** argv) { FILE * fp; uint8_t Data[0x1000]; size_t Size; DIR *d; struct dirent *dir; int r = 0; int i; if (argc != 2) { return 1; } d = opendir(argv[1]); if (d == NULL) { printf("Invalid directory\n"); return 2; } if (chdir(argv[1]) != 0) { closedir(d); printf("Invalid directory\n"); return 2; } while((dir = readdir(d)) != NULL) { //opens the file, get its size, and reads it into a buffer if (dir->d_type != DT_REG) { continue; } printf("Running %s\n", dir->d_name); fflush(stdout); fp = fopen(dir->d_name, "rb"); if (fp == NULL) { r = 3; break; } if (fseek(fp, 0L, SEEK_END) != 0) { fclose(fp); r = 4; break; } Size = ftell(fp); if (Size == (size_t) -1) { fclose(fp); r = 5; break; } else if (Size > 0x1000) { fclose(fp); continue; } if (fseek(fp, 0L, SEEK_SET) != 0) { fclose(fp); r = 7; break; } if (fread(Data, Size, 1, fp) != 1) { fclose(fp); r = 8; break; } if (Size > 0) { printf("command cstool %s\n", cs_fuzz_arch(Data[0])); } for (i=0; i<Size; i++) { printf("%02x", Data[i]); } printf("\n"); //lauch fuzzer LLVMFuzzerTestOneInput(Data, Size); fclose(fp); } closedir(d); printf("Ok : whole directory finished\n"); return r; }
the_stack_data/59512564.c
/*------------------------------------------------------------ PROGRAMACIÓN AVANZADA I HW04P02 César Magaña [email protected] --------------------------------------------------------------*/ #include <stdio.h> char* cifras[] = {"CERO", "UNO", "DOS", "TRES", "CUATRO", "CINCO", "SEIS", "SIETE", "OCHO", "NUEVE"}; //------------------------------------------------------------ //Función recursiva. void LeeNumero( unsigned int n ){ if (n<10) printf( "%s ", cifras[n] ); else { printf( "%s ", cifras[n%10] ); return LeeNumero ( n/10 ); } } //------------------------------------------------------------ //Función iterativa. /* int potencia = 10; int cifra; while ( n-potencia > 0 ) { cifra = (n/potencia)%10; potencia *= 10; printf( "%s ", numeros[cifra] ); }*/ //------------------------------------------------------------ int main (int argc, const char * argv[]) { unsigned int n; printf( "Ingrese un unsigned int:\n" ); scanf( "%u",&n ); LeeNumero(n); getchar(); return 0; } //------------------------------------------------------------
the_stack_data/1044298.c
/*********************************************************** rndtest.c -- 乱数 ***********************************************************/ /* 乱数のごく簡単なテスト */ #include <stdio.h> #include <stdlib.h> #include <math.h> #define rnd() (1.0 / (RAND_MAX + 1.0)) * rand() int main(void) { unsigned seed; unsigned long i, n; double r, s1, s2, x, x0, xprev; printf("乱数の種? "); scanf("%u", &seed); srand(seed); /* 任意の unsigned int で初期化. */ printf("個数? "); scanf("%lu", &n); s1 = x0 = xprev = rnd() - 0.5; s2 = x0 * x0; r = 0; for (i = 1; i < n; i++) { x = rnd() - 0.5; s1 += x; s2 += x * x; r += xprev * x; xprev = x; } r = (n * (r + x * x0) - s1 * s1) / (n * s2 - s1 * s1); printf("以下は期待値との差を標準誤差で割ったもの.\n"); printf("20回中19回は±2以内に入るはず.\n"); printf("平均値………………… %6.3f\n", s1 * sqrt(12.0 / n)); printf("隣どうしの相関係数… %6.3f\n", ((n - 1) * r + 1) * sqrt((n + 1.0) / (n * (n - 3.0)))); return 0; }
the_stack_data/220455966.c
int main() { return 0; }
the_stack_data/74989.c
#include <stdio.h> int main(void) { int grade[6][2]; int sum_grade[2] = {0}; int sum_student[6] = {0}; for (int i = 0; i < 6; i++) { for (int j = 0; j < 2; j++) { do { printf("学生[%d],科目[%d]的成绩:", i+1, j+1); scanf("%d", &grade[i][j]); if (grade[i][j] < 0) puts("学生的成绩必须为正整数。"); } while (grade[i][j] < 0); } } putchar('\n'); // 各门课程的总成绩 for (int i = 0; i < 2; i++) { for (int j = 0; j < 6; j++) { sum_grade[i] += grade[j][i]; } } // 各个学生的总成绩 for (int i = 0; i < 6; i++) { for (int j = 0; j < 2; j++) { sum_student[i] += grade[i][j]; } } printf("[语文]课程的总成绩: %d, 平均成绩: %d\n", sum_grade[0], sum_grade[0] / 6); printf("[数学]课程的总成绩: %d, 平均成绩: %d\n", sum_grade[1], sum_grade[1] / 6); for (int i = 0; i < 6; i++) { printf("学生[%d]的总成绩: %d, 平均成绩: %d\n", i+1, sum_student[i], sum_student[i] / 2); } return 0; }
the_stack_data/64200766.c
/* Copyright (C) 1996, 1997, 1999 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <[email protected]>, 1996. The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. The GNU C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with the GNU C Library; if not, see <http://www.gnu.org/licenses/>. */ #include <netinet/ether.h> #include <netinet/if_ether.h> char * ether_ntoa (const struct ether_addr *addr) { static char asc[18]; return ether_ntoa_r (addr, asc); }
the_stack_data/1045110.c
/* Copyright (C) 2003, 2005 Free Software Foundation. Verify that the `const' function attribute is applied to various builtins and that these functions are optimized away by the compiler under the appropriate circumstances. Written by Kaveh Ghazi, 2003-08-04. */ /* { dg-do link } */ /* { dg-options "-ffast-math" } */ /* These are helper macros to test combinations of functions. We test foo() != foo() with the same arguments, and expect the compiler to optimize away these tests of const functions. */ /* Just test the __builtin_ functions. */ #define BUILTIN_TEST1(FN, TYPE) \ extern void link_failure_builtin_##FN(void); \ void test_builtin_##FN(TYPE x) \ { if (__builtin_##FN(x) != __builtin_##FN(x)) link_failure_builtin_##FN(); } /* Just test the __builtin_ functions. */ #define BUILTIN_TEST2(FN, TYPE) \ extern void link_failure_builtin_##FN(void); \ void test_builtin_##FN(TYPE x, TYPE y) \ { if (__builtin_##FN(x,y) != __builtin_##FN(x,y)) link_failure_builtin_##FN(); } /* Also test the regular (non-__builtin_) function. */ #define TEST1(FN, TYPE, RTYPE) \ BUILTIN_TEST1(FN, TYPE) \ extern void link_failure_##FN(void); \ extern RTYPE FN(TYPE); \ void test_##FN(TYPE x) { if (FN(x) != FN(x)) link_failure_##FN(); } /* Test the __builtin_ functions taking void arguments (with the "f" and "l" variants). */ #define BUILTIN_FPTEST0(FN) \ extern void link_failure_builtin_##FN(void); \ extern void link_failure_builtin_##FN##f(void); \ extern void link_failure_builtin_##FN##l(void); \ void test_builtin_##FN(void) \ { if (__builtin_##FN() != __builtin_##FN()) link_failure_builtin_##FN(); } \ void test_builtin_##FN##f(void) \ { if (__builtin_##FN##f() != __builtin_##FN##f()) link_failure_builtin_##FN##f(); } \ void test_builtin_##FN##l(void) \ { if (__builtin_##FN##l() != __builtin_##FN##l()) link_failure_builtin_##FN##l(); } /* Test the __builtin_ functions taking one FP argument (with the "f" and "l" variants). */ #define BUILTIN_FPTEST1(FN) \ extern void link_failure_builtin_##FN(void); \ extern void link_failure_builtin_##FN##f(void); \ extern void link_failure_builtin_##FN##l(void); \ void test_builtin_##FN(double d) \ { if (__builtin_##FN(d) != __builtin_##FN(d)) link_failure_builtin_##FN(); } \ void test_builtin_##FN##f(float f) \ { if (__builtin_##FN##f(f) != __builtin_##FN##f(f)) link_failure_builtin_##FN##f(); } \ void test_builtin_##FN##l(long double ld) \ { if (__builtin_##FN##l(ld) != __builtin_##FN##l(ld)) link_failure_builtin_##FN##l(); } /* Test the __builtin_ functions taking one argument of supplied type (with the "f" and "l" variants). */ #define BUILTIN_FPTEST1ARG(FN, TYPE) \ extern void link_failure_builtin_##FN(void); \ extern void link_failure_builtin_##FN##f(void); \ extern void link_failure_builtin_##FN##l(void); \ void test_builtin_##FN(TYPE x) \ { if (__builtin_##FN(x) != __builtin_##FN(x)) link_failure_builtin_##FN(); } \ void test_builtin_##FN##f(TYPE x) \ { if (__builtin_##FN##f(x) != __builtin_##FN##f(x)) link_failure_builtin_##FN##f(); } \ void test_builtin_##FN##l(TYPE x) \ { if (__builtin_##FN##l(x) != __builtin_##FN##l(x)) link_failure_builtin_##FN##l(); } /* Test the __builtin_ functions taking two FP arguments (with the "f" and "l" variants). */ #define BUILTIN_FPTEST2(FN) \ extern void link_failure_builtin_##FN(void); \ extern void link_failure_builtin_##FN##f(void); \ extern void link_failure_builtin_##FN##l(void); \ void test_builtin_##FN(double d1, double d2) \ { if (__builtin_##FN(d1,d2) != __builtin_##FN(d1,d2)) link_failure_builtin_##FN(); } \ void test_builtin_##FN##f(float f1, float f2) \ { if (__builtin_##FN##f(f1,f2) != __builtin_##FN##f(f1,f2)) link_failure_builtin_##FN##f(); } \ void test_builtin_##FN##l(long double ld1, long double ld2) \ { if (__builtin_##FN##l(ld1,ld2) != __builtin_##FN##l(ld1,ld2)) link_failure_builtin_##FN##l(); } /* Test the __builtin_ functions taking two arguments, the first one is of a supplied type and the second one one is of FP type (with the "f" and "l" variants). */ #define BUILTIN_FPTEST2ARG1(FN, TYPE) \ extern void link_failure_builtin_##FN(void); \ extern void link_failure_builtin_##FN##f(void); \ extern void link_failure_builtin_##FN##l(void); \ void test_builtin_##FN(TYPE x, double d) \ { if (__builtin_##FN(x,d) != __builtin_##FN(x,d)) link_failure_builtin_##FN(); } \ void test_builtin_##FN##f(TYPE x, float f) \ { if (__builtin_##FN##f(x,f) != __builtin_##FN##f(x,f)) link_failure_builtin_##FN##f(); } \ void test_builtin_##FN##l(TYPE x, long double ld) \ { if (__builtin_##FN##l(x,ld) != __builtin_##FN##l(x,ld)) link_failure_builtin_##FN##l(); } /* Test the __builtin_ functions taking two arguments, the first one is of FP type and the second one one is of a supplied type (with the "f" and "l" variants). */ #define BUILTIN_FPTEST2ARG2(FN, TYPE) \ extern void link_failure_builtin_##FN(void); \ extern void link_failure_builtin_##FN##f(void); \ extern void link_failure_builtin_##FN##l(void); \ void test_builtin_##FN(double d, TYPE x) \ { if (__builtin_##FN(d,x) != __builtin_##FN(d,x)) link_failure_builtin_##FN(); } \ void test_builtin_##FN##f(float f, TYPE x) \ { if (__builtin_##FN##f(f,x) != __builtin_##FN##f(f,x)) link_failure_builtin_##FN##f(); } \ void test_builtin_##FN##l(long double ld, TYPE x) \ { if (__builtin_##FN##l(ld,x) != __builtin_##FN##l(ld,x)) link_failure_builtin_##FN##l(); } /* Test the __builtin_ functions taking three FP arguments (with the "f" and "l" variants). */ #define BUILTIN_FPTEST3(FN) \ extern void link_failure_builtin_##FN(void); \ extern void link_failure_builtin_##FN##f(void); \ extern void link_failure_builtin_##FN##l(void); \ void test_builtin_##FN(double d1, double d2, double d3) \ { if (__builtin_##FN(d1,d2,d3) != __builtin_##FN(d1,d2,d3)) link_failure_builtin_##FN(); } \ void test_builtin_##FN##f(float f1, float f2, float f3) \ { if (__builtin_##FN##f(f1,f2,f3) != __builtin_##FN##f(f1,f2,f3)) link_failure_builtin_##FN##f(); } \ void test_builtin_##FN##l(long double ld1, long double ld2, long double ld3) \ { if (__builtin_##FN##l(ld1,ld2,ld3) != __builtin_##FN##l(ld1,ld2,ld3)) link_failure_builtin_##FN##l(); } /* Test the __builtin_ functions taking one complex argument (with the "f" and "l" variants). */ #define BUILTIN_CPTEST1(FN) \ extern void link_failure_builtin_##FN(void); \ extern void link_failure_builtin_##FN##f(void); \ extern void link_failure_builtin_##FN##l(void); \ void test_builtin_##FN(_Complex double d) \ { if (__builtin_##FN(d) != __builtin_##FN(d)) link_failure_builtin_##FN(); } \ void test_builtin_##FN##f(_Complex float f) \ { if (__builtin_##FN##f(f) != __builtin_##FN##f(f)) link_failure_builtin_##FN##f(); } \ void test_builtin_##FN##l(_Complex long double ld) \ { if (__builtin_##FN##l(ld) != __builtin_##FN##l(ld)) link_failure_builtin_##FN##l(); } /* Test the __builtin_ functions taking two complex arguments (with the "f" and "l" variants). */ #define BUILTIN_CPTEST2(FN) \ extern void link_failure_builtin_##FN(void); \ extern void link_failure_builtin_##FN##f(void); \ extern void link_failure_builtin_##FN##l(void); \ void test_builtin_##FN(_Complex double d1, _Complex double d2) \ { if (__builtin_##FN(d1,d2) != __builtin_##FN(d1,d2)) link_failure_builtin_##FN(); } \ void test_builtin_##FN##f(_Complex float f1, _Complex float f2) \ { if (__builtin_##FN##f(f1,f2) != __builtin_##FN##f(f1,f2)) link_failure_builtin_##FN##f(); } \ void test_builtin_##FN##l(_Complex long double ld1, _Complex long double ld2) \ { if (__builtin_##FN##l(ld1,ld2) != __builtin_##FN##l(ld1,ld2)) link_failure_builtin_##FN##l(); } /* These macros additionally test the non-__builtin_ functions. */ /* Test the functions taking one FP argument (with the "f" and "l" variants) and returning that type. */ #define FPTEST1(FN) \ BUILTIN_FPTEST1(FN) \ extern void link_failure_##FN(void); \ extern void link_failure_##FN##f(void); \ extern void link_failure_##FN##l(void); \ extern double FN(double); \ extern float FN##f(float); \ extern long double FN##l(long double); \ void test_##FN(double d) \ { if (FN(d) != FN(d)) link_failure_##FN(); } \ void test_##FN##f(float f) \ { if (FN##f(f) != FN##f(f)) link_failure_##FN##f(); } \ void test_##FN##l(long double ld) \ { if (FN##l(ld) != FN##l(ld)) link_failure_##FN##l(); } /* Test the functions taking one FP argument (with the "f" and "l" variants) and returning TYPE. */ #define FPTEST1T(FN, TYPE) \ BUILTIN_FPTEST1(FN) \ extern void link_failure_##FN(void); \ extern void link_failure_##FN##f(void); \ extern void link_failure_##FN##l(void); \ extern TYPE FN(double); \ extern TYPE FN##f(float); \ extern TYPE FN##l(long double); \ void test_##FN(double d) \ { if (FN(d) != FN(d)) link_failure_##FN(); } \ void test_##FN##f(float f) \ { if (FN##f(f) != FN##f(f)) link_failure_##FN##f(); } \ void test_##FN##l(long double ld) \ { if (FN##l(ld) != FN##l(ld)) link_failure_##FN##l(); } /* Test the functions taking two FP arguments (with the "f" and "l" variants). */ #define FPTEST2(FN) \ BUILTIN_FPTEST2(FN) \ extern void link_failure_##FN(void); \ extern void link_failure_##FN##f(void); \ extern void link_failure_##FN##l(void); \ extern double FN(double, double); \ extern float FN##f(float, float); \ extern long double FN##l(long double, long double); \ void test_##FN(double d1, double d2) \ { if (FN(d1,d2) != FN(d1,d2)) link_failure_##FN(); } \ void test_##FN##f(float f1, float f2) \ { if (FN##f(f1,f2) != FN##f(f1,f2)) link_failure_##FN##f(); } \ void test_##FN##l(long double ld1, long double ld2) \ { if (FN##l(ld1,ld2) != FN##l(ld1,ld2)) link_failure_##FN##l(); } /* Test the functions taking two arguments, the first one is of a supplied type and the second one one is of FP type (with the "f" and "l" variants). */ #define FPTEST2ARG1(FN, TYPE) \ BUILTIN_FPTEST2ARG1(FN, TYPE) \ extern void link_failure_##FN(void); \ extern void link_failure_##FN##f(void); \ extern void link_failure_##FN##l(void); \ extern double FN(TYPE, double); \ extern float FN##f(TYPE, float); \ extern long double FN##l(TYPE, long double); \ void test_##FN(TYPE x, double d) \ { if (FN(x,d) != FN(x,d)) link_failure_##FN(); } \ void test_##FN##f(TYPE x, float f) \ { if (FN##f(x,f) != FN##f(x,f)) link_failure_##FN##f(); } \ void test_##FN##l(TYPE x, long double ld) \ { if (FN##l(x,ld) != FN##l(x,ld)) link_failure_##FN##l(); } /* Test the functions taking two arguments, the first one is of FP type and the second one one is of a supplied type (with the "f" and "l" variants). */ #define FPTEST2ARG2(FN, TYPE) \ BUILTIN_FPTEST2ARG2(FN, TYPE) \ extern void link_failure_##FN(void); \ extern void link_failure_##FN##f(void); \ extern void link_failure_##FN##l(void); \ extern double FN(double, TYPE); \ extern float FN##f(float, TYPE); \ extern long double FN##l(long double, TYPE); \ void test_##FN(double d, TYPE x) \ { if (FN(d,x) != FN(d,x)) link_failure_##FN(); } \ void test_##FN##f(float f, TYPE x) \ { if (FN##f(f,x) != FN##f(f,x)) link_failure_##FN##f(); } \ void test_##FN##l(long double ld, TYPE x) \ { if (FN##l(ld,x) != FN##l(ld,x)) link_failure_##FN##l(); } /* Test the functions taking three FP arguments (with the "f" and "l" variants). */ #define FPTEST3(FN) \ BUILTIN_FPTEST3(FN) \ extern void link_failure_##FN(void); \ extern void link_failure_##FN##f(void); \ extern void link_failure_##FN##l(void); \ extern double FN(double, double, double); \ extern float FN##f(float, float, float); \ extern long double FN##l(long double, long double, long double); \ void test_##FN(double d1, double d2, double d3) \ { if (FN(d1,d2,d3) != FN(d1,d2,d3)) link_failure_##FN(); } \ void test_##FN##f(float f1, float f2, float f3) \ { if (FN##f(f1,f2,f3) != FN##f(f1,f2,f3)) link_failure_##FN##f(); } \ void test_##FN##l(long double ld1, long double ld2, long double ld3) \ { if (FN##l(ld1,ld2,ld3) != FN##l(ld1,ld2,ld3)) link_failure_##FN##l(); } /* Test the functions taking one complex argument (with the "f" and "l" variants) and returning that type. */ #define CPTEST1(FN) \ BUILTIN_CPTEST1(FN) \ extern void link_failure_##FN(void); \ extern void link_failure_##FN##f(void); \ extern void link_failure_##FN##l(void); \ extern _Complex double FN(_Complex double); \ extern _Complex float FN##f(_Complex float); \ extern _Complex long double FN##l(_Complex long double); \ void test_##FN(_Complex double d) \ { if (FN(d) != FN(d)) link_failure_##FN(); } \ void test_##FN##f(_Complex float f) \ { if (FN##f(f) != FN##f(f)) link_failure_##FN##f(); } \ void test_##FN##l(_Complex long double ld) \ { if (FN##l(ld) != FN##l(ld)) link_failure_##FN##l(); } /* Test the functions taking one complex argument (with the "f" and "l" variants) and returning the real type. */ #define CPTEST1R(FN) \ BUILTIN_CPTEST1(FN) \ extern void link_failure_##FN(void); \ extern void link_failure_##FN##f(void); \ extern void link_failure_##FN##l(void); \ extern double FN(_Complex double); \ extern float FN##f(_Complex float); \ extern long double FN##l(_Complex long double); \ void test_##FN(_Complex double d) \ { if (FN(d) != FN(d)) link_failure_##FN(); } \ void test_##FN##f(_Complex float f) \ { if (FN##f(f) != FN##f(f)) link_failure_##FN##f(); } \ void test_##FN##l(_Complex long double ld) \ { if (FN##l(ld) != FN##l(ld)) link_failure_##FN##l(); } /* Test the functions taking two complex arguments (with the "f" and "l" variants). */ #define CPTEST2(FN) \ BUILTIN_CPTEST2(FN) \ extern void link_failure_##FN(void); \ extern void link_failure_##FN##f(void); \ extern void link_failure_##FN##l(void); \ extern _Complex double FN(_Complex double, _Complex double); \ extern _Complex float FN##f(_Complex float, _Complex float); \ extern _Complex long double FN##l(_Complex long double, _Complex long double); \ void test_##FN(_Complex double d1, _Complex double d2) \ { if (FN(d1,d2) != FN(d1,d2)) link_failure_##FN(); } \ void test_##FN##f(_Complex float f1, _Complex float f2) \ { if (FN##f(f1,f2) != FN##f(f1,f2)) link_failure_##FN##f(); } \ void test_##FN##l(_Complex long double ld1, _Complex long double ld2) \ { if (FN##l(ld1,ld2) != FN##l(ld1,ld2)) link_failure_##FN##l(); } /* Test the math builtins. */ FPTEST1 (acos) FPTEST1 (acosh) FPTEST1 (asin) FPTEST1 (asinh) FPTEST1 (atan) FPTEST2 (atan2) FPTEST1 (atanh) FPTEST1 (cbrt) FPTEST1 (ceil) FPTEST2 (copysign) FPTEST1 (cos) FPTEST1 (cosh) FPTEST2 (drem) FPTEST1 (erf) FPTEST1 (erfc) FPTEST1 (exp) FPTEST1 (exp10) FPTEST1 (exp2) FPTEST1 (expm1) FPTEST1 (fabs) FPTEST2 (fdim) FPTEST1 (floor) FPTEST3 (fma) FPTEST2 (fmax) FPTEST2 (fmin) FPTEST2 (fmod) BUILTIN_FPTEST0 (huge_val) FPTEST2 (hypot) FPTEST1T (ilogb, int) BUILTIN_FPTEST0 (inf) /* { dg-warning "does not support infinity" "INF unsupported" { target vax-*-* pdp11-*-* spu-*-* } } */ FPTEST1 (j0) FPTEST1 (j1) FPTEST2ARG1 (jn, int) FPTEST2ARG2 (ldexp, int) BUILTIN_FPTEST1 (llceil) BUILTIN_FPTEST1 (llfloor) FPTEST1T (llrint, long long) FPTEST1T (llround, long long) FPTEST1 (log) FPTEST1 (log10) FPTEST1 (log1p) FPTEST1 (log2) FPTEST1 (logb) BUILTIN_FPTEST1 (lceil) BUILTIN_FPTEST1 (lfloor) FPTEST1T (lrint, long) FPTEST1T (lround, long) BUILTIN_FPTEST1ARG (nan, char *) BUILTIN_FPTEST1ARG (nans, char *) FPTEST1 (nearbyint) FPTEST2 (nextafter) FPTEST2ARG2 (nexttoward, long double) FPTEST2 (pow) FPTEST1 (pow10) FPTEST2 (remainder) FPTEST1 (rint) FPTEST1 (round) FPTEST2 (scalb) FPTEST2ARG2 (scalbn, int) FPTEST2ARG2 (scalbln, long int) FPTEST1 (significand) FPTEST1 (sin) FPTEST1 (sinh) FPTEST1 (sqrt) FPTEST1 (tan) FPTEST1 (tanh) FPTEST1 (tgamma) FPTEST1 (trunc) FPTEST1 (y0) FPTEST1 (y1) FPTEST2ARG1 (yn, int) /* Test the complex math builtins. */ /*CPTEST1 (cabs) See http://gcc.gnu.org/ml/gcc-patches/2003-09/msg00040.html */ CPTEST1 (cacos) CPTEST1 (cacosh) CPTEST1R (carg) CPTEST1 (casin) CPTEST1 (casinh) CPTEST1 (catan) CPTEST1 (catanh) CPTEST1 (ccos) CPTEST1 (ccosh) CPTEST1 (cexp) CPTEST1R (cimag) CPTEST1 (clog) CPTEST1 (conj) CPTEST2 (cpow) CPTEST1 (cproj) CPTEST1R (creal) CPTEST1 (csin) CPTEST1 (csinh) CPTEST1 (csqrt) CPTEST1 (ctan) CPTEST1 (ctanh) typedef __INTMAX_TYPE__ intmax_t; /* Various other const builtins. */ TEST1 (abs, int, int) BUILTIN_TEST1 (clz, int) BUILTIN_TEST1 (clzl, long) BUILTIN_TEST1 (clzll, long long) BUILTIN_TEST1 (ctz, int) BUILTIN_TEST1 (ctzl, long) BUILTIN_TEST1 (ctzll, long long) BUILTIN_TEST1 (clrsb, int) BUILTIN_TEST1 (clrsbl, long) BUILTIN_TEST1 (clrsbll, long long) TEST1 (ffs, int, int) TEST1 (ffsl, long, int) TEST1 (ffsll, long long, int) TEST1 (imaxabs, intmax_t, intmax_t) TEST1 (labs, long, long) TEST1 (llabs, long long, long long) BUILTIN_TEST1 (parity, int) BUILTIN_TEST1 (parityl, long) BUILTIN_TEST1 (parityll, long long) BUILTIN_TEST1 (popcount, int) BUILTIN_TEST1 (popcountl, long) BUILTIN_TEST1 (popcountll, long long) int main(void) { return 0; }
the_stack_data/132953605.c
#include <sys/time.h> #include <sys/types.h> #include <sys/times.h> #include <unistd.h> static double timetick; static double tstart = 0.0; static double ucpustart = 0.0; static int first = 1; void reloj (double *elapsed, double *ucpu) { struct tms cpu; struct timeval tp; // struct timezone tzp; if(first) { /* Initialize clock */ timetick = 1.0 / (double)(sysconf(_SC_CLK_TCK)); first = 0; gettimeofday(&tp, NULL); // gettimeofday(&tp, &tzp); tstart = (double)tp.tv_sec + (double)tp.tv_usec * 1.0e-6; /* Initialize CPU time */ times(&cpu); ucpustart = (double)(cpu.tms_utime + cpu.tms_cutime) * timetick; /* Return values */ *elapsed = 0.0e0; *ucpu = 0.0e0; } else { /* Get clock time */ gettimeofday(&tp, NULL); // gettimeofday(&tp, &tzp); *elapsed = (double)tp.tv_sec + (double)tp.tv_usec * 1.0e-6 - tstart; /* Get CPU time */ times(&cpu); *ucpu = (double)(cpu.tms_utime + cpu.tms_cutime) * timetick - ucpustart; } return; }
the_stack_data/40761445.c
/* This file was autogenerated by raw2c. Visit http://www.devkitpro.org */ const unsigned char logo[] = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x01, 0x60, 0x00, 0x00, 0x00, 0x5c, 0x08, 0x06, 0x00, 0x00, 0x00, 0x50, 0xae, 0x6f, 0x2e, 0x00, 0x00, 0x00, 0x01, 0x73, 0x52, 0x47, 0x42, 0x00, 0xae, 0xce, 0x1c, 0xe9, 0x00, 0x00, 0x02, 0x28, 0x49, 0x44, 0x41, 0x54, 0x78, 0xda, 0xed, 0xdd, 0x4b, 0x8e, 0xa4, 0x30, 0x10, 0x40, 0x41, 0x68, 0x71, 0xff, 0x2b, 0xd3, 0x37, 0x28, 0x23, 0x8c, 0x95, 0x1f, 0x47, 0xec, 0x7b, 0xaa, 0x4c, 0x99, 0x37, 0x2c, 0x52, 0xe6, 0x38, 0x00, 0x08, 0x71, 0xae, 0xfc, 0xc7, 0xef, 0xfb, 0xbe, 0xdb, 0x5c, 0xa8, 0xf3, 0x3c, 0xbb, 0xac, 0xf3, 0xd7, 0x5a, 0x3a, 0xfd, 0x9e, 0x6f, 0xd7, 0xb9, 0x72, 0xad, 0x33, 0xdf, 0xa9, 0xd2, 0x3d, 0xea, 0x7e, 0x79, 0xe6, 0xcf, 0xff, 0x41, 0x00, 0x31, 0x04, 0x18, 0x40, 0x80, 0x01, 0x04, 0x18, 0x00, 0x01, 0x06, 0x10, 0x60, 0x00, 0x3e, 0x36, 0x35, 0x5e, 0x31, 0x1a, 0x27, 0xc9, 0x36, 0x72, 0xb3, 0x6a, 0xad, 0xd5, 0xd6, 0xf9, 0x76, 0x0c, 0x68, 0x97, 0x75, 0xae, 0x5c, 0x6b, 0xc4, 0x3e, 0xda, 0xe5, 0x33, 0x2b, 0xde, 0xfb, 0x9e, 0x80, 0x01, 0x82, 0x08, 0x30, 0x80, 0x00, 0x03, 0x08, 0x30, 0x00, 0x02, 0x0c, 0x20, 0xc0, 0x00, 0x7c, 0x6c, 0x38, 0x42, 0x31, 0x33, 0x82, 0xe1, 0x34, 0xb4, 0x7a, 0x6b, 0xe9, 0xf4, 0x7b, 0x56, 0x3b, 0x0d, 0xed, 0xed, 0xbd, 0x36, 0x33, 0x0e, 0xea, 0x34, 0xb4, 0xb5, 0x6b, 0x19, 0xed, 0x41, 0x4f, 0xc0, 0x00, 0x41, 0x04, 0x18, 0x40, 0x80, 0x01, 0x04, 0x18, 0x00, 0x01, 0x06, 0x10, 0x60, 0x00, 0x04, 0x18, 0xa0, 0x87, 0xeb, 0x38, 0xd6, 0xcd, 0x1f, 0x92, 0x53, 0xa7, 0xa3, 0x02, 0xad, 0x93, 0xcc, 0xfb, 0x68, 0xf4, 0xb7, 0x9e, 0x80, 0x01, 0x82, 0x08, 0x30, 0x80, 0x00, 0x03, 0x08, 0x30, 0x00, 0x02, 0x0c, 0x20, 0xc0, 0x00, 0x7c, 0xec, 0xca, 0xf8, 0xa5, 0x8c, 0x08, 0x8d, 0xaf, 0xc3, 0x2e, 0x47, 0x7d, 0x76, 0x5b, 0x2b, 0xee, 0x17, 0x4f, 0xc0, 0x00, 0x02, 0x0c, 0x20, 0xc0, 0x00, 0x08, 0x30, 0x80, 0x00, 0x03, 0x20, 0xc0, 0x00, 0xfd, 0x5c, 0x15, 0xbf, 0x74, 0xc4, 0x48, 0x49, 0xc4, 0x68, 0x5c, 0xc4, 0x1b, 0x6b, 0x3b, 0xfd, 0x9e, 0xc6, 0x19, 0xf7, 0x92, 0xf1, 0x0d, 0xcf, 0xde, 0x8a, 0x0c, 0x90, 0x94, 0x00, 0x03, 0x08, 0x30, 0x80, 0x00, 0x03, 0x20, 0xc0, 0x00, 0x02, 0x0c, 0x80, 0x00, 0x03, 0xf4, 0x70, 0xb9, 0x04, 0xfb, 0xf1, 0x56, 0xe4, 0x7a, 0xeb, 0x74, 0x24, 0x67, 0xcd, 0x7d, 0xe4, 0xad, 0xc8, 0x00, 0x49, 0x09, 0x30, 0x80, 0x00, 0x03, 0x08, 0x30, 0x00, 0x02, 0x0c, 0x20, 0xc0, 0x00, 0x7c, 0xac, 0xe4, 0x18, 0x9a, 0xb7, 0x05, 0x7b, 0x2b, 0x72, 0x47, 0x8e, 0xcf, 0xdc, 0xef, 0x7e, 0xf1, 0x04, 0x0c, 0x20, 0xc0, 0x00, 0x02, 0x0c, 0x80, 0x00, 0x03, 0x08, 0x30, 0x00, 0x02, 0x0c, 0xd0, 0x43, 0xca, 0x31, 0x34, 0x27, 0x3f, 0xd1, 0xd5, 0x2e, 0x6f, 0xf4, 0xd6, 0x0d, 0x4f, 0xc0, 0x00, 0x02, 0x0c, 0x80, 0x00, 0x03, 0x08, 0x30, 0x80, 0x00, 0x03, 0x20, 0xc0, 0x00, 0x02, 0x0c, 0xc0, 0x72, 0x53, 0x73, 0xc0, 0x9d, 0x8e, 0x11, 0x74, 0x14, 0x20, 0x4f, 0xf7, 0x83, 0x39, 0x75, 0x7b, 0xe1, 0xe9, 0x5e, 0x18, 0x75, 0xc5, 0x13, 0x30, 0x40, 0x10, 0x01, 0x06, 0x10, 0x60, 0x00, 0x01, 0x06, 0x40, 0x80, 0x01, 0x04, 0x18, 0x80, 0x8f, 0x0d, 0x47, 0xaf, 0x66, 0xc7, 0x2c, 0xaa, 0x98, 0x19, 0x2d, 0x5a, 0x75, 0x0d, 0x7e, 0x7d, 0xa7, 0x5d, 0x3e, 0x73, 0xd5, 0xe7, 0x66, 0xfc, 0xbd, 0x23, 0xf6, 0x76, 0xa7, 0x7d, 0x54, 0xf1, 0xfa, 0x79, 0x02, 0x06, 0x08, 0x22, 0xc0, 0x00, 0x02, 0x0c, 0x20, 0xc0, 0x00, 0x08, 0x30, 0x80, 0x00, 0x03, 0xf0, 0xb1, 0xe9, 0x71, 0x90, 0x2e, 0x27, 0x43, 0xcd, 0x8c, 0x93, 0xac, 0xba, 0x06, 0x11, 0x27, 0x72, 0x65, 0xfb, 0xcc, 0x55, 0x9f, 0x9b, 0xf1, 0xf7, 0x8e, 0xd8, 0xdb, 0x9d, 0xf6, 0x51, 0xc6, 0x36, 0x78, 0x02, 0x06, 0x48, 0x4a, 0x80, 0x01, 0x04, 0x18, 0x40, 0x80, 0x01, 0x10, 0x60, 0x00, 0x01, 0x06, 0x40, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x78, 0xe8, 0x1f, 0x87, 0x2a, 0x18, 0xc9, 0xe4, 0xf5, 0x50, 0x98, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82 }; const int logo_size = sizeof(logo);
the_stack_data/200144263.c
#include <stdio.h> int main() { int X = 0, Z = 0, contador = 1, guardavalor = 0; scanf("%d", &X); // 3 scanf("%d", &Z); // 5 if (X > Z) { while (X >= Z) { scanf("%d", &Z); // 20 } guardavalor = X + 1; // 4 while (X < Z) { X = X + guardavalor; // X = 3 + 4 // 7+5+6+7 guardavalor = guardavalor + 1; // 4 contador++; } printf("%d\n", contador); } else { printf("0"); } return 0; }
the_stack_data/87637360.c
// RUN: clang-cc -fsyntax-only -verify %s typedef float __attribute__((vector_size (16))) v4f_t; typedef union { struct { float x, y, z, w; }s; v4f_t v; } vector_t; vector_t foo(v4f_t p) { vector_t v = {.v = p}; return v; }
the_stack_data/6388110.c
#include <stdio.h> #include <stdlib.h> #include <math.h> #define MAXSIZE 254 #define DIMENTION 15 #define NUMOFFILE 100 #define FNAME_OUTPUT "./output001.txt" typedef struct { char name[20]; char onso[50]; int flame; double mcepdata[MAXSIZE][DIMENTION]; } mcepdata_t; int main(void) { int h0, h, i, j, k; FILE *fp_temp, *fp_miti, *fp_output; mcepdata_t city_temp, city_miti; //テンプレートのデータと未知入力データ char ch0[200]; double d[MAXSIZE][MAXSIZE]; //局所距離 double g[MAXSIZE][MAXSIZE]; //累積距離 double tangokankyori[NUMOFFILE]; //単語間距離 double tangokankyori_min; int num_matchfname = 0; int count = 0; int TEMP_NUM, MITI_NUM; printf("ファイルを選択してください\n"); printf("city0"); scanf("%03d", &TEMP_NUM); printf("city0"); scanf("%03d", &MITI_NUM); printf("city%03dとcity%03dの認識実験を開始します。\n", TEMP_NUM, MITI_NUM); for (h0 = 0; h0 < NUMOFFILE; h0++) { sprintf(ch0, "./city%03d/city%03d_%03d.txt",TEMP_NUM, TEMP_NUM, h0 + 1); if ((fp_temp = fopen(ch0, "r")) == NULL) { printf("temp file open error!!\n"); exit(EXIT_FAILURE); } fgets(city_temp.name, sizeof(city_temp.name), fp_temp); fgets(city_temp.onso, sizeof(city_temp.onso), fp_temp); fgets(ch0,sizeof(ch0), fp_temp); city_temp.flame = atoi(ch0); for (i = 0; i < city_temp.flame; i++) { for (j = 0; j < DIMENTION; j++) { fscanf(fp_temp, "%lf", &city_temp.mcepdata[i][j]); } } for (h = 0; h < NUMOFFILE; h++) { sprintf(ch0, "./city%03d/city%03d_%03d.txt",MITI_NUM, MITI_NUM, h + 1); if ((fp_miti = fopen(ch0, "r")) == NULL) { printf("miti file open error!!\n"); exit(EXIT_FAILURE); } fgets(city_miti.name, sizeof(city_miti.name), fp_miti); fgets(city_miti.onso, sizeof(city_miti.onso), fp_miti); fgets(ch0,sizeof(ch0), fp_miti); city_miti.flame = atoi(ch0); for (i = 0; i < city_miti.flame; i++) { for (j = 0; j < DIMENTION; j++) { fscanf(fp_miti, "%lf", &city_miti.mcepdata[i][j]); } } for (i = 0; i < city_temp.flame; i++) { for (j = 0; j < city_miti.flame; j++) { d[i][j] = 0; for (int k = 0; k < DIMENTION; k++) { //printf("%f\n", kyokusyokyori); d[i][j] += (city_temp.mcepdata[i][k] - city_miti.mcepdata[j][k]) * (city_temp.mcepdata[i][k] - city_miti.mcepdata[j][k]); } sqrtl(d[i][j]); } } g[0][0] = d[0][0]; for (i = 1; i < city_temp.flame; i++) { g[i][0] = g[i - 1][0] + d[i][0]; } for (j = 1; j < city_miti.flame; j++) { g[0][j] = g[0][j - 1] + d[0][j]; } for (i = 1; i < city_temp.flame; i++) { for (j = 1; j < city_miti.flame; j++) { double a = g[i][j - 1] + d[i][j]; double b = g[i - 1][j - 1] + 2 * d[i][j]; double c = g[i - 1][j] + d[i][j]; g[i][j] = a; if (b < g[i][j]) { g[i][j] = b; } if (c < g[i][j]) { g[i][j] = c; } } } tangokankyori[h] = g[city_temp.flame - 1][city_miti.flame - 1] / (city_temp.flame + city_miti.flame); fclose(fp_miti); } tangokankyori_min = tangokankyori[0]; num_matchfname = 0; for (h = 1; h < NUMOFFILE; h++) { if (tangokankyori_min > tangokankyori[h] ) { tangokankyori_min = tangokankyori[h]; num_matchfname = h; } } fclose(fp_temp); if (num_matchfname == h0 ) { count++; } if (num_matchfname != h0 ) { printf("----------Result NOT Matchng----------\n"); printf("city_temp : city%03d/city%03d_%03d.txt\n", TEMP_NUM, TEMP_NUM, h0 + 1); printf("city_miti : city%03d/city%03d_%03d.txt\n", MITI_NUM, MITI_NUM, num_matchfname + 1); printf("tangokankyori : %f\n", tangokankyori_min); } } sprintf(ch0, FNAME_OUTPUT); if ((fp_output = fopen(ch0, "a")) == NULL) { printf("output file open error!!\n"); exit(EXIT_FAILURE); } fprintf(fp_output, "正答率%d%%です。\n", count); printf("\nファイルを作成しました。\n"); printf("正答率 %d%% です。\n", count); fclose(fp_output); return 0; }
the_stack_data/45451397.c
/* ************************************************ username : smmehrab fullname : s.m.mehrabul islam email : [email protected] institute : university of dhaka, bangladesh session : 2017-2018 ************************************************ */ #include<stdio.h> void swap(int* a, int* b) { int t = *a; *a = *b; *b = t; } int partition (int arr[], int low, int high) { int pivot = arr[high]; int i = (low - 1); int j; for(j = low; j <= high- 1; j++) { if (arr[j] <= pivot) { i++; swap(&arr[i], &arr[j]); } } swap(&arr[i + 1], &arr[high]); return (i + 1); } void quickSort(int arr[], int low, int high) { if (low < high) { int pi = partition(arr, low, high); quickSort(arr, low, pi - 1); quickSort(arr, pi + 1, high); } } void printArray(int arr[], int size) { int i; for (i=0; i < size; i++) printf("%d ", arr[i]); printf("\n"); } int scanArray(int arr[], int size) { int i; for (i=0; i < size; i++) scanf("%d", &arr[i]); return *arr; } int main() { int size; scanf("%d",&size); int arr[size]; scanArray(arr,size); quickSort(arr, 0, size-1); printArray(arr, size); return 0; }
the_stack_data/838324.c
/* test/igetest.c -*- mode:C; c-file-style: "eay" -*- */ /* ==================================================================== * Copyright (c) 2006 The OpenSSL 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: * * 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. All advertising materials mentioning features or use of this * software must display the following acknowledgment: * "This product includes software developed by the OpenSSL Project * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" * * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to * endorse or promote products derived from this software without * prior written permission. For written permission, please contact * [email protected]. * * 5. Products derived from this software may not be called "OpenSSL" * nor may "OpenSSL" appear in their names without prior written * permission of the OpenSSL Project. * * 6. Redistributions of any form whatsoever must retain the following * acknowledgment: * "This product includes software developed by the OpenSSL Project * for use in the OpenSSL Toolkit (http://www.openssl.org/)" * * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY * EXPRESSED 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 OpenSSL PROJECT OR * ITS 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 <openssl/aes.h> #include <openssl/rand.h> #include <stdio.h> #include <string.h> #include <assert.h> #define TEST_SIZE 128 #define BIG_TEST_SIZE 10240 static void hexdump(FILE *f,const char *title,const unsigned char *s,int l) { int n=0; fprintf(f,"%s",title); for( ; n < l ; ++n) { if((n%16) == 0) fprintf(f,"\n%04x",n); fprintf(f," %02x",s[n]); } fprintf(f,"\n"); } #define MAX_VECTOR_SIZE 64 struct ige_test { const unsigned char key[16]; const unsigned char iv[32]; const unsigned char in[MAX_VECTOR_SIZE]; const unsigned char out[MAX_VECTOR_SIZE]; const size_t length; const int encrypt; }; static struct ige_test const ige_test_vectors[] = { { { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, /* key */ { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f }, /* iv */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* in */ { 0x1a, 0x85, 0x19, 0xa6, 0x55, 0x7b, 0xe6, 0x52, 0xe9, 0xda, 0x8e, 0x43, 0xda, 0x4e, 0xf4, 0x45, 0x3c, 0xf4, 0x56, 0xb4, 0xca, 0x48, 0x8a, 0xa3, 0x83, 0xc7, 0x9c, 0x98, 0xb3, 0x47, 0x97, 0xcb }, /* out */ 32, AES_ENCRYPT }, /* test vector 0 */ { { 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x61, 0x6e, 0x20, 0x69, 0x6d, 0x70, 0x6c, 0x65 }, /* key */ { 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x49, 0x47, 0x45, 0x20, 0x6d, 0x6f, 0x64, 0x65, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x4f, 0x70, 0x65, 0x6e, 0x53, 0x53 }, /* iv */ { 0x4c, 0x2e, 0x20, 0x4c, 0x65, 0x74, 0x27, 0x73, 0x20, 0x68, 0x6f, 0x70, 0x65, 0x20, 0x42, 0x65, 0x6e, 0x20, 0x67, 0x6f, 0x74, 0x20, 0x69, 0x74, 0x20, 0x72, 0x69, 0x67, 0x68, 0x74, 0x21, 0x0a }, /* in */ { 0x99, 0x70, 0x64, 0x87, 0xa1, 0xcd, 0xe6, 0x13, 0xbc, 0x6d, 0xe0, 0xb6, 0xf2, 0x4b, 0x1c, 0x7a, 0xa4, 0x48, 0xc8, 0xb9, 0xc3, 0x40, 0x3e, 0x34, 0x67, 0xa8, 0xca, 0xd8, 0x93, 0x40, 0xf5, 0x3b }, /* out */ 32, AES_DECRYPT }, /* test vector 1 */ }; static int run_test_vectors(void) { unsigned int n; int errs = 0; for(n=0 ; n < sizeof(ige_test_vectors)/sizeof(ige_test_vectors[0]) ; ++n) { const struct ige_test * const v = &ige_test_vectors[n]; AES_KEY key; unsigned char buf[MAX_VECTOR_SIZE]; unsigned char iv[AES_BLOCK_SIZE*2]; assert(v->length <= MAX_VECTOR_SIZE); if(v->encrypt == AES_ENCRYPT) AES_set_encrypt_key(v->key, 8*sizeof v->key, &key); else AES_set_decrypt_key(v->key, 8*sizeof v->key, &key); memcpy(iv, v->iv, sizeof iv); AES_ige_encrypt(v->in, buf, v->length, &key, iv, v->encrypt); if(memcmp(v->out, buf, v->length)) { printf("IGE test vector %d failed\n", n); hexdump(stdout, "key", v->key, sizeof v->key); hexdump(stdout, "iv", v->iv, sizeof v->iv); hexdump(stdout, "in", v->in, v->length); hexdump(stdout, "expected", v->out, v->length); hexdump(stdout, "got", buf, v->length); ++errs; } /* try with in == out */ memcpy(iv, v->iv, sizeof iv); memcpy(buf, v->in, v->length); AES_ige_encrypt(buf, buf, v->length, &key, iv, v->encrypt); if(memcmp(v->out, buf, v->length)) { printf("IGE test vector %d failed (with in == out)\n", n); hexdump(stdout, "key", v->key, sizeof v->key); hexdump(stdout, "iv", v->iv, sizeof v->iv); hexdump(stdout, "in", v->in, v->length); hexdump(stdout, "expected", v->out, v->length); hexdump(stdout, "got", buf, v->length); ++errs; } } return errs; } int main(int argc, char **argv) { unsigned char rkey[16]; unsigned char rkey2[16]; AES_KEY key; AES_KEY key2; unsigned char plaintext[BIG_TEST_SIZE]; unsigned char ciphertext[BIG_TEST_SIZE]; unsigned char checktext[BIG_TEST_SIZE]; unsigned char iv[AES_BLOCK_SIZE*4]; unsigned char saved_iv[AES_BLOCK_SIZE*4]; int err = 0; unsigned int n; unsigned matches; assert(BIG_TEST_SIZE >= TEST_SIZE); RAND_pseudo_bytes(rkey, sizeof rkey); RAND_pseudo_bytes(plaintext, sizeof plaintext); RAND_pseudo_bytes(iv, sizeof iv); memcpy(saved_iv, iv, sizeof saved_iv); /* Forward IGE only... */ /* Straight encrypt/decrypt */ AES_set_encrypt_key(rkey, 8*sizeof rkey, &key); AES_ige_encrypt(plaintext, ciphertext, TEST_SIZE, &key, iv, AES_ENCRYPT); AES_set_decrypt_key(rkey, 8*sizeof rkey, &key); memcpy(iv, saved_iv, sizeof iv); AES_ige_encrypt(ciphertext, checktext, TEST_SIZE, &key, iv, AES_DECRYPT); if(memcmp(checktext, plaintext, TEST_SIZE)) { printf("Encrypt+decrypt doesn't match\n"); hexdump(stdout, "Plaintext", plaintext, TEST_SIZE); hexdump(stdout, "Checktext", checktext, TEST_SIZE); ++err; } /* Now check encrypt chaining works */ AES_set_encrypt_key(rkey, 8*sizeof rkey, &key); memcpy(iv, saved_iv, sizeof iv); AES_ige_encrypt(plaintext, ciphertext, TEST_SIZE/2, &key, iv, AES_ENCRYPT); AES_ige_encrypt(plaintext+TEST_SIZE/2, ciphertext+TEST_SIZE/2, TEST_SIZE/2, &key, iv, AES_ENCRYPT); AES_set_decrypt_key(rkey, 8*sizeof rkey, &key); memcpy(iv, saved_iv, sizeof iv); AES_ige_encrypt(ciphertext, checktext, TEST_SIZE, &key, iv, AES_DECRYPT); if(memcmp(checktext, plaintext, TEST_SIZE)) { printf("Chained encrypt+decrypt doesn't match\n"); hexdump(stdout, "Plaintext", plaintext, TEST_SIZE); hexdump(stdout, "Checktext", checktext, TEST_SIZE); ++err; } /* And check decrypt chaining */ AES_set_encrypt_key(rkey, 8*sizeof rkey, &key); memcpy(iv, saved_iv, sizeof iv); AES_ige_encrypt(plaintext, ciphertext, TEST_SIZE/2, &key, iv, AES_ENCRYPT); AES_ige_encrypt(plaintext+TEST_SIZE/2, ciphertext+TEST_SIZE/2, TEST_SIZE/2, &key, iv, AES_ENCRYPT); AES_set_decrypt_key(rkey, 8*sizeof rkey, &key); memcpy(iv, saved_iv, sizeof iv); AES_ige_encrypt(ciphertext, checktext, TEST_SIZE/2, &key, iv, AES_DECRYPT); AES_ige_encrypt(ciphertext+TEST_SIZE/2, checktext+TEST_SIZE/2, TEST_SIZE/2, &key, iv, AES_DECRYPT); if(memcmp(checktext, plaintext, TEST_SIZE)) { printf("Chained encrypt+chained decrypt doesn't match\n"); hexdump(stdout, "Plaintext", plaintext, TEST_SIZE); hexdump(stdout, "Checktext", checktext, TEST_SIZE); ++err; } /* make sure garble extends forwards only */ AES_set_encrypt_key(rkey, 8*sizeof rkey, &key); memcpy(iv, saved_iv, sizeof iv); AES_ige_encrypt(plaintext, ciphertext, sizeof plaintext, &key, iv, AES_ENCRYPT); /* corrupt halfway through */ ++ciphertext[sizeof ciphertext/2]; AES_set_decrypt_key(rkey, 8*sizeof rkey, &key); memcpy(iv, saved_iv, sizeof iv); AES_ige_encrypt(ciphertext, checktext, sizeof checktext, &key, iv, AES_DECRYPT); matches=0; for(n=0 ; n < sizeof checktext ; ++n) if(checktext[n] == plaintext[n]) ++matches; if(matches > sizeof checktext/2+sizeof checktext/100) { printf("More than 51%% matches after garbling\n"); ++err; } if(matches < sizeof checktext/2) { printf("Garble extends backwards!\n"); ++err; } /* make sure garble extends both ways */ AES_set_encrypt_key(rkey, 8*sizeof rkey, &key); AES_set_encrypt_key(rkey2, 8*sizeof rkey2, &key2); AES_ige_encrypt(plaintext, ciphertext, sizeof plaintext, &key, iv, AES_ENCRYPT); /* corrupt halfway through */ ++ciphertext[sizeof ciphertext/2]; AES_set_decrypt_key(rkey, 8*sizeof rkey, &key); AES_set_decrypt_key(rkey2, 8*sizeof rkey2, &key2); AES_ige_encrypt(ciphertext, checktext, sizeof checktext, &key, iv, AES_DECRYPT); matches=0; for(n=0 ; n < sizeof checktext ; ++n) if(checktext[n] == plaintext[n]) ++matches; if(matches > sizeof checktext/100) { printf("More than 1%% matches after bidirectional garbling\n"); ++err; } /* make sure garble extends both ways (2) */ AES_set_encrypt_key(rkey, 8*sizeof rkey, &key); AES_set_encrypt_key(rkey2, 8*sizeof rkey2, &key2); AES_ige_encrypt(plaintext, ciphertext, sizeof plaintext, &key, iv, AES_ENCRYPT); /* corrupt right at the end */ ++ciphertext[sizeof ciphertext-1]; AES_set_decrypt_key(rkey, 8*sizeof rkey, &key); AES_set_decrypt_key(rkey2, 8*sizeof rkey2, &key2); AES_ige_encrypt(ciphertext, checktext, sizeof checktext, &key, iv, AES_DECRYPT); matches=0; for(n=0 ; n < sizeof checktext ; ++n) if(checktext[n] == plaintext[n]) ++matches; if(matches > sizeof checktext/100) { printf("More than 1%% matches after bidirectional garbling (2)\n"); ++err; } /* make sure garble extends both ways (3) */ AES_set_encrypt_key(rkey, 8*sizeof rkey, &key); AES_set_encrypt_key(rkey2, 8*sizeof rkey2, &key2); AES_ige_encrypt(plaintext, ciphertext, sizeof plaintext, &key, iv, AES_ENCRYPT); /* corrupt right at the start */ ++ciphertext[0]; AES_set_decrypt_key(rkey, 8*sizeof rkey, &key); AES_set_decrypt_key(rkey2, 8*sizeof rkey2, &key2); AES_ige_encrypt(ciphertext, checktext, sizeof checktext, &key, iv, AES_DECRYPT); matches=0; for(n=0 ; n < sizeof checktext ; ++n) if(checktext[n] == plaintext[n]) ++matches; if(matches > sizeof checktext/100) { printf("More than 1%% matches after bidirectional garbling (3)\n"); ++err; } err += run_test_vectors(); return err; }
the_stack_data/248582136.c
// Test strict_string_checks option in strchr function // RUN: %clang_asan %s -o %t && %run %t 2>&1 // RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false %run %t 2>&1 // RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=true not %run %t 2>&1 | FileCheck %s #include <assert.h> #include <stdlib.h> #include <string.h> int main(int argc, char **argv) { size_t size = 100; char fill = 'o'; char *s = (char*)malloc(size); memset(s, fill, size); char c = 'o'; char* r = strchr(s, c); // CHECK: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}} // CHECK: READ of size 101 assert(r == s); free(s); return 0; }
the_stack_data/25649.c
/* This used to fail on H8/300 due to incorrect specification of pushi1. */ /* { dg-do run } */ /* { dg-options "-O2" } */ /* { dg-options "-O2 -fomit-frame-pointer" { target h8300-*-* } } */ extern void abort (void); extern void exit (int); void bar (int a, int b, int c, int d, int e) { if (d != 1) abort (); } void foo (int a, int b, int c, int d, int e) { bar (a, b, c, d, e); } int main () { foo (0, 0, 0, 1, 2); exit (0); }
the_stack_data/181394145.c
#include<stdio.h> #include<string.h> union intro { char name[20]; char fname[20]; long double Phone; }; void main() { union intro vb; strcpy(vb.name,"Vishwajeet Bharti"); printf("%s\n",vb.name); strcpy(vb.fname,"Binod Prasad"); printf("%s\n",vb.fname); vb.Phone=7366828903; printf("%ld\n",vb.Phone); }
the_stack_data/265257.c
/* Author: Debjyoti Guha Date: 14/08/2017 Updates: Minor Fixes and code Simplicity . Description: This is a MENU driven function for creating an arrey, insertion elements, deleting elements and display the arrey. */ #include<stdio.h> void create(int b[], int l); void insert(int c[], int m); void del(int d[], int o); void disp(int e[], int p); int a[50], n; void main() { int i, ch, pos; do{ printf("\n------------------------------------------------------------------------"); printf("\n\t\t\t\tMENU\n"); printf("------------------------------------------------------------------------\n"); printf("1. Create\t2. Insert\t3. Delete\t4.Display\t0. EXIT\n"); printf("------------------------------------------------------------------------\n"); scanf("%d", &ch); switch(ch) { case 1: printf("Enter The Limit\n"); repeat : scanf("%d", &n); if(n==0) { printf("Please Enter a valid Limit!\n"); goto repeat; } create(a,n); disp(a,n); break; case 2: if (n==0) { noelm : printf("Create the Arrey first, No elements in the arrey! \n"); break; } else { printf("Enter the position to insert\n"); scanf("%d", &pos); insert(a,pos); disp(a,n); break; } case 3: if (n==0) { goto noelm; } else { printf("Enter the position to delete\n"); scanf("%d", &pos); del(a,pos); disp(a,n); break; } case 4: disp(a,n); break; default: printf("\nInvalid choice!\n"); break; } }while(ch!=0); printf("Closing Menu...\n"); } void create(int b[], int l) { int i; printf("Enter the %d Elements\n", n); for(i=0; i<l; i++) { scanf("%d", &b[i]); } printf("Created an arrey having %d element(s)...\n", n); } void insert(int c[], int m) { int i, elm; for(i=n-1; i>=m; i--) { c[i+1]=c[i]; } printf("Enter The element to insert\n"); scanf("%d", &elm); c[m]=elm; n++; printf("%d is Inserted...\n", elm); } void del(int d[], int o) { int i,x; x=d[o]; for(i=o; i<n-1; i++) { d[i]=d[i+1]; } n--; printf("%d is Deleted...\n", x); } void disp(int e[], int p) { int i; if (n==0) { printf("No Element(s) stored in the Arrey\n"); } else { printf("Elements stored are\n"); for(i=0;i<p;i++) { printf("%d\t",e[i]); } } }
the_stack_data/89199363.c
#include <stdio.h> #define MAX 5 void main() { int array[MAX] = {1, 2, 4, 5}; int N = 4; // number of elements in array int i = 0; // loop variable int index = 1; // index location after which value will be inserted int value = 3; // new data element to be inserted // print array before insertion printf("Printing array before insertion −\n"); for (i = 0; i < N; i++) { printf("array[%d] = %d \n", i, array[i]); } // now shift rest of the elements downwards for (i = N; i >= index + 1; i--) { array[i + 1] = array[i]; } // add new element at first position array[index + 1] = value; // increase N to reflect number of elements N++; // print to confirm printf("Printing array after insertion −\n"); for (i = 0; i < N; i++) { printf("array[%d] = %d\n", i, array[i]); } }
the_stack_data/463529.c
/** * hellotest.c * To compile, use following commands: * gcc -o hellotest -lhello hellotest.c */ #include <stdio.h> int main() { int a = 3, b = 4; printf("%d + %d = %d\n", a, b, hello_add(a,b)); return 0; }
the_stack_data/111078217.c
#include<stdio.h> int val_sqr(int x) { return x * x; } void ref_sqr(int *x) { *x *= *x; } int main(int argc, char** argv) { int n1 = 2, n2 = 2, ans; ref_sqr(&n2); printf("ref_sqr: 2^2 = %d\n", n2); ans = val_sqr(n1); printf("val_sqr: 2^2 = %d\n", ans); return 0; }
the_stack_data/306533.c
#include <stdio.h> #include <string.h> #define lli long long int #define DEBUG if(0) char expression[5] = "+-*e"; void printResult(char n[], char selected[]) { int i, j; printf("%c", n[0]); for (i = 1, j = 0; n[i]; i ++, j ++) { if (selected[j] != 'e') printf("%c", selected[j]); printf("%c", n[i]); } } int countNumbers(char selected[]) { int i, numbers = 1; for (i = 0; selected[i]; i ++) numbers += selected[i] != 'e'; return(numbers); } void getNumbers(char n[], char selected[], lli number[]) { int i, j, k; lli newNum = n[0] - '0'; for (i = 1, j = 0, k = 0; n[i]; i ++, j ++) { int bug = selected[j] == 'e'; while (n[i] && selected[j] == 'e') { newNum = newNum*10 + n[i] - '0'; i ++; j ++; } number[k ++] = newNum; newNum = n[i] - '0'; } number[k] = newNum; } lli calculate(lli a, lli b, char oper) { if (oper == '*') return(a * b); if (oper == '+') return(a + b); return(a - b); } lli calculateResult(char n[], char selected[]) { int numbers = countNumbers(selected); lli number[numbers]; getNumbers(n, selected, number); //DEBUG for (int j = 0; j < numbers; j ++) printf("%lld%c", number[j], j < numbers - 1 ? ' ' : '\n'); char operation[13] = ""; int j, k; for (k = 0, j = 0; selected[j]; j ++) { if (selected[j] == 'e') continue; operation[k ++] = selected[j]; } operation[k] = '\0'; lli result = 0; if (!operation[0]) result = number[0]; else if (!operation[1]) result = calculate(number[0], number[1], operation[0]); else { char prevOp = operation[0]; int missing = 0; for (j = 1; operation[j]; j ++) { if (prevOp != '*' && operation[j] == '*') { lli aux = number[j] * number[j + 1]; number[j] = number[j - 1]; number[j + 1] = aux; operation[j] = prevOp; prevOp = operation[j]; operation[j - 1] = 'd'; } else { number[j] = calculate(number[j - 1], number[j], prevOp); prevOp = operation[j]; } if (!operation[j + 1]) missing = 1; } result = number[numbers - 1]; if (prevOp) result = calculate(number[numbers - 2], number[numbers - 1], prevOp); DEBUG for (j = 0; j < numbers; j ++) printf(" %lld%c", number[j], j < numbers - 1 ? ' ' : '\n'); } return(result); } int isFirst = 1, now = 0; char answer[100000][13]; void tryAll(char n[], char selected[], int i, lli target) { if (!n[i + 1]) { DEBUG { printResult(n, selected); printf("\n"); } lli result = calculateResult(n, selected); DEBUG printf("%lld\n\n", result); if (result == target) strcpy(answer[now ++], selected); return; } int k; for (k = 0; k < 4; k ++) { selected[i] = expression[k]; tryAll(n, selected, i + 1, target); } } int main() { char n[13] = ""; lli t; scanf("%s\n%lld", n, &t); char selected[13] = ""; tryAll(n, selected, 0, t); printf("["); printResult(n, answer[0]); int o; for (o = 1; o < now; o ++) { printf(", "); printResult(n, answer[o]); } printf("]\n"); return(0); }
the_stack_data/88358.c
/* * Call the system to execute a command line * which is passed as an argument. */ #include <stdio.h> #include <signal.h> system(line) char *line; { int status, pid; register wpid; register int (*intfun)(), (*quitfun)(); if ((pid = fork()) < 0) return (-1); if (pid == 0) { /* Child */ execl("/bin/sh", "sh", "-c", line, NULL); exit(0177); } intfun = signal(SIGINT, SIG_IGN); quitfun = signal(SIGQUIT, SIG_IGN); while ((wpid = wait(&status))!=pid && wpid>=0) ; if (wpid < 0) status = wpid; signal(SIGINT, intfun); signal(SIGQUIT, quitfun); return (status); }
the_stack_data/69596.c
#include<stdio.h> #define MAX_SIZE 100 int main() { int arr[MAX_SIZE]; int size, i, toSearch, toReplace, found; printf("Enter size of array: "); scanf("%d", &size); printf("Enter elements in array: "); for(i=0; i<size; i++) { scanf("%d", &arr[i]); } printf("\nEnter element to search: "); scanf("%d", &toSearch); found = 0; for(i=0; i<size; i++) { if(arr[i] == toSearch) { found = 1; break; } } if(found==1) { printf("%d is found at %d position\n", toSearch, i); printf("Enter a number to replace it "); scanf("%d", &toReplace); arr[i] = toReplace; printf("Done! resultant array is:"); for(i=0; i<size; i++) { printf("%d", arr[i]); printf("\n"); } } else { printf("Element not found."); } }
the_stack_data/146761.c
#include <stdio.h> int f() { puts("in f"); } int main() { /* Do a nexti now! */ f(); return 0; }
the_stack_data/767759.c
const unsigned short TRIPLE_data[1008] = { 4228, 4228, 4228, 4228, 4228, 4228, 4355, 4451, 4451, 4451, 4451, 4451, 4451, 4451, 4451, 4451, 4451, 4355, 4355, 4451, 4451, 4451, 4451, 4451, 4451, 4451, 4451, 4355, 4228, 4228, 4355, 4451, 4451, 4451, 4451, 4451, 4451, 4451, 4451, 4451, 4451, 4355, 4355, 4451, 4451, 4451, 4451, 4451, 4451, 4451, 4451, 4355, 4228, 4228, 4355, 4451, 4451, 4355, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4355, 4451, 4451, 4451, 4451, 4451, 4451, 4451, 4451, 4451, 4451, 4355, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4451, 13035, 13035, 13035, 13035, 13035, 13035, 13035, 13035, 13035, 13035, 4451, 4451, 13035, 13035, 13035, 13035, 13035, 13035, 13035, 13035, 4451, 4355, 4228, 4451, 13035, 13035, 13035, 13035, 13035, 13035, 13035, 13035, 13035, 13035, 4451, 4451, 13035, 13035, 13035, 13035, 13035, 13035, 13035, 13035, 4451, 4355, 4228, 4451, 13035, 13035, 4451, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4451, 13035, 13035, 13035, 13035, 13035, 13035, 13035, 13035, 13035, 13035, 4451, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4451, 8840, 8840, 8840, 8840, 8840, 8840, 8840, 8840, 8840, 8840, 4451, 4451, 8840, 8840, 8840, 8840, 8840, 8840, 8840, 8840, 13035, 4451, 4355, 4451, 8840, 8840, 8840, 8840, 8840, 8840, 8840, 8840, 8840, 8840, 4451, 4451, 8840, 8840, 8840, 8840, 8840, 8840, 8840, 8840, 13035, 4451, 4355, 4451, 8840, 8840, 4451, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4451, 8840, 8840, 8840, 8840, 8840, 8840, 8840, 8840, 8840, 8840, 4451, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4355, 4451, 4451, 4451, 4451, 8840, 8840, 4451, 4451, 4451, 4451, 4355, 4451, 8840, 8840, 4451, 4451, 4451, 4451, 4451, 8840, 8840, 13035, 4451, 4355, 4451, 4451, 4451, 4451, 8840, 8840, 4451, 4451, 4451, 4451, 4355, 4451, 8840, 8840, 4451, 4451, 4451, 4451, 4451, 8840, 8840, 13035, 4451, 4451, 8840, 8840, 4451, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4451, 8840, 8840, 4451, 4451, 4451, 4451, 4451, 4451, 4451, 4451, 4355, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4451, 8840, 8840, 4451, 4228, 4228, 4228, 4228, 4451, 8840, 8840, 4451, 4451, 4451, 4451, 4451, 4451, 8840, 8840, 4451, 4228, 4228, 4228, 4228, 4451, 8840, 8840, 4451, 4228, 4228, 4228, 4228, 4451, 8840, 8840, 4451, 4228, 4228, 4228, 4355, 4451, 8840, 8840, 4451, 4451, 8840, 8840, 4451, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4451, 8840, 8840, 4451, 4451, 4451, 4451, 4451, 4355, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4451, 8840, 8840, 4451, 4228, 4228, 4228, 4228, 4451, 8840, 8840, 13035, 13035, 13035, 13035, 13035, 13035, 8840, 8840, 4451, 4228, 4228, 4228, 4228, 4451, 8840, 8840, 4451, 4228, 4228, 4228, 4228, 4451, 8840, 8840, 4451, 4451, 4451, 4451, 4451, 13035, 8840, 8840, 4451, 4451, 8840, 8840, 4451, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4451, 8840, 8840, 13035, 13035, 13035, 13035, 13035, 4451, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4451, 8840, 8840, 4451, 4228, 4228, 4228, 4228, 4451, 8840, 8840, 8840, 8840, 8840, 8840, 8840, 8840, 8840, 4451, 4355, 4228, 4228, 4228, 4228, 4451, 8840, 8840, 4451, 4228, 4228, 4228, 4228, 4451, 8840, 8840, 13035, 13035, 13035, 13035, 13035, 8840, 8840, 4451, 4355, 4451, 8840, 8840, 4451, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4451, 8840, 8840, 8840, 8840, 8840, 8840, 8840, 4451, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4451, 8840, 8840, 4451, 4228, 4228, 4228, 4228, 4451, 8840, 8840, 4451, 4451, 4451, 8840, 8840, 8840, 4451, 4355, 4228, 4228, 4228, 4228, 4228, 4451, 8840, 8840, 4451, 4228, 4228, 4228, 4228, 4451, 8840, 8840, 8840, 8840, 8840, 8840, 8840, 8840, 4451, 4355, 4228, 4451, 8840, 8840, 4451, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4451, 8840, 8840, 4451, 4451, 4451, 4451, 4451, 4355, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4451, 8840, 8840, 4451, 4228, 4228, 4228, 4228, 4451, 8840, 8840, 4451, 4228, 4355, 4451, 8840, 8840, 13035, 4451, 4355, 4355, 4451, 4451, 4451, 4451, 8840, 8840, 4451, 4451, 4451, 4451, 4355, 4451, 8840, 8840, 4451, 4451, 4451, 4451, 4451, 4451, 4355, 4228, 4228, 4451, 8840, 8840, 4451, 4451, 4451, 4451, 4451, 4451, 4451, 4451, 4355, 4451, 8840, 8840, 4451, 4451, 4451, 4451, 4451, 4451, 4451, 4451, 4355, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4451, 8840, 8840, 4451, 4228, 4228, 4228, 4228, 4451, 8840, 8840, 4451, 4228, 4228, 4355, 4451, 8840, 8840, 13035, 4451, 4451, 13035, 13035, 13035, 13035, 8840, 8840, 13035, 13035, 13035, 13035, 4451, 4451, 8840, 8840, 4451, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4451, 8840, 8840, 13035, 13035, 13035, 13035, 13035, 13035, 13035, 13035, 4451, 4451, 8840, 8840, 13035, 13035, 13035, 13035, 13035, 13035, 13035, 13035, 4451, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4451, 8840, 8840, 4451, 4228, 4228, 4228, 4228, 4451, 8840, 8840, 4451, 4228, 4228, 4228, 4355, 4451, 8840, 8840, 4451, 4451, 8840, 8840, 8840, 8840, 8840, 8840, 8840, 8840, 8840, 8840, 4451, 4451, 8840, 8840, 4451, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4451, 8840, 8840, 8840, 8840, 8840, 8840, 8840, 8840, 8840, 8840, 4451, 4451, 8840, 8840, 8840, 8840, 8840, 8840, 8840, 8840, 8840, 8840, 4451, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4355, 4451, 4451, 4355, 4228, 4228, 4228, 4228, 4355, 4451, 4451, 4355, 4228, 4228, 4228, 4228, 4355, 4451, 4451, 4355, 4355, 4451, 4451, 4451, 4451, 4451, 4451, 4451, 4451, 4451, 4451, 4355, 4355, 4451, 4451, 4355, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4228, 4355, 4451, 4451, 4451, 4451, 4451, 4451, 4451, 4451, 4451, 4451, 4355, 4355, 4451, 4451, 4451, 4451, 4451, 4451, 4451, 4451, 4451, 4451, 4355, 4228, 4228, 4228, 4228, 4228, 4228, };
the_stack_data/67326085.c
/* * Simple MD5 implementation * * Compile with: gcc -o md5 -O3 -lm md5.c */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdint.h> // leftrotate function definition #define LEFTROTATE(x, c) (((x) << (c)) | ((x) >> (32 - (c)))) // These vars will contain the hash uint32_t h0, h1, h2, h3; void md5(char *initial_msg, size_t initial_len) { // Message (to prepare) uint8_t *msg = NULL; // Note: All variables are unsigned 32 bit and wrap modulo 2^32 when calculating // r specifies the per-round shift amounts uint32_t r[] = {7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21}; // Use binary integer part of the sines of integers (in radians) as constants// Initialize variables: uint32_t k[] = { 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501, 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821, 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8, 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a, 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70, 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05, 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665, 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1, 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391}; h0 = 0x67452301; h1 = 0xefcdab89; h2 = 0x98badcfe; h3 = 0x10325476; // Pre-processing: adding a single 1 bit //append "1" bit to message /* Notice: the input bytes are considered as bits strings, where the first bit is the most significant bit of the byte.[37] */ // Pre-processing: padding with zeros //append "0" bit until message length in bit ≡ 448 (mod 512) //append length mod (2 pow 64) to message int new_len; for(new_len = initial_len*8 + 1; new_len%512!=448; new_len++); new_len /= 8; msg = (uint8_t*)calloc(new_len + 64, 1); // also appends "0" bits // (we alloc also 64 extra bytes...) memcpy(msg, initial_msg, initial_len); msg[initial_len] = 128; // write the "1" bit uint32_t bits_len = 8*initial_len; // note, we append the len memcpy(msg + new_len, &bits_len, 4); // in bits at the end of the buffer // Process the message in successive 512-bit chunks: //for each 512-bit chunk of message: int offset; for(offset=0; offset<new_len; offset += (512/8)) { // break chunk into sixteen 32-bit words w[j], 0 ≤ j ≤ 15 uint32_t *w = (uint32_t *) (msg + offset); // Initialize hash value for this chunk: uint32_t a = h0; uint32_t b = h1; uint32_t c = h2; uint32_t d = h3; // Main loop: uint32_t i; for(i = 0; i<64; i++) { uint32_t f, g; if (i < 16) { f = (b & c) | ((~b) & d); g = i; } else if (i < 32) { f = (d & b) | ((~d) & c); g = (5*i + 1) % 16; } else if (i < 48) { f = b ^ c ^ d; g = (3*i + 5) % 16; } else { f = c ^ (b | (~d)); g = (7*i) % 16; } uint32_t temp = d; d = c; c = b; b = b + LEFTROTATE((a + f + k[i] + w[g]), r[i]); a = temp; } // Add this chunk's hash to result so far: h0 += a; h1 += b; h2 += c; h3 += d; } // cleanup free(msg); } char strin[100]; int main(int argc, char **argv) { FILE* fd=fopen("input","r"); while (fgets(strin,80,fd)) { strin[strlen(strin)-1]=0; size_t len = strlen(strin); //printf("%s--",strin); // benchmark // int i; // for (i = 0; i < 1000000; i++) { md5(strin, len); // } //var char digest[16] := h0 append h1 append h2 append h3 //(Output is in little-endian) uint8_t *p; // display result p=(uint8_t *)&h0; printf("%2.2x%2.2x%2.2x%2.2x", p[0], p[1], p[2], p[3]); p=(uint8_t *)&h1; printf("%2.2x%2.2x%2.2x%2.2x", p[0], p[1], p[2], p[3]); p=(uint8_t *)&h2; printf("%2.2x%2.2x%2.2x%2.2x", p[0], p[1], p[2], p[3]); p=(uint8_t *)&h3; printf("%2.2x%2.2x%2.2x%2.2x", p[0], p[1], p[2], p[3]); puts(""); } return 0; }
the_stack_data/786197.c
#include <stdio.h> int main(int argc, char* argv[]) { printf("Time: %g seconds\n", 183.7); printf("Memory: %d GB\n", 24); printf("Validation: SUCCESS\n"); }
the_stack_data/25136808.c
/* floora.c */ #include <stdio.h> double floor(double num); int main() { double a; printf("Input a real number:"); scanf("%lf", &a); printf("\tInteger:%f\n", floor(a)); return 0; } double floor(double num) { return (double)(int)(num); }
the_stack_data/61074096.c
/* * GRUB -- GRand Unified Bootloader * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* * Copyright 2010 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* * The zfs plug-in routines for GRUB are: * * zfs_mount() - locates a valid uberblock of the root pool and reads * in its MOS at the memory address MOS. * * zfs_open() - locates a plain file object by following the MOS * and places its dnode at the memory address DNODE. * * zfs_read() - read in the data blocks pointed by the DNODE. * * ZFS_SCRATCH is used as a working area. * * (memory addr) MOS DNODE ZFS_SCRATCH * | | | * +-------V---------V----------V---------------+ * memory | | dnode | dnode | scratch | * | | 512B | 512B | area | * +--------------------------------------------+ */ #ifdef FSYS_ZFS #include "shared.h" #include "filesys.h" #include "fsys_zfs.h" /* cache for a file block of the currently zfs_open()-ed file */ static void *file_buf = NULL; static uint64_t file_start = 0; static uint64_t file_end = 0; /* cache for a dnode block */ static dnode_phys_t *dnode_buf = NULL; static dnode_phys_t *dnode_mdn = NULL; static uint64_t dnode_start = 0; static uint64_t dnode_end = 0; static uint64_t pool_guid = 0; static uberblock_t current_uberblock; static char *stackbase; decomp_entry_t decomp_table[ZIO_COMPRESS_FUNCTIONS] = { {"inherit", 0}, /* ZIO_COMPRESS_INHERIT */ {"on", lzjb_decompress}, /* ZIO_COMPRESS_ON */ {"off", 0}, /* ZIO_COMPRESS_OFF */ {"lzjb", lzjb_decompress}, /* ZIO_COMPRESS_LZJB */ {"empty", 0} /* ZIO_COMPRESS_EMPTY */ }; static int zio_read_data(blkptr_t *bp, void *buf, char *stack); /* * Our own version of bcmp(). */ static int zfs_bcmp(const void *s1, const void *s2, size_t n) { const uint8_t *ps1 = s1; const uint8_t *ps2 = s2; if (s1 != s2 && n != 0) { do { if (*ps1++ != *ps2++) return (1); } while (--n != 0); } return (0); } /* * Our own version of log2(). Same thing as highbit()-1. */ static int zfs_log2(uint64_t num) { int i = 0; while (num > 1) { i++; num = num >> 1; } return (i); } /* Checksum Functions */ static void zio_checksum_off(const void *buf, uint64_t size, zio_cksum_t *zcp) { ZIO_SET_CHECKSUM(zcp, 0, 0, 0, 0); } /* Checksum Table and Values */ zio_checksum_info_t zio_checksum_table[ZIO_CHECKSUM_FUNCTIONS] = { { { NULL, NULL }, 0, 0, "inherit" }, { { NULL, NULL }, 0, 0, "on" }, { { zio_checksum_off, zio_checksum_off }, 0, 0, "off" }, { { zio_checksum_SHA256, zio_checksum_SHA256 }, 1, 1, "label" }, { { zio_checksum_SHA256, zio_checksum_SHA256 }, 1, 1, "gang_header" }, { { NULL, NULL }, 0, 0, "zilog" }, { { fletcher_2_native, fletcher_2_byteswap }, 0, 0, "fletcher2" }, { { fletcher_4_native, fletcher_4_byteswap }, 1, 0, "fletcher4" }, { { zio_checksum_SHA256, zio_checksum_SHA256 }, 1, 0, "SHA256" }, { { NULL, NULL }, 0, 0, "zilog2" } }; /* * zio_checksum_verify: Provides support for checksum verification. * * Fletcher2, Fletcher4, and SHA256 are supported. * * Return: * -1 = Failure * 0 = Success */ static int zio_checksum_verify(blkptr_t *bp, char *data, int size) { zio_cksum_t zc = bp->blk_cksum; uint32_t checksum = BP_GET_CHECKSUM(bp); int byteswap = BP_SHOULD_BYTESWAP(bp); zio_eck_t *zec = (zio_eck_t *)(data + size) - 1; zio_checksum_info_t *ci = &zio_checksum_table[checksum]; zio_cksum_t actual_cksum, expected_cksum; /* byteswap is not supported */ if (byteswap) return (-1); if (checksum >= ZIO_CHECKSUM_FUNCTIONS || ci->ci_func[0] == NULL) return (-1); if (ci->ci_eck) { expected_cksum = zec->zec_cksum; zec->zec_cksum = zc; ci->ci_func[0](data, size, &actual_cksum); zec->zec_cksum = expected_cksum; zc = expected_cksum; } else { ci->ci_func[byteswap](data, size, &actual_cksum); } if ((actual_cksum.zc_word[0] - zc.zc_word[0]) | (actual_cksum.zc_word[1] - zc.zc_word[1]) | (actual_cksum.zc_word[2] - zc.zc_word[2]) | (actual_cksum.zc_word[3] - zc.zc_word[3])) return (-1); return (0); } /* * vdev_label_start returns the physical disk offset (in bytes) of * label "l". */ static uint64_t vdev_label_start(uint64_t psize, int l) { return (l * sizeof (vdev_label_t) + (l < VDEV_LABELS / 2 ? 0 : psize - VDEV_LABELS * sizeof (vdev_label_t))); } /* * vdev_uberblock_compare takes two uberblock structures and returns an integer * indicating the more recent of the two. * Return Value = 1 if ub2 is more recent * Return Value = -1 if ub1 is more recent * The most recent uberblock is determined using its transaction number and * timestamp. The uberblock with the highest transaction number is * considered "newer". If the transaction numbers of the two blocks match, the * timestamps are compared to determine the "newer" of the two. */ static int vdev_uberblock_compare(uberblock_t *ub1, uberblock_t *ub2) { if (ub1->ub_txg < ub2->ub_txg) return (-1); if (ub1->ub_txg > ub2->ub_txg) return (1); if (ub1->ub_timestamp < ub2->ub_timestamp) return (-1); if (ub1->ub_timestamp > ub2->ub_timestamp) return (1); return (0); } /* * Three pieces of information are needed to verify an uberblock: the magic * number, the version number, and the checksum. * * Currently Implemented: version number, magic number * Need to Implement: checksum * * Return: * 0 - Success * -1 - Failure */ static int uberblock_verify(uberblock_phys_t *ub, uint64_t offset) { uberblock_t *uber = &ub->ubp_uberblock; blkptr_t bp; BP_ZERO(&bp); BP_SET_CHECKSUM(&bp, ZIO_CHECKSUM_LABEL); BP_SET_BYTEORDER(&bp, ZFS_HOST_BYTEORDER); ZIO_SET_CHECKSUM(&bp.blk_cksum, offset, 0, 0, 0); if (zio_checksum_verify(&bp, (char *)ub, UBERBLOCK_SIZE) != 0) return (-1); if (uber->ub_magic == UBERBLOCK_MAGIC && uber->ub_version > 0 && uber->ub_version <= SPA_VERSION) return (0); return (-1); } /* * Find the best uberblock. * Return: * Success - Pointer to the best uberblock. * Failure - NULL */ static uberblock_phys_t * find_bestub(uberblock_phys_t *ub_array, uint64_t sector) { uberblock_phys_t *ubbest = NULL; uint64_t offset; int i; for (i = 0; i < (VDEV_UBERBLOCK_RING >> VDEV_UBERBLOCK_SHIFT); i++) { offset = (sector << SPA_MINBLOCKSHIFT) + VDEV_UBERBLOCK_OFFSET(i); if (uberblock_verify(&ub_array[i], offset) == 0) { if (ubbest == NULL) { ubbest = &ub_array[i]; } else if (vdev_uberblock_compare( &(ub_array[i].ubp_uberblock), &(ubbest->ubp_uberblock)) > 0) { ubbest = &ub_array[i]; } } } return (ubbest); } /* * Read a block of data based on the gang block address dva, * and put its data in buf. * * Return: * 0 - success * 1 - failure */ static int zio_read_gang(blkptr_t *bp, dva_t *dva, void *buf, char *stack) { zio_gbh_phys_t *zio_gb; uint64_t offset, sector; blkptr_t tmpbp; int i; zio_gb = (zio_gbh_phys_t *)stack; stack += SPA_GANGBLOCKSIZE; offset = DVA_GET_OFFSET(dva); sector = DVA_OFFSET_TO_PHYS_SECTOR(offset); /* read in the gang block header */ if (devread(sector, 0, SPA_GANGBLOCKSIZE, (char *)zio_gb) == 0) { grub_printf("failed to read in a gang block header\n"); return (1); } /* self checksuming the gang block header */ BP_ZERO(&tmpbp); BP_SET_CHECKSUM(&tmpbp, ZIO_CHECKSUM_GANG_HEADER); BP_SET_BYTEORDER(&tmpbp, ZFS_HOST_BYTEORDER); ZIO_SET_CHECKSUM(&tmpbp.blk_cksum, DVA_GET_VDEV(dva), DVA_GET_OFFSET(dva), bp->blk_birth, 0); if (zio_checksum_verify(&tmpbp, (char *)zio_gb, SPA_GANGBLOCKSIZE)) { grub_printf("failed to checksum a gang block header\n"); return (1); } for (i = 0; i < SPA_GBH_NBLKPTRS; i++) { if (zio_gb->zg_blkptr[i].blk_birth == 0) continue; if (zio_read_data(&zio_gb->zg_blkptr[i], buf, stack)) return (1); buf += BP_GET_PSIZE(&zio_gb->zg_blkptr[i]); } return (0); } /* * Read in a block of raw data to buf. * * Return: * 0 - success * 1 - failure */ static int zio_read_data(blkptr_t *bp, void *buf, char *stack) { int i, psize; psize = BP_GET_PSIZE(bp); /* pick a good dva from the block pointer */ for (i = 0; i < SPA_DVAS_PER_BP; i++) { uint64_t offset, sector; if (bp->blk_dva[i].dva_word[0] == 0 && bp->blk_dva[i].dva_word[1] == 0) continue; if (DVA_GET_GANG(&bp->blk_dva[i])) { if (zio_read_gang(bp, &bp->blk_dva[i], buf, stack) == 0) return (0); } else { /* read in a data block */ offset = DVA_GET_OFFSET(&bp->blk_dva[i]); sector = DVA_OFFSET_TO_PHYS_SECTOR(offset); if (devread(sector, 0, psize, buf)) return (0); } } return (1); } /* * Read in a block of data, verify its checksum, decompress if needed, * and put the uncompressed data in buf. * * Return: * 0 - success * errnum - failure */ static int zio_read(blkptr_t *bp, void *buf, char *stack) { int lsize, psize, comp; char *retbuf; comp = BP_GET_COMPRESS(bp); lsize = BP_GET_LSIZE(bp); psize = BP_GET_PSIZE(bp); if ((unsigned int)comp >= ZIO_COMPRESS_FUNCTIONS || (comp != ZIO_COMPRESS_OFF && decomp_table[comp].decomp_func == NULL)) { grub_printf("compression algorithm not supported\n"); return (ERR_FSYS_CORRUPT); } if ((char *)buf < stack && ((char *)buf) + lsize > stack) { grub_printf("not enough memory allocated\n"); return (ERR_WONT_FIT); } retbuf = buf; if (comp != ZIO_COMPRESS_OFF) { buf = stack; stack += psize; } if (zio_read_data(bp, buf, stack)) { grub_printf("zio_read_data failed\n"); return (ERR_FSYS_CORRUPT); } if (zio_checksum_verify(bp, buf, psize) != 0) { grub_printf("checksum verification failed\n"); return (ERR_FSYS_CORRUPT); } if (comp != ZIO_COMPRESS_OFF) decomp_table[comp].decomp_func(buf, retbuf, psize, lsize); return (0); } /* * Get the block from a block id. * push the block onto the stack. * * Return: * 0 - success * errnum - failure */ static int dmu_read(dnode_phys_t *dn, uint64_t blkid, void *buf, char *stack) { int idx, level; blkptr_t *bp_array = dn->dn_blkptr; int epbs = dn->dn_indblkshift - SPA_BLKPTRSHIFT; blkptr_t *bp, *tmpbuf; bp = (blkptr_t *)stack; stack += sizeof (blkptr_t); tmpbuf = (blkptr_t *)stack; stack += 1<<dn->dn_indblkshift; for (level = dn->dn_nlevels - 1; level >= 0; level--) { idx = (blkid >> (epbs * level)) & ((1<<epbs)-1); *bp = bp_array[idx]; if (level == 0) tmpbuf = buf; if (BP_IS_HOLE(bp)) { grub_memset(buf, 0, dn->dn_datablkszsec << SPA_MINBLOCKSHIFT); break; } else if ((errnum = zio_read(bp, tmpbuf, stack))) { return (errnum); } bp_array = tmpbuf; } return (0); } /* * mzap_lookup: Looks up property described by "name" and returns the value * in "value". * * Return: * 0 - success * errnum - failure */ static int mzap_lookup(mzap_phys_t *zapobj, int objsize, char *name, uint64_t *value) { int i, chunks; mzap_ent_phys_t *mzap_ent = zapobj->mz_chunk; chunks = objsize/MZAP_ENT_LEN - 1; for (i = 0; i < chunks; i++) { if (grub_strcmp(mzap_ent[i].mze_name, name) == 0) { *value = mzap_ent[i].mze_value; return (0); } } return (ERR_FSYS_CORRUPT); } static uint64_t zap_hash(uint64_t salt, const char *name) { static uint64_t table[256]; const uint8_t *cp; uint8_t c; uint64_t crc = salt; if (table[128] == 0) { uint64_t *ct; int i, j; for (i = 0; i < 256; i++) { for (ct = table + i, *ct = i, j = 8; j > 0; j--) *ct = (*ct >> 1) ^ (-(*ct & 1) & ZFS_CRC64_POLY); } } if (crc == 0 || table[128] != ZFS_CRC64_POLY) { errnum = ERR_FSYS_CORRUPT; return (0); } for (cp = (const uint8_t *)name; (c = *cp) != '\0'; cp++) crc = (crc >> 8) ^ table[(crc ^ c) & 0xFF]; /* * Only use 28 bits, since we need 4 bits in the cookie for the * collision differentiator. We MUST use the high bits, since * those are the onces that we first pay attention to when * chosing the bucket. */ crc &= ~((1ULL << (64 - 28)) - 1); return (crc); } /* * Only to be used on 8-bit arrays. * array_len is actual len in bytes (not encoded le_value_length). * buf is null-terminated. */ static int zap_leaf_array_equal(zap_leaf_phys_t *l, int blksft, int chunk, int array_len, const char *buf) { int bseen = 0; while (bseen < array_len) { struct zap_leaf_array *la = &ZAP_LEAF_CHUNK(l, blksft, chunk).l_array; int toread = MIN(array_len - bseen, ZAP_LEAF_ARRAY_BYTES); if (chunk >= ZAP_LEAF_NUMCHUNKS(blksft)) return (0); if (zfs_bcmp(la->la_array, buf + bseen, toread) != 0) break; chunk = la->la_next; bseen += toread; } return (bseen == array_len); } /* * Given a zap_leaf_phys_t, walk thru the zap leaf chunks to get the * value for the property "name". * * Return: * 0 - success * errnum - failure */ static int zap_leaf_lookup(zap_leaf_phys_t *l, int blksft, uint64_t h, const char *name, uint64_t *value) { uint16_t chunk; struct zap_leaf_entry *le; /* Verify if this is a valid leaf block */ if (l->l_hdr.lh_block_type != ZBT_LEAF) return (ERR_FSYS_CORRUPT); if (l->l_hdr.lh_magic != ZAP_LEAF_MAGIC) return (ERR_FSYS_CORRUPT); for (chunk = l->l_hash[LEAF_HASH(blksft, h)]; chunk != CHAIN_END; chunk = le->le_next) { if (chunk >= ZAP_LEAF_NUMCHUNKS(blksft)) return (ERR_FSYS_CORRUPT); le = ZAP_LEAF_ENTRY(l, blksft, chunk); /* Verify the chunk entry */ if (le->le_type != ZAP_CHUNK_ENTRY) return (ERR_FSYS_CORRUPT); if (le->le_hash != h) continue; if (zap_leaf_array_equal(l, blksft, le->le_name_chunk, le->le_name_length, name)) { struct zap_leaf_array *la; uint8_t *ip; if (le->le_int_size != 8 || le->le_value_length != 1) return (ERR_FSYS_CORRUPT); /* get the uint64_t property value */ la = &ZAP_LEAF_CHUNK(l, blksft, le->le_value_chunk).l_array; ip = la->la_array; *value = (uint64_t)ip[0] << 56 | (uint64_t)ip[1] << 48 | (uint64_t)ip[2] << 40 | (uint64_t)ip[3] << 32 | (uint64_t)ip[4] << 24 | (uint64_t)ip[5] << 16 | (uint64_t)ip[6] << 8 | (uint64_t)ip[7]; return (0); } } return (ERR_FSYS_CORRUPT); } /* * Fat ZAP lookup * * Return: * 0 - success * errnum - failure */ static int fzap_lookup(dnode_phys_t *zap_dnode, zap_phys_t *zap, char *name, uint64_t *value, char *stack) { zap_leaf_phys_t *l; uint64_t hash, idx, blkid; int blksft = zfs_log2(zap_dnode->dn_datablkszsec << DNODE_SHIFT); /* Verify if this is a fat zap header block */ if (zap->zap_magic != (uint64_t)ZAP_MAGIC || zap->zap_flags != 0) return (ERR_FSYS_CORRUPT); hash = zap_hash(zap->zap_salt, name); if (errnum) return (errnum); /* get block id from index */ if (zap->zap_ptrtbl.zt_numblks != 0) { /* external pointer tables not supported */ return (ERR_FSYS_CORRUPT); } idx = ZAP_HASH_IDX(hash, zap->zap_ptrtbl.zt_shift); blkid = ((uint64_t *)zap)[idx + (1<<(blksft-3-1))]; /* Get the leaf block */ l = (zap_leaf_phys_t *)stack; stack += 1<<blksft; if ((1<<blksft) < sizeof (zap_leaf_phys_t)) return (ERR_FSYS_CORRUPT); if ((errnum = dmu_read(zap_dnode, blkid, l, stack))) return (errnum); return (zap_leaf_lookup(l, blksft, hash, name, value)); } /* * Read in the data of a zap object and find the value for a matching * property name. * * Return: * 0 - success * errnum - failure */ static int zap_lookup(dnode_phys_t *zap_dnode, char *name, uint64_t *val, char *stack) { uint64_t block_type; int size; void *zapbuf; /* Read in the first block of the zap object data. */ zapbuf = stack; size = zap_dnode->dn_datablkszsec << SPA_MINBLOCKSHIFT; stack += size; if ((errnum = dmu_read(zap_dnode, 0, zapbuf, stack))) return (errnum); block_type = *((uint64_t *)zapbuf); if (block_type == ZBT_MICRO) { return (mzap_lookup(zapbuf, size, name, val)); } else if (block_type == ZBT_HEADER) { /* this is a fat zap */ return (fzap_lookup(zap_dnode, zapbuf, name, val, stack)); } return (ERR_FSYS_CORRUPT); } /* * Get the dnode of an object number from the metadnode of an object set. * * Input * mdn - metadnode to get the object dnode * objnum - object number for the object dnode * buf - data buffer that holds the returning dnode * stack - scratch area * * Return: * 0 - success * errnum - failure */ static int dnode_get(dnode_phys_t *mdn, uint64_t objnum, uint8_t type, dnode_phys_t *buf, char *stack) { uint64_t blkid, blksz; /* the block id this object dnode is in */ int epbs; /* shift of number of dnodes in a block */ int idx; /* index within a block */ dnode_phys_t *dnbuf; blksz = mdn->dn_datablkszsec << SPA_MINBLOCKSHIFT; epbs = zfs_log2(blksz) - DNODE_SHIFT; blkid = objnum >> epbs; idx = objnum & ((1<<epbs)-1); if (dnode_buf != NULL && dnode_mdn == mdn && objnum >= dnode_start && objnum < dnode_end) { grub_memmove(buf, &dnode_buf[idx], DNODE_SIZE); VERIFY_DN_TYPE(buf, type); return (0); } if (dnode_buf && blksz == 1<<DNODE_BLOCK_SHIFT) { dnbuf = dnode_buf; dnode_mdn = mdn; dnode_start = blkid << epbs; dnode_end = (blkid + 1) << epbs; } else { dnbuf = (dnode_phys_t *)stack; stack += blksz; } if ((errnum = dmu_read(mdn, blkid, (char *)dnbuf, stack))) return (errnum); grub_memmove(buf, &dnbuf[idx], DNODE_SIZE); VERIFY_DN_TYPE(buf, type); return (0); } /* * Check if this is a special file that resides at the top * dataset of the pool. Currently this is the GRUB menu, * boot signature and boot signature backup. * str starts with '/'. */ static int is_top_dataset_file(char *str) { char *tptr; if ((tptr = grub_strstr(str, "menu.lst")) && (tptr[8] == '\0' || tptr[8] == ' ') && *(tptr-1) == '/') return (1); if (grub_strncmp(str, BOOTSIGN_DIR"/", grub_strlen(BOOTSIGN_DIR) + 1) == 0) return (1); if (grub_strcmp(str, BOOTSIGN_BACKUP) == 0) return (1); return (0); } /* * Get the file dnode for a given file name where mdn is the meta dnode * for this ZFS object set. When found, place the file dnode in dn. * The 'path' argument will be mangled. * * Return: * 0 - success * errnum - failure */ static int dnode_get_path(dnode_phys_t *mdn, char *path, dnode_phys_t *dn, char *stack) { uint64_t objnum, version; char *cname, ch; if ((errnum = dnode_get(mdn, MASTER_NODE_OBJ, DMU_OT_MASTER_NODE, dn, stack))) return (errnum); if ((errnum = zap_lookup(dn, ZPL_VERSION_STR, &version, stack))) return (errnum); if (version > ZPL_VERSION) return (-1); if ((errnum = zap_lookup(dn, ZFS_ROOT_OBJ, &objnum, stack))) return (errnum); if ((errnum = dnode_get(mdn, objnum, DMU_OT_DIRECTORY_CONTENTS, dn, stack))) return (errnum); /* skip leading slashes */ while (*path == '/') path++; while (*path && !isspace((uint8_t)*path)) { /* get the next component name */ cname = path; while (*path && !isspace((uint8_t)*path) && *path != '/') path++; ch = *path; *path = 0; /* ensure null termination */ if ((errnum = zap_lookup(dn, cname, &objnum, stack))) return (errnum); objnum = ZFS_DIRENT_OBJ(objnum); if ((errnum = dnode_get(mdn, objnum, 0, dn, stack))) return (errnum); *path = ch; while (*path == '/') path++; } /* We found the dnode for this file. Verify if it is a plain file. */ VERIFY_DN_TYPE(dn, DMU_OT_PLAIN_FILE_CONTENTS); return (0); } /* * Get the default 'bootfs' property value from the rootpool. * * Return: * 0 - success * errnum -failure */ static int get_default_bootfsobj(dnode_phys_t *mosmdn, uint64_t *obj, char *stack) { uint64_t objnum = 0; dnode_phys_t *dn = (dnode_phys_t *)stack; stack += DNODE_SIZE; if ((errnum = dnode_get(mosmdn, DMU_POOL_DIRECTORY_OBJECT, DMU_OT_OBJECT_DIRECTORY, dn, stack))) return (errnum); /* * find the object number for 'pool_props', and get the dnode * of the 'pool_props'. */ if (zap_lookup(dn, DMU_POOL_PROPS, &objnum, stack)) return (ERR_FILESYSTEM_NOT_FOUND); if ((errnum = dnode_get(mosmdn, objnum, DMU_OT_POOL_PROPS, dn, stack))) return (errnum); if (zap_lookup(dn, ZPOOL_PROP_BOOTFS, &objnum, stack)) return (ERR_FILESYSTEM_NOT_FOUND); if (!objnum) return (ERR_FILESYSTEM_NOT_FOUND); *obj = objnum; return (0); } /* * Given a MOS metadnode, get the metadnode of a given filesystem name (fsname), * e.g. pool/rootfs, or a given object number (obj), e.g. the object number * of pool/rootfs. * * If no fsname and no obj are given, return the DSL_DIR metadnode. * If fsname is given, return its metadnode and its matching object number. * If only obj is given, return the metadnode for this object number. * * Return: * 0 - success * errnum - failure */ static int get_objset_mdn(dnode_phys_t *mosmdn, char *fsname, uint64_t *obj, dnode_phys_t *mdn, char *stack) { uint64_t objnum, headobj; char *cname, ch; blkptr_t *bp; objset_phys_t *osp; int issnapshot = 0; char *snapname = NULL; if (fsname == NULL && obj) { headobj = *obj; goto skip; } if ((errnum = dnode_get(mosmdn, DMU_POOL_DIRECTORY_OBJECT, DMU_OT_OBJECT_DIRECTORY, mdn, stack))) return (errnum); if ((errnum = zap_lookup(mdn, DMU_POOL_ROOT_DATASET, &objnum, stack))) return (errnum); if ((errnum = dnode_get(mosmdn, objnum, DMU_OT_DSL_DIR, mdn, stack))) return (errnum); if (fsname == NULL) { headobj = ((dsl_dir_phys_t *)DN_BONUS(mdn))->dd_head_dataset_obj; goto skip; } /* take out the pool name */ while (*fsname && !isspace((uint8_t)*fsname) && *fsname != '/') fsname++; while (*fsname && !isspace((uint8_t)*fsname)) { uint64_t childobj; while (*fsname == '/') fsname++; cname = fsname; while (*fsname && !isspace((uint8_t)*fsname) && *fsname != '/') fsname++; ch = *fsname; *fsname = 0; snapname = cname; while (*snapname && !isspace((uint8_t)*snapname) && *snapname != '@') snapname++; if (*snapname == '@') { issnapshot = 1; *snapname = 0; } childobj = ((dsl_dir_phys_t *)DN_BONUS(mdn))->dd_child_dir_zapobj; if ((errnum = dnode_get(mosmdn, childobj, DMU_OT_DSL_DIR_CHILD_MAP, mdn, stack))) return (errnum); if (zap_lookup(mdn, cname, &objnum, stack)) return (ERR_FILESYSTEM_NOT_FOUND); if ((errnum = dnode_get(mosmdn, objnum, DMU_OT_DSL_DIR, mdn, stack))) return (errnum); *fsname = ch; if (issnapshot) *snapname = '@'; } headobj = ((dsl_dir_phys_t *)DN_BONUS(mdn))->dd_head_dataset_obj; if (obj) *obj = headobj; skip: if ((errnum = dnode_get(mosmdn, headobj, DMU_OT_DSL_DATASET, mdn, stack))) return (errnum); if (issnapshot) { uint64_t snapobj; snapobj = ((dsl_dataset_phys_t *)DN_BONUS(mdn))-> ds_snapnames_zapobj; if ((errnum = dnode_get(mosmdn, snapobj, DMU_OT_DSL_DS_SNAP_MAP, mdn, stack))) return (errnum); if (zap_lookup(mdn, snapname + 1, &headobj, stack)) return (ERR_FILESYSTEM_NOT_FOUND); if ((errnum = dnode_get(mosmdn, headobj, DMU_OT_DSL_DATASET, mdn, stack))) return (errnum); if (obj) *obj = headobj; } bp = &((dsl_dataset_phys_t *)DN_BONUS(mdn))->ds_bp; osp = (objset_phys_t *)stack; stack += sizeof (objset_phys_t); if ((errnum = zio_read(bp, osp, stack))) return (errnum); grub_memmove((char *)mdn, (char *)&osp->os_meta_dnode, DNODE_SIZE); return (0); } /* * For a given XDR packed nvlist, verify the first 4 bytes and move on. * * An XDR packed nvlist is encoded as (comments from nvs_xdr_create) : * * encoding method/host endian (4 bytes) * nvl_version (4 bytes) * nvl_nvflag (4 bytes) * encoded nvpairs: * encoded size of the nvpair (4 bytes) * decoded size of the nvpair (4 bytes) * name string size (4 bytes) * name string data (sizeof(NV_ALIGN4(string)) * data type (4 bytes) * # of elements in the nvpair (4 bytes) * data * 2 zero's for the last nvpair * (end of the entire list) (8 bytes) * * Return: * 0 - success * 1 - failure */ static int nvlist_unpack(char *nvlist, char **out) { /* Verify if the 1st and 2nd byte in the nvlist are valid. */ if (nvlist[0] != NV_ENCODE_XDR || nvlist[1] != HOST_ENDIAN) return (1); nvlist += 4; *out = nvlist; return (0); } static char * nvlist_array(char *nvlist, int index) { int i, encode_size; for (i = 0; i < index; i++) { /* skip the header, nvl_version, and nvl_nvflag */ nvlist = nvlist + 4 * 2; while ((encode_size = BSWAP_32(*(uint32_t *)nvlist))) nvlist += encode_size; /* goto the next nvpair */ nvlist = nvlist + 4 * 2; /* skip the ending 2 zeros - 8 bytes */ } return (nvlist); } static int nvlist_lookup_value(char *nvlist, char *name, void *val, int valtype, int *nelmp) { int name_len, type, slen, encode_size; char *nvpair, *nvp_name, *strval = val; uint64_t *intval = val; /* skip the header, nvl_version, and nvl_nvflag */ nvlist = nvlist + 4 * 2; /* * Loop thru the nvpair list * The XDR representation of an integer is in big-endian byte order. */ while ((encode_size = BSWAP_32(*(uint32_t *)nvlist))) { nvpair = nvlist + 4 * 2; /* skip the encode/decode size */ name_len = BSWAP_32(*(uint32_t *)nvpair); nvpair += 4; nvp_name = nvpair; nvpair = nvpair + ((name_len + 3) & ~3); /* align */ type = BSWAP_32(*(uint32_t *)nvpair); nvpair += 4; if ((grub_strncmp(nvp_name, name, name_len) == 0) && type == valtype) { int nelm; if ((nelm = BSWAP_32(*(uint32_t *)nvpair)) < 1) return (1); nvpair += 4; switch (valtype) { case DATA_TYPE_STRING: slen = BSWAP_32(*(uint32_t *)nvpair); nvpair += 4; grub_memmove(strval, nvpair, slen); strval[slen] = '\0'; return (0); case DATA_TYPE_UINT64: *intval = BSWAP_64(*(uint64_t *)nvpair); return (0); case DATA_TYPE_NVLIST: *(void **)val = (void *)nvpair; return (0); case DATA_TYPE_NVLIST_ARRAY: *(void **)val = (void *)nvpair; if (nelmp) *nelmp = nelm; return (0); } } nvlist += encode_size; /* goto the next nvpair */ } return (1); } /* * Check if this vdev is online and is in a good state. */ static int vdev_validate(char *nv) { uint64_t ival; if (nvlist_lookup_value(nv, ZPOOL_CONFIG_OFFLINE, &ival, DATA_TYPE_UINT64, NULL) == 0 || nvlist_lookup_value(nv, ZPOOL_CONFIG_FAULTED, &ival, DATA_TYPE_UINT64, NULL) == 0 || nvlist_lookup_value(nv, ZPOOL_CONFIG_REMOVED, &ival, DATA_TYPE_UINT64, NULL) == 0) return (ERR_DEV_VALUES); return (0); } /* * Get a valid vdev pathname/devid from the boot device. * The caller should already allocate MAXPATHLEN memory for bootpath and devid. */ static int vdev_get_bootpath(char *nv, uint64_t inguid, char *devid, char *bootpath, int is_spare) { char type[16]; if (nvlist_lookup_value(nv, ZPOOL_CONFIG_TYPE, &type, DATA_TYPE_STRING, NULL)) return (ERR_FSYS_CORRUPT); if (strcmp(type, VDEV_TYPE_DISK) == 0) { uint64_t guid; if (vdev_validate(nv) != 0) return (ERR_NO_BOOTPATH); if (nvlist_lookup_value(nv, ZPOOL_CONFIG_GUID, &guid, DATA_TYPE_UINT64, NULL) != 0) return (ERR_NO_BOOTPATH); if (guid != inguid) return (ERR_NO_BOOTPATH); /* for a spare vdev, pick the disk labeled with "is_spare" */ if (is_spare) { uint64_t spare = 0; (void) nvlist_lookup_value(nv, ZPOOL_CONFIG_IS_SPARE, &spare, DATA_TYPE_UINT64, NULL); if (!spare) return (ERR_NO_BOOTPATH); } if (nvlist_lookup_value(nv, ZPOOL_CONFIG_PHYS_PATH, bootpath, DATA_TYPE_STRING, NULL) != 0) bootpath[0] = '\0'; if (nvlist_lookup_value(nv, ZPOOL_CONFIG_DEVID, devid, DATA_TYPE_STRING, NULL) != 0) devid[0] = '\0'; if (strlen(bootpath) >= MAXPATHLEN || strlen(devid) >= MAXPATHLEN) return (ERR_WONT_FIT); return (0); } else if (strcmp(type, VDEV_TYPE_MIRROR) == 0 || strcmp(type, VDEV_TYPE_REPLACING) == 0 || (is_spare = (strcmp(type, VDEV_TYPE_SPARE) == 0))) { int nelm, i; char *child; if (nvlist_lookup_value(nv, ZPOOL_CONFIG_CHILDREN, &child, DATA_TYPE_NVLIST_ARRAY, &nelm)) return (ERR_FSYS_CORRUPT); for (i = 0; i < nelm; i++) { char *child_i; child_i = nvlist_array(child, i); if (vdev_get_bootpath(child_i, inguid, devid, bootpath, is_spare) == 0) return (0); } } return (ERR_NO_BOOTPATH); } /* * Check the disk label information and retrieve needed vdev name-value pairs. * * Return: * 0 - success * ERR_* - failure */ int check_pool_label(uint64_t sector, char *stack, char *outdevid, char *outpath, uint64_t *outguid) { vdev_phys_t *vdev; uint64_t pool_state, txg = 0; char *nvlist, *nv; uint64_t diskguid; uint64_t version; sector += (VDEV_SKIP_SIZE >> SPA_MINBLOCKSHIFT); /* Read in the vdev name-value pair list (112K). */ if (devread(sector, 0, VDEV_PHYS_SIZE, stack) == 0) return (ERR_READ); vdev = (vdev_phys_t *)stack; stack += sizeof (vdev_phys_t); if (nvlist_unpack(vdev->vp_nvlist, &nvlist)) return (ERR_FSYS_CORRUPT); if (nvlist_lookup_value(nvlist, ZPOOL_CONFIG_POOL_STATE, &pool_state, DATA_TYPE_UINT64, NULL)) return (ERR_FSYS_CORRUPT); if (pool_state == POOL_STATE_DESTROYED) return (ERR_FILESYSTEM_NOT_FOUND); if (nvlist_lookup_value(nvlist, ZPOOL_CONFIG_POOL_NAME, current_rootpool, DATA_TYPE_STRING, NULL)) return (ERR_FSYS_CORRUPT); if (nvlist_lookup_value(nvlist, ZPOOL_CONFIG_POOL_TXG, &txg, DATA_TYPE_UINT64, NULL)) return (ERR_FSYS_CORRUPT); /* not an active device */ if (txg == 0) return (ERR_NO_BOOTPATH); if (nvlist_lookup_value(nvlist, ZPOOL_CONFIG_VERSION, &version, DATA_TYPE_UINT64, NULL)) return (ERR_FSYS_CORRUPT); if (version > SPA_VERSION) return (ERR_NEWER_VERSION); if (nvlist_lookup_value(nvlist, ZPOOL_CONFIG_VDEV_TREE, &nv, DATA_TYPE_NVLIST, NULL)) return (ERR_FSYS_CORRUPT); if (nvlist_lookup_value(nvlist, ZPOOL_CONFIG_GUID, &diskguid, DATA_TYPE_UINT64, NULL)) return (ERR_FSYS_CORRUPT); if (vdev_get_bootpath(nv, diskguid, outdevid, outpath, 0)) return (ERR_NO_BOOTPATH); if (nvlist_lookup_value(nvlist, ZPOOL_CONFIG_POOL_GUID, outguid, DATA_TYPE_UINT64, NULL)) return (ERR_FSYS_CORRUPT); return (0); } /* * zfs_mount() locates a valid uberblock of the root pool and read in its MOS * to the memory address MOS. * * Return: * 1 - success * 0 - failure */ int zfs_mount(void) { char *stack; int label = 0; uberblock_phys_t *ub_array, *ubbest; objset_phys_t *osp; char tmp_bootpath[MAXNAMELEN]; char tmp_devid[MAXNAMELEN]; uint64_t tmp_guid; uint64_t adjpl = (uint64_t)part_length << SPA_MINBLOCKSHIFT; int err = errnum; /* preserve previous errnum state */ /* if it's our first time here, zero the best uberblock out */ if (best_drive == 0 && best_part == 0 && find_best_root) { grub_memset(&current_uberblock, 0, sizeof (uberblock_t)); pool_guid = 0; } stackbase = ZFS_SCRATCH; stack = stackbase; ub_array = (uberblock_phys_t *)stack; stack += VDEV_UBERBLOCK_RING; osp = (objset_phys_t *)stack; stack += sizeof (objset_phys_t); adjpl = P2ALIGN(adjpl, (uint64_t)sizeof (vdev_label_t)); for (label = 0; label < VDEV_LABELS; label++) { uint64_t sector; /* * some eltorito stacks don't give us a size and * we end up setting the size to MAXUINT, further * some of these devices stop working once a single * read past the end has been issued. Checking * for a maximum part_length and skipping the backup * labels at the end of the slice/partition/device * avoids breaking down on such devices. */ if (part_length == MAXUINT && label == 2) break; sector = vdev_label_start(adjpl, label) >> SPA_MINBLOCKSHIFT; /* Read in the uberblock ring (128K). */ if (devread(sector + ((VDEV_SKIP_SIZE + VDEV_PHYS_SIZE) >> SPA_MINBLOCKSHIFT), 0, VDEV_UBERBLOCK_RING, (char *)ub_array) == 0) continue; if ((ubbest = find_bestub(ub_array, sector)) != NULL && zio_read(&ubbest->ubp_uberblock.ub_rootbp, osp, stack) == 0) { VERIFY_OS_TYPE(osp, DMU_OST_META); if (check_pool_label(sector, stack, tmp_devid, tmp_bootpath, &tmp_guid)) continue; if (pool_guid == 0) pool_guid = tmp_guid; if (find_best_root && ((pool_guid != tmp_guid) || vdev_uberblock_compare(&ubbest->ubp_uberblock, &(current_uberblock)) <= 0)) continue; /* Got the MOS. Save it at the memory addr MOS. */ grub_memmove(MOS, &osp->os_meta_dnode, DNODE_SIZE); grub_memmove(&current_uberblock, &ubbest->ubp_uberblock, sizeof (uberblock_t)); grub_memmove(current_bootpath, tmp_bootpath, MAXNAMELEN); grub_memmove(current_devid, tmp_devid, grub_strlen(tmp_devid)); is_zfs_mount = 1; return (1); } } /* * While some fs impls. (tftp) rely on setting and keeping * global errnums set, others won't reset it and will break * when issuing rawreads. The goal here is to simply not * have zfs mount attempts impact the previous state. */ errnum = err; return (0); } /* * zfs_open() locates a file in the rootpool by following the * MOS and places the dnode of the file in the memory address DNODE. * * Return: * 1 - success * 0 - failure */ int zfs_open(char *filename) { char *stack; dnode_phys_t *mdn; file_buf = NULL; stackbase = ZFS_SCRATCH; stack = stackbase; mdn = (dnode_phys_t *)stack; stack += sizeof (dnode_phys_t); dnode_mdn = NULL; dnode_buf = (dnode_phys_t *)stack; stack += 1<<DNODE_BLOCK_SHIFT; /* * menu.lst is placed at the root pool filesystem level, * do not goto 'current_bootfs'. */ if (is_top_dataset_file(filename)) { if ((errnum = get_objset_mdn(MOS, NULL, NULL, mdn, stack))) return (0); current_bootfs_obj = 0; } else { if (current_bootfs[0] == '\0') { /* Get the default root filesystem object number */ if ((errnum = get_default_bootfsobj(MOS, &current_bootfs_obj, stack))) return (0); if ((errnum = get_objset_mdn(MOS, NULL, &current_bootfs_obj, mdn, stack))) return (0); } else { if ((errnum = get_objset_mdn(MOS, current_bootfs, &current_bootfs_obj, mdn, stack))) { grub_memset(current_bootfs, 0, MAXNAMELEN); return (0); } } } if (dnode_get_path(mdn, filename, DNODE, stack)) { errnum = ERR_FILE_NOT_FOUND; return (0); } /* get the file size and set the file position to 0 */ /* * For DMU_OT_SA we will need to locate the SIZE attribute * attribute, which could be either in the bonus buffer * or the "spill" block. */ if (DNODE->dn_bonustype == DMU_OT_SA) { sa_hdr_phys_t *sahdrp; int hdrsize; if (DNODE->dn_bonuslen != 0) { sahdrp = (sa_hdr_phys_t *)DN_BONUS(DNODE); } else { if (DNODE->dn_flags & DNODE_FLAG_SPILL_BLKPTR) { blkptr_t *bp = &DNODE->dn_spill; void *buf; buf = (void *)stack; stack += BP_GET_LSIZE(bp); /* reset errnum to rawread() failure */ errnum = 0; if (zio_read(bp, buf, stack) != 0) { return (0); } sahdrp = buf; } else { errnum = ERR_FSYS_CORRUPT; return (0); } } hdrsize = SA_HDR_SIZE(sahdrp); filemax = *(uint64_t *)((char *)sahdrp + hdrsize + SA_SIZE_OFFSET); } else { filemax = ((znode_phys_t *)DN_BONUS(DNODE))->zp_size; } filepos = 0; dnode_buf = NULL; return (1); } /* * zfs_read reads in the data blocks pointed by the DNODE. * * Return: * len - the length successfully read in to the buffer * 0 - failure */ int zfs_read(char *buf, int len) { char *stack; int blksz, length, movesize; if (file_buf == NULL) { file_buf = stackbase; stackbase += SPA_MAXBLOCKSIZE; file_start = file_end = 0; } stack = stackbase; /* * If offset is in memory, move it into the buffer provided and return. */ if (filepos >= file_start && filepos+len <= file_end) { grub_memmove(buf, file_buf + filepos - file_start, len); filepos += len; return (len); } blksz = DNODE->dn_datablkszsec << SPA_MINBLOCKSHIFT; /* * Entire Dnode is too big to fit into the space available. We * will need to read it in chunks. This could be optimized to * read in as large a chunk as there is space available, but for * now, this only reads in one data block at a time. */ length = len; while (length) { /* * Find requested blkid and the offset within that block. */ uint64_t blkid = filepos / blksz; if ((errnum = dmu_read(DNODE, blkid, file_buf, stack))) return (0); file_start = blkid * blksz; file_end = file_start + blksz; movesize = MIN(length, file_end - filepos); grub_memmove(buf, file_buf + filepos - file_start, movesize); buf += movesize; length -= movesize; filepos += movesize; } return (len); } /* * No-Op */ int zfs_embed(int *start_sector, int needed_sectors) { return (1); } #endif /* FSYS_ZFS */
the_stack_data/26892.c
#include <stdio.h> #include <stdlib.h> #define MAX 32767 #define MAXSIZE 100 typedef struct { int data[MAXSIZE]; int top; } SqStack; void Dij(int m, int matrix[m][m]); void dij(int m, int n, int matrix[m][m]); void Floyd(int m, int matrix[m][m]); void InitStack(SqStack **s); int Push(SqStack *s, int i); int Pop(SqStack *s); int main(void) { /* int matrix[4][4] = { {0, 1, MAX, 4}, {MAX, 0, 9, 2}, {3, 5, 0, 8}, {MAX, MAX, 6, 0}}; */ int matrix[6][6] = { {0, MAX, 10, MAX, 30, 100}, {MAX, 0, 5, MAX, MAX, MAX}, {MAX, MAX, 0, 50, MAX, MAX}, {MAX, MAX, MAX, 0, MAX, 10}, {MAX, MAX, MAX, 20, 0, 60}, {MAX, MAX, MAX, MAX, MAX, 0}}; //Dij(6, matrix); dij(6,0,matrix); //Floyd(6, matrix); } void dij(int m, int n, int matrix[m][m]) { int x[m], y[m], flag[m], Path[m][m]; for (int i = 0; i < m; i++) { x[i] = matrix[n][i]; y[i] = -1; flag[i] = 0; for (int j = 0; j < m; j++) Path[i][j] = -1; } flag[n] = 1; int l = 0; int V = MAX; for (int i = 0; i < m - 1; i++) { l = 0; V = MAX; for (int j = 0; j < m; j++) { if (flag[j] != 1 && x[j] < V) { l = j; V = x[j]; } } if (V == MAX) continue; flag[l] = 1; int o = 0; printf("%d", n); if (y[l] != -1) { while (Path[y[l]][o] != -1) { printf("->%d", Path[y[l]][o]); Path[l][o] = Path[y[l]][o]; o++; } printf("->%d", y[l]); Path[l][o] = y[l]; } printf("->%d value:%d\n", l, V); for (int j = 0; j < m; j++) { if (matrix[l][j] + V < x[j]) { x[j] = matrix[l][j] + V; y[j] = l; } } } } void Floyd(int m, int matrix[m][m]) { int d[m][m], p[m][m]; for (int i = 0; i < m; i++) for (int j = 0; j < m; j++) { if (matrix[i][j] != MAX) p[i][j] = i; else p[i][j] = -1; d[i][j] = matrix[i][j]; }; for (int i = 0; i < m; i++) { for (int x = 0; x < m; x++) { for (int y = 0; y < m; y++) { if (d[x][y] > d[x][i] + d[i][y]) { d[x][y] = d[x][i] + d[i][y]; p[x][y] = p[i][y]; } } } } SqStack *s; for (int i = 0; i < m; i++) { for (int j = 0; j < m; j++) { if (i == j || d[i][j] == MAX) { continue; }; InitStack(&s); printf("%d", i); int t = p[i][j]; while (t != i) { Push(s, t); t = p[i][t]; } t = Pop(s); while (t != -1) { printf("->%d", t); t = Pop(s); } printf("->%d value:%d\n", j, d[i][j]); } } printf("\n"); } void Dij(int m, int matrix[m][m]) { for (int i = 0; i < m; i++) { dij(m, i, matrix); } printf("\n"); } void InitStack(SqStack **s) { *s = (SqStack *)malloc(sizeof(SqStack)); (*s)->top = -1; } int Push(SqStack *s, int i) { if (s->top == 100) return -1; s->data[++s->top] = i; return 1; } int Pop(SqStack *s) { if (s->top == -1) return -1; return s->data[s->top--]; }
the_stack_data/237643394.c
# 1 "/home/giulianob/gcc_git_gnu/gcc/libiberty/partition.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/partition.c" # 23 "/home/giulianob/gcc_git_gnu/gcc/libiberty/partition.c" # 1 "./config.h" 1 # 24 "/home/giulianob/gcc_git_gnu/gcc/libiberty/partition.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 # 33 "/usr/include/x86_64-linux-gnu/bits/libc-header-start.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 # 34 "/usr/include/x86_64-linux-gnu/bits/libc-header-start.h" 2 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 # 209 "/usr/lib/gcc/x86_64-linux-gnu/10/include/stddef.h" 3 4 # 209 "/usr/lib/gcc/x86_64-linux-gnu/10/include/stddef.h" 3 4 typedef long unsigned int size_t; # 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))) ; # 1 "/usr/include/x86_64-linux-gnu/sys/types.h" 1 3 4 # 27 "/usr/include/x86_64-linux-gnu/sys/types.h" 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 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 # 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 # 395 "/usr/include/stdlib.h" 2 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/partition.c" 2 # 1 "/usr/include/string.h" 1 3 4 # 26 "/usr/include/string.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/libc-header-start.h" 1 3 4 # 27 "/usr/include/string.h" 2 3 4 # 1 "/usr/lib/gcc/x86_64-linux-gnu/10/include/stddef.h" 1 3 4 # 34 "/usr/include/string.h" 2 3 4 # 43 "/usr/include/string.h" 3 4 extern void *memcpy (void *__restrict __dest, const void *__restrict __src, size_t __n) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); extern void *memmove (void *__dest, const void *__src, size_t __n) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); extern void *memccpy (void *__restrict __dest, const void *__restrict __src, int __c, size_t __n) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); extern void *memset (void *__s, int __c, size_t __n) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); extern int memcmp (const void *__s1, const void *__s2, size_t __n) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); # 91 "/usr/include/string.h" 3 4 extern void *memchr (const void *__s, int __c, size_t __n) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); # 104 "/usr/include/string.h" 3 4 extern void *rawmemchr (const void *__s, int __c) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); # 115 "/usr/include/string.h" 3 4 extern void *memrchr (const void *__s, int __c, size_t __n) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); extern char *strcpy (char *__restrict __dest, const char *__restrict __src) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); extern char *strncpy (char *__restrict __dest, const char *__restrict __src, size_t __n) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); extern char *strcat (char *__restrict __dest, const char *__restrict __src) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); extern char *strncat (char *__restrict __dest, const char *__restrict __src, size_t __n) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); extern int strcmp (const char *__s1, const char *__s2) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern int strncmp (const char *__s1, const char *__s2, size_t __n) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern int strcoll (const char *__s1, const char *__s2) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern size_t strxfrm (char *__restrict __dest, const char *__restrict __src, size_t __n) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2))); extern int strcoll_l (const char *__s1, const char *__s2, locale_t __l) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2, 3))); extern size_t strxfrm_l (char *__dest, const char *__src, size_t __n, locale_t __l) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2, 4))); extern char *strdup (const char *__s) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__malloc__)) __attribute__ ((__nonnull__ (1))); extern char *strndup (const char *__string, size_t __n) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__malloc__)) __attribute__ ((__nonnull__ (1))); # 226 "/usr/include/string.h" 3 4 extern char *strchr (const char *__s, int __c) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); # 253 "/usr/include/string.h" 3 4 extern char *strrchr (const char *__s, int __c) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); # 266 "/usr/include/string.h" 3 4 extern char *strchrnul (const char *__s, int __c) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); extern size_t strcspn (const char *__s, const char *__reject) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern size_t strspn (const char *__s, const char *__accept) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); # 303 "/usr/include/string.h" 3 4 extern char *strpbrk (const char *__s, const char *__accept) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); # 330 "/usr/include/string.h" 3 4 extern char *strstr (const char *__haystack, const char *__needle) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern char *strtok (char *__restrict __s, const char *__restrict __delim) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2))); extern char *__strtok_r (char *__restrict __s, const char *__restrict __delim, char **__restrict __save_ptr) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2, 3))); extern char *strtok_r (char *__restrict __s, const char *__restrict __delim, char **__restrict __save_ptr) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2, 3))); # 360 "/usr/include/string.h" 3 4 extern char *strcasestr (const char *__haystack, const char *__needle) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern void *memmem (const void *__haystack, size_t __haystacklen, const void *__needle, size_t __needlelen) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 3))); extern void *__mempcpy (void *__restrict __dest, const void *__restrict __src, size_t __n) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); extern void *mempcpy (void *__restrict __dest, const void *__restrict __src, size_t __n) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); extern size_t strlen (const char *__s) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); extern size_t strnlen (const char *__string, size_t __maxlen) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); extern char *strerror (int __errnum) __attribute__ ((__nothrow__ , __leaf__)); # 421 "/usr/include/string.h" 3 4 extern char *strerror_r (int __errnum, char *__buf, size_t __buflen) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (2))) ; extern char *strerror_l (int __errnum, locale_t __l) __attribute__ ((__nothrow__ , __leaf__)); # 1 "/usr/include/strings.h" 1 3 4 # 23 "/usr/include/strings.h" 3 4 # 1 "/usr/lib/gcc/x86_64-linux-gnu/10/include/stddef.h" 1 3 4 # 24 "/usr/include/strings.h" 2 3 4 extern int bcmp (const void *__s1, const void *__s2, size_t __n) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern void bcopy (const void *__src, void *__dest, size_t __n) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); extern void bzero (void *__s, size_t __n) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); # 68 "/usr/include/strings.h" 3 4 extern char *index (const char *__s, int __c) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); # 96 "/usr/include/strings.h" 3 4 extern char *rindex (const char *__s, int __c) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); extern int ffs (int __i) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__const__)); extern int ffsl (long int __l) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__const__)); __extension__ extern int ffsll (long long int __ll) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__const__)); extern int strcasecmp (const char *__s1, const char *__s2) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern int strncasecmp (const char *__s1, const char *__s2, size_t __n) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern int strcasecmp_l (const char *__s1, const char *__s2, locale_t __loc) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2, 3))); extern int strncasecmp_l (const char *__s1, const char *__s2, size_t __n, locale_t __loc) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2, 4))); # 433 "/usr/include/string.h" 2 3 4 extern void explicit_bzero (void *__s, size_t __n) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); extern char *strsep (char **__restrict __stringp, const char *__restrict __delim) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); extern char *strsignal (int __sig) __attribute__ ((__nothrow__ , __leaf__)); extern char *__stpcpy (char *__restrict __dest, const char *__restrict __src) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); extern char *stpcpy (char *__restrict __dest, const char *__restrict __src) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); extern char *__stpncpy (char *__restrict __dest, const char *__restrict __src, size_t __n) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); extern char *stpncpy (char *__restrict __dest, const char *__restrict __src, size_t __n) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1, 2))); extern int strverscmp (const char *__s1, const char *__s2) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern char *strfry (char *__string) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); extern void *memfrob (void *__s, size_t __n) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); # 487 "/usr/include/string.h" 3 4 extern char *basename (const char *__filename) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__nonnull__ (1))); # 499 "/usr/include/string.h" 3 4 # 32 "/home/giulianob/gcc_git_gnu/gcc/libiberty/partition.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__)); # 35 "/home/giulianob/gcc_git_gnu/gcc/libiberty/partition.c" 2 # 1 "/home/giulianob/gcc_git_gnu/gcc/libiberty/../include/partition.h" 1 # 46 "/home/giulianob/gcc_git_gnu/gcc/libiberty/../include/partition.h" struct partition_elem { struct partition_elem* next; int class_element; unsigned class_count; }; typedef struct partition_def { int num_elements; struct partition_elem elements[1]; } *partition; extern partition partition_new (int); extern void partition_delete (partition); extern int partition_union (partition, int, int); extern void partition_print (partition, FILE*); # 36 "/home/giulianob/gcc_git_gnu/gcc/libiberty/partition.c" 2 static int elem_compare (const void *, const void *); partition partition_new (int num_elements) { int e; partition part = (partition) xmalloc (sizeof (struct partition_def) + (num_elements - 1) * sizeof (struct partition_elem)); part->num_elements = num_elements; for (e = 0; e < num_elements; ++e) { part->elements[e].class_element = e; part->elements[e].next = &(part->elements[e]); part->elements[e].class_count = 1; } return part; } void partition_delete (partition part) { free (part); } int partition_union (partition part, int elem1, int elem2) { struct partition_elem *elements = part->elements; struct partition_elem *e1; struct partition_elem *e2; struct partition_elem *p; struct partition_elem *old_next; int class_element = elements[elem1].class_element; if (class_element == elements[elem2].class_element) return class_element; if (elements[elem1].class_count < elements[elem2].class_count) { int temp = elem1; elem1 = elem2; elem2 = temp; class_element = elements[elem1].class_element; } e1 = &(elements[elem1]); e2 = &(elements[elem2]); elements[class_element].class_count += elements[e2->class_element].class_count; e2->class_element = class_element; for (p = e2->next; p != e2; p = p->next) p->class_element = class_element; old_next = e1->next; e1->next = e2->next; e2->next = old_next; return class_element; } static int elem_compare (const void *elem1, const void *elem2) { int e1 = * (const int *) elem1; int e2 = * (const int *) elem2; if (e1 < e2) return -1; else if (e1 > e2) return 1; else return 0; } void partition_print (partition part, FILE *fp) { char *done; int num_elements = part->num_elements; struct partition_elem *elements = part->elements; int *class_elements; int e; done = (char *) xmalloc (num_elements); memset (done, 0, num_elements); class_elements = (int *) xmalloc (num_elements * sizeof (int)); fputc ('[', fp); for (e = 0; e < num_elements; ++e) if (! done[e]) { int c = e; int count = elements[elements[e].class_element].class_count; int i; for (i = 0; i < count; ++i) { class_elements[i] = c; done[c] = 1; c = elements[c].next - elements; } qsort ((void *) class_elements, count, sizeof (int), elem_compare); fputc ('(', fp); for (i = 0; i < count; ++i) fprintf (fp, i == 0 ? "%d" : " %d", class_elements[i]); fputc (')', fp); } fputc (']', fp); free (class_elements); free (done); }
the_stack_data/175143393.c
/*Exercise 3 - Repetition Write a C program to calculate the sum of the numbers from 1 to n. Where n is a keyboard input. e.g. n -> 100 sum = 1+2+3+....+ 99+100 = 5050 n -> 1- sum = 1+2+3+...+10 = 55 */ #include <stdio.h> int main() { int n, num, sum=0; printf("Enter a final number to take a sum : "); scanf("%d",&n); for(int num=0;num<=n;num++){ sum=sum+num; } printf("sum of the numbers until the number you entered: %d",sum); return 0; }
the_stack_data/97214.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdbool.h> long accumulator = 0; #define MAX_LINES 1024 #define MAX_LINE_LEN 10 int parse_value(char l[MAX_LINES][MAX_LINE_LEN], int i) { char val[4]; size_t len = strlen(l[i]) - 1; int ival = 0; for (int z = 5; z < len; z++) { val[ival] = l[i][z]; ival++; } val[ival] = '\0'; const char *inc = val; return strtol(inc, NULL, 0); } void solve(char l[MAX_LINES][MAX_LINE_LEN], int lcount) { char init[MAX_LINES][MAX_LINE_LEN]; memcpy(init, l, sizeof(char) * MAX_LINES * MAX_LINE_LEN); bool seen[MAX_LINES] = {}; bool fix_tried[MAX_LINES] = {}; bool solved1 = false; for (long i = 0; i < lcount; i++) { if (seen[i]) { if (!solved1) { printf("pt.1: %d\n", accumulator); solved1 = true; } memset(l, 0, sizeof(char) * MAX_LINES * MAX_LINE_LEN); memcpy(l, init, sizeof(char) * MAX_LINES * MAX_LINE_LEN); accumulator = 0; for (long j = 0; j < MAX_LINES; j++) { seen[j] = false; } for (long z = 0; z < lcount; z++) { if (fix_tried[z]) { continue; } char op[4] = {l[z][0], l[z][1], l[z][2], '\0'}; if (strcmp(op, "nop") == 0) { l[z][0] = 'j'; l[z][1] = 'm'; l[z][2] = 'p'; fix_tried[z] = true; break; } else if (strcmp(op, "jmp") == 0) { l[z][0] = 'n'; l[z][1] = 'o'; l[z][2] = 'p'; fix_tried[z] = true; break; } } i = 0; } seen[i] = true; char op[4] = {l[i][0], l[i][1], l[i][2], '\0'}; char sign[2] = {l[i][4], '\0'}; int opsign = 0x01; if (strcmp(sign, "+") == 0) { opsign = 0x02; } long val = parse_value(l, i); if (strcmp(op, "acc") == 0) { if (opsign == 0x02) { accumulator += val; } else { accumulator -= val; } } else if (strcmp(op, "jmp") == 0) { if (opsign == 0x02) { val -= 1; i += val; } else { val += 1; i -= val; } } } printf("pt.2: %d\n", accumulator); } int read_file(char l[MAX_LINES][MAX_LINE_LEN]) { int i = 0; FILE *fp = fopen("input.txt", "r"); while (i < MAX_LINES && fgets(l[i], sizeof(l[0]), fp)) { i++; } l[i - 1][6] = '\n'; fclose(fp); return i; } int main() { char l[MAX_LINES][MAX_LINE_LEN]; int lcount = read_file(l); solve(l, lcount); }
the_stack_data/170452479.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_print_program_name.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: lgavalda <[email protected]> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/16 00:55:23 by lgavalda #+# #+# */ /* Updated: 2019/07/16 00:58:22 by lgavalda ### ########.fr */ /* */ /* ************************************************************************** */ #include <unistd.h> int main(int ac, char **av) { (void)ac; while (*av[0]) { write(1, av[0]++, 1); } write(1, "\n", 1); return (0); }
the_stack_data/167330303.c
#include <stdio.h> #include <time.h> struct timeStruct { struct tm *systime; struct tm *usertime; }; int main(int argc, char const *argv[]) { struct timeStruct Time; time_t systime; time(&systime); Time.systime = localtime(&systime); time_t usertime; char usertimestring[256]; printf("Enter time in the following format YYYY/MM/DD H:M:S (24 hour format): "); fgets(usertimestring, 255, stdin); time_t result = 0; int year = 0, month = 0, day = 0, hour = 0, min = 0, sec = 0; if (sscanf(usertimestring, "%4d/%2d/%2d %2d:%2d:%2d", &year, &month, &day, &hour, &min, &sec) == 6) { struct tm when = {0}; when.tm_year = 50; when.tm_year = year - 1900; when.tm_mon = month - 1; when.tm_mday = day; when.tm_hour = hour; when.tm_min = min; Time.usertime = &when; if ((result = mktime(Time.usertime)) == (time_t)-1) { printf("Could not convert time input to time_t\n"); } } else { printf("The input was not a valid time format\n"); } printf("Sys time: %s", asctime(Time.systime)); printf("User time: %s", asctime(Time.usertime)); int totalSeconds = difftime(systime, mktime(Time.usertime)); int seconds = (totalSeconds % 60); int minutes = (totalSeconds % 3600) / 60; int hours = (totalSeconds % 86400) / 3600; int days = (totalSeconds % (86400 * 30)) / 86400; int months = (totalSeconds % (86400 * 30 * 12)) / (86400 * 30); printf("Time difference is "); printf("%i months, %i days, %i hours, %i minutes, %i seconds", months, days, hours, minutes, seconds); return 0; }
the_stack_data/154826786.c
//This gets parametric ReLU activation function for each element of X. //This is also called the leaky ReLU (where default alpha is 0.01). //For compatibility to PyTorch, this function is identical to leaky ReLU. #include <stdio.h> #ifdef __cplusplus namespace codee { extern "C" { #endif int prelu_s (float *Y, const float *X, const size_t N, const float alpha); int prelu_d (double *Y, const double *X, const size_t N, const double alpha); int prelu_inplace_s (float *X, const size_t N, const float alpha); int prelu_inplace_d (double *X, const size_t N, const double alpha); int prelu_s (float *Y, const float *X, const size_t N, const float alpha) { if (alpha==0.0f) { for (size_t n=N; n>0u; --n, ++X, ++Y) { *Y = (*X<0.0f) ? 0.0f : *X; } } else if (alpha==1.0f) { for (size_t n=N; n>0u; --n, ++X, ++Y) { *Y = *X; } } else { for (size_t n=N; n>0u; --n, ++X, ++Y) { *Y = (*X<0.0f) ? alpha**X : *X; } } return 0; } int prelu_d (double *Y, const double *X, const size_t N, const double alpha) { if (alpha==0.0) { for (size_t n=N; n>0u; --n, ++X, ++Y) { *Y = (*X<0.0) ? 0.0 : *X; } } else if (alpha==1.0) { for (size_t n=N; n>0u; --n, ++X, ++Y) { *Y = *X; } } else { for (size_t n=N; n>0u; --n, ++X, ++Y) { *Y = (*X<0.0) ? alpha**X : *X; } } return 0; } int prelu_inplace_s (float *X, const size_t N, const float alpha) { if (alpha==0.0f) { for (size_t n=N; n>0u; --n, ++X) { if (*X<0.0f) { *X = 0.0f; } } } else if (alpha==1.0f) {} else { for (size_t n=N; n>0u; --n, ++X) { if(*X<0.0f) { *X *= alpha; } } } return 0; } int prelu_inplace_d (double *X, const size_t N, const double alpha) { if (alpha==0.0) { for (size_t n=N; n>0u; --n, ++X) { if (*X<0.0) { *X = 0.0; } } } else if (alpha==1.0) {} else { for (size_t n=N; n>0u; --n, ++X) { if(*X<0.0) { *X *= alpha; } } } return 0; } #ifdef __cplusplus } } #endif
the_stack_data/77752.c
// RUN: %ucc -o %t %s // RUN: %t | %stdoutcheck %s // STDOUT: a // STDOUT-NEXT: b int printf(const char *, ...) __attribute__((format(printf, 1, 2))); static int (*fs[3])(); static int f_i; add(int (*f)()) { fs[f_i++] = f; } run() { for(int i = 0; fs[i]; i++) fs[i](); } a(){printf("a\n");} b(){printf("b\n");} main() { //printf("%p\n", fs); add(a); add(&b); run(); }
the_stack_data/50014.c
#include <stdlib.h> #include <stdio.h> #include <string.h> void creerFIC(char nom[], char DOS[]){ FILE* f; char nomF[256]; sprintf (nomF, "%s/%s", DOS, nom); f = fopen(nomF, "w" ); fclose(f); } void creerDOS(char nom[]){ char mk[256]="mkdir "; strcat(mk,nom); system(mk); char cd[256]="cd "; strcat(cd,nom); system(cd); } void WmakeF(char nom[], char DOS[]){ FILE* f; char chem[256]; creerFIC(nom, DOS); sprintf (chem, "%s/%s", DOS, nom); f = fopen(chem, "w" ); fprintf(f,"compil:\n gcc -o main main.c -Wall\nrun: main\n ./main\n"); fclose(f); } void ficC(char nom[], char DOS[]){ FILE* f; char chem[256]; creerFIC(nom, DOS); sprintf (chem, "%s/%s", DOS, nom); f = fopen(chem, "w" ); fprintf(f,"#include <stdlib.h>\n#include <stdio.h>\n\n\nint main(){\n//Votre code ici\nreturn 0;\n}"); fclose(f); } void ficPython(char nom[], char DOS[]){ FILE* f; char chem[256]; creerFIC(nom, DOS); sprintf (chem, "%s/%s", DOS, nom); f = fopen(chem, "w" ); fprintf(f,"print(\"Hello World !\")"); fclose(f); free(DOS); } void ficHTML(char nom[], char DOS[]){ FILE* f; char chem[256]; creerFIC(nom, DOS); sprintf (chem, "%s/%s", DOS, nom); f = fopen(chem, "w" ); fprintf(f,"<!doctype html>\n<html lang='fr'>\n <head>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n <meta name=\"author\" content=\"\">\n <meta name=\"description\" content=\"VOID\">\n <title>index</title>\n <link rel=\"icon\" href=\"\">\n <link rel=\"stylesheet\" href=\"PageCSS.css\">\n </head>\n \n<body>\n\n\n</body>\n"); fclose(f); } void ficCSS(char nom[], char DOS[]){ FILE* f; char chem[256]; creerFIC(nom, DOS); sprintf (chem, "%s/%s", DOS, nom); f = fopen(chem, "w" ); fprintf(f,"."); fclose(f); } void help(void) { system("clear"); printf("Utilisation : MMF [DOSSIER DE TRAVAIL][LANGAGE]\n\n"); printf("-0 | Ne crée pas de nouveau dossier de travail. Reste dans le répertoire courant\n\n"); printf("[Nom d'un nouveau dossier] | Crée un nouveau dossier de travail\n\n"); printf("-python ou -C ou -html | Choisit le langage\n\n"); printf("-UI | permet d'avoir un affichage plus graphique\n\n"); printf("-h | Affiche ce menu d'aide.\n\n"); } int ui(){ char DOS[256]; int choix1, choix0; choix1=0; choix0=-1; printf("\n###########################\n### Préparateur de Code ###\n###########################\n"); printf("\nComment souhaitez-vous nommer ce nouveau dossier de travail ? \n"); scanf("%s",DOS); creerDOS(DOS); // Module de choix à propos du langage printf("\n Quel langage souhaitez-vous ? \n ''1'' pour C, ''2'' pour HTML, ''3'' pour Python \n"); scanf("%d",&choix0); while(choix0){ if (choix0==1){ printf("\nLe langage choisis est le C\n"); // Module de choix à propos du makefile printf("\n Souhaitez-vous un Makefile ? \n ''1'' pour Oui, ''0'' pour non \n"); scanf("%d",&choix1); while(choix1!=1 || choix1!=0){ if (choix1==1){ printf("\nUn makefile sera ajouté à votre environnement de travail\n"); WmakeF("Makefile",DOS); ficC("main.c",DOS); return 1; } if(choix1==0){ printf("\nAucun makefile ne sera ajouté à votre environnement de travail\n"); ficC("main.c",DOS); return 1; } else{ return 999; } } } if(choix0==2){ printf("\nLe langage choisit est le HTML\n"); ficHTML("index.html",DOS); ficCSS("PageCSS.css",DOS); return 1; } if(choix0==3){ printf("\nLe langage choisit est le Python\n"); ficPython("script.py",DOS); return 1; } else{ printf("Pas compris"); return 999; } } } int main(int argc, char ** argv){ // MMF [Dossier o/n][Langage] int u; char *DOS; if (argc>3){ printf("Trop d'arguments, ""faites MMF -h""\n"); } // Dossier if (strcmp(argv[1], "-0") == 0){ DOS="."; } if (strcmp(argv[1], "-UI") == 0){ // Affichage graphique u=ui(); if (u==1){ return 1; } if (u==999){ help(); return 1; } } if (strcmp(argv[1], "-h") == 0){ help(); return 1; } if (strcmp(argv[1], "-0") != 0){ DOS = argv[1]; creerDOS(argv[1]); // avoir si on peut pas le retirer } // Choix du langage if (strcmp(argv[2], "-python") == 0){ printf("%s\n", DOS); ficPython("script.py",DOS); return 1; } if (strcmp(argv[2], "-C") == 0){ WmakeF("Makefile",DOS); ficC("main.c",DOS); return 1; } if (strcmp(argv[2], "-html") == 0){ ficHTML("index.html",DOS); ficCSS("PageCSS.css",DOS); return 1; } return 0; }
the_stack_data/8113.c
//file: _insn_test_v1cmpleu_X0.c //op=241 #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] = { 0xf650c1dfb5e7ad42, 0x58b08e812190ba77 }; int main(void) { unsigned long a[4] = { 0, 0 }; asm __volatile__ ( "moveli r3, -2057\n" "shl16insli r3, r3, 27159\n" "shl16insli r3, r3, -22172\n" "shl16insli r3, r3, 8048\n" "moveli r8, -12225\n" "shl16insli r8, r8, -10603\n" "shl16insli r8, r8, 1383\n" "shl16insli r8, r8, -9619\n" "moveli r14, -24673\n" "shl16insli r14, r14, 32616\n" "shl16insli r14, r14, 28197\n" "shl16insli r14, r14, -4516\n" "{ v1cmpleu r3, r8, r14 ; fnop }\n" "move %0, r3\n" "move %1, r8\n" "move %2, r14\n" :"=r"(a[0]),"=r"(a[1]),"=r"(a[2])); printf("%016lx\n", a[0]); printf("%016lx\n", a[1]); printf("%016lx\n", a[2]); return 0; }
the_stack_data/40763916.c
#include<stdio.h> void minmax(int *, int , int *, int *); int main() { int num[500]; int *min; int *max; int i, len; min = &num[0]; max = &num[0]; scanf("%d", &len); for(i = 0; i < len; i++) { scanf("%d", &num[i]); } minmax(num, len, min, max); return 0; } void minmax(int *arr, int size, int *min, int *max) { int i; for(i = 0; i < size; i++) { if(*min > arr[i]) { min = &arr[i]; } if(*max < arr[i]) { max = &arr[i]; } } printf("%d", *max + *min); }
the_stack_data/7105.c
#include <stdio.h> #include <stdlib.h> #include <time.h> void error(){ fprintf(stderr, "-1\n"); exit(EXIT_FAILURE); } int main(int argc, char * argv[]) { int i; if(argc != 4) error(); int n, a, b; n = atoi(argv[1]); a = atoi(argv[2]); b = atoi(argv[3]); if(n > 200 || a >= b) error(); srand(time(NULL)); for(i=0; i<n ; i++) { int random = rand(); printf("%d\n", random); } return 0; }
the_stack_data/3263415.c
#include<stdio.h> int main() { char a; scanf("%c",&a); printf("The ASCII of character '%c' is %d.\n",a,a); return 0; }
the_stack_data/78744.c
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct stru_node { struct stru_node *next; int v; } node; /* remove the first element of the list and return the new head */ node * pop(node * head); /* add integer e as the first element of the list and return the new head */ node * push(node * head, int e); /* frees all memory associated with the list and returns NULL */ node * destroy(node * head); /* print the elements of the integers in the list, one per line */ void print(node * head); /* compara duas listas */ int is_eq(node *h1, node *h2); /* devolve uma nova lista que corresponda a lista dada invertida */ node * rev(node * head); int is_palind() { int i, len, eq; node * head = NULL, * head2 = NULL; char * str = malloc(sizeof(char)*80); scanf("%s", str); len = strlen(str); for (i = 0; i < len; i++) { head = push(head, (str+i)[0]); } head2 = rev(head); eq = is_eq(head, head2); destroy(head); destroy(head2); return eq; } int main() { printf(is_palind() ? "yes\n" : "no\n"); return 0; } node * pop(node * head) { node * next = head->next; free(head); return next; } node * push(node * head, int e) { node * new_head = malloc(sizeof(node)); new_head->next = head; new_head->v = e; return new_head; } void print(node * head) { while (head != NULL) { printf("%d\n", head-> v); head = head->next; } } node * destroy(node * head) { while (head != NULL) head = pop(head); return NULL; } int is_eq(node * h1, node * h2) { if (h1 == NULL || h2 == NULL) { return h1 == NULL && h2 == NULL; } if (h1->v == h2->v) { if (h1->next == NULL && h2->next == NULL) return 1; return is_eq(h1->next, h2->next); } return 0; } node *rev(node * head) { node * new_head = NULL; while (head != NULL) { new_head = push(new_head, head->v); head = head->next; } return new_head; }
the_stack_data/62638779.c
int subtract(int a, int b) { return a - b; } int main() { return subtract(52, 25); }
the_stack_data/154828418.c
#include <stdio.h> #include <stdlib.h> int main(int argc, char** argv) { int n = atoi(argv[1]); FILE *file; file = fopen("numbers.txt", "w"); fprintf(file, "%d\n", n); for (unsigned int i = 0; i < n; i++) fprintf(file, "%d ", rand() % 60000 - 30000); fclose(file); return 0; }
the_stack_data/243893536.c
#include <math.h> // void visc_force(int N, double *f, double *vis, double *velo) { // int i; // for (i = 0; i < N; i++) { // f[i] = -vis[i] * velo[i]; // } // } // void wind_force(int N, double *f, double *vis, double velo) { // int i; // for (i = 0; i < N; i++) { // f[i] = f[i] - vis[i] * velo; // } // } void add_norm(int N, double *r, double *delta) { int k; for (k = 0; k < N; k++) { r[k] += (delta[k] * delta[k]); } } double force(double W, double delta, double r) { return W * delta / (pow(r, 3.0)); } void new_force(int N, double *f, double *vis, double *velo, double wind) { int i; #pragma ivdep #pragma vector aligned for (i = 0; i < N; i++) { f[i] = -vis[i] * velo[i] - vis[i] * wind; } }
the_stack_data/98202.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> #include <fcntl.h> #include <unistd.h> #include <pthread.h> char buffer[128]; int has_data=0; pthread_mutex_t mutex; pthread_cond_t cond; pthread_cond_t cond2; void read_buf(void) { do { printf("lock read_buf\n"); pthread_mutex_lock(&mutex);//锁定互斥锁 printf("read_buf\n"); if(has_data==0) { printf("wait read data\n"); /*阻塞线程,等待另外一个线程发送信号,同时为公共数据区解锁*/ pthread_cond_wait(&cond,&mutex); } else if(has_data==1) { printf("the data : %s\n",buffer); has_data=0; pthread_cond_signal(&cond2); } pthread_mutex_unlock(&mutex);//打开互斥锁 printf("unlock read_buf\n"); }while(strcmp(buffer,"#")!=0); pthread_exit(NULL); } void write_buf(void) { char input[128]; do { printf("lock write_buf\n"); pthread_mutex_lock(&mutex); printf("write_buf\n"); if(has_data==0) { memset(input,'\0',128); printf("input data:\n"); scanf("%s",input); sprintf(buffer,"%s",input); has_data=1; pthread_cond_signal(&cond);//条件改变,唤醒阻塞的线程 } else if(has_data==1) { pthread_cond_wait(&cond2,&mutex); } pthread_mutex_unlock(&mutex); printf("unlock write_buf\n"); }while(strcmp(input,"#")!=0); pthread_exit(NULL); } int main(int argc,char **argv) { pthread_t id,id2; pthread_cond_init(&cond,NULL); pthread_cond_init(&cond2,NULL); pthread_mutex_init(&mutex,NULL); pthread_create(&id,NULL,(void *)read_buf,NULL);//返回值为0,创建成功 pthread_create(&id2,NULL,(void *)write_buf,NULL); pthread_join(id,NULL); pthread_join(id2,NULL); pthread_mutex_destroy(&mutex); pthread_cond_destroy(&cond); pthread_cond_destroy(&cond2); return 0; }
the_stack_data/140764842.c
typedef enum {false,true} bool; extern int __VERIFIER_nondet_int(void); int main() { int x; int y; int tmp; int xtmp; x = __VERIFIER_nondet_int(); y = __VERIFIER_nondet_int(); while(y > 0 && x > 0) { tmp = y; xtmp = x; while(xtmp>=y && y > 0) { xtmp = xtmp - y; } y = xtmp; x = tmp; } return 0; }
the_stack_data/1020617.c
/* * Copyright (C) 2004-2006 Kay Sievers <[email protected]> * Copyright (C) 2006 Hannes Reinecke <[email protected]> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation version 2 of the License. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ #include <stdlib.h> #include <stddef.h> #include <stdarg.h> #include <string.h> #include <stdio.h> #include <unistd.h> #include <getopt.h> #include <errno.h> #include <dirent.h> #include <fcntl.h> #include <syslog.h> #include <sys/stat.h> #include <sys/types.h> #define PATH_SIZE 512 static int verbose; static int dry_run; void log_message(int priority, const char *format, ...) { va_list args; va_start(args, format); vsyslog(priority, format, args); va_end(args); } #undef err #define err(format, arg...) \ do { \ log_message(LOG_ERR ,"%s: " format ,__FUNCTION__ ,## arg); \ } while (0) #undef info #define info(format, arg...) \ do { \ log_message(LOG_INFO ,"%s: " format ,__FUNCTION__ ,## arg); \ } while (0) #ifdef DEBUG #undef dbg #define dbg(format, arg...) \ do { \ log_message(LOG_DEBUG ,"%s: " format ,__FUNCTION__ ,## arg); \ } while (0) #else #define dbg(...) do {} while(0) #endif static void trigger_uevent(const char *devpath) { char filename[PATH_SIZE]; int fd; strlcpy(filename, "/sys", sizeof(filename)); strlcat(filename, devpath, sizeof(filename)); strlcat(filename, "/uevent", sizeof(filename)); if (verbose) printf("%s\n", devpath); if (dry_run) return; fd = open(filename, O_WRONLY); if (fd < 0) { dbg("error on opening %s: %s\n", filename, strerror(errno)); return; } if (write(fd, "add", 3) < 0) info("error on triggering %s: %s\n", filename, strerror(errno)); close(fd); } static int sysfs_resolve_link(char *devpath, size_t size) { char link_path[PATH_SIZE]; char link_target[PATH_SIZE]; int len; int i; int back; strlcpy(link_path, "/sys", sizeof(link_path)); strlcat(link_path, devpath, sizeof(link_path)); len = readlink(link_path, link_target, sizeof(link_target)); if (len <= 0) return -1; link_target[len] = '\0'; dbg("path link '%s' points to '%s'", devpath, link_target); for (back = 0; strncmp(&link_target[back * 3], "../", 3) == 0; back++) ; dbg("base '%s', tail '%s', back %i", devpath, &link_target[back * 3], back); for (i = 0; i <= back; i++) { char *pos = strrchr(devpath, '/'); if (pos == NULL) return -1; pos[0] = '\0'; } dbg("after moving back '%s'", devpath); strlcat(devpath, "/", size); strlcat(devpath, &link_target[back * 3], size); return 0; } static int device_list_insert(const char *path) { char filename[PATH_SIZE]; char devpath[PATH_SIZE]; struct stat statbuf; dbg("add '%s'" , path); /* we only have a device, if we have an uevent file */ strlcpy(filename, path, sizeof(filename)); strlcat(filename, "/uevent", sizeof(filename)); if (stat(filename, &statbuf) < 0) return -1; if (!(statbuf.st_mode & S_IWUSR)) return -1; strlcpy(devpath, &path[4], sizeof(devpath)); /* resolve possible link to real target */ if (lstat(path, &statbuf) < 0) return -1; if (S_ISLNK(statbuf.st_mode)) if (sysfs_resolve_link(devpath, sizeof(devpath)) != 0) return -1; trigger_uevent(devpath); return 0; } static void scan_subsystem(const char *subsys) { char base[PATH_SIZE]; DIR *dir; struct dirent *dent; strlcpy(base, "/sys/", sizeof(base)); strlcat(base, subsys, sizeof(base)); dir = opendir(base); if (dir != NULL) { for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) { char dirname[PATH_SIZE]; DIR *dir2; struct dirent *dent2; if (dent->d_name[0] == '.') continue; strlcpy(dirname, base, sizeof(dirname)); strlcat(dirname, "/", sizeof(dirname)); strlcat(dirname, dent->d_name, sizeof(dirname)); strlcat(dirname, "/devices", sizeof(dirname)); /* look for devices */ dir2 = opendir(dirname); if (dir2 != NULL) { for (dent2 = readdir(dir2); dent2 != NULL; dent2 = readdir(dir2)) { char dirname2[PATH_SIZE]; if (dent2->d_name[0] == '.') continue; strlcpy(dirname2, dirname, sizeof(dirname2)); strlcat(dirname2, "/", sizeof(dirname2)); strlcat(dirname2, dent2->d_name, sizeof(dirname2)); device_list_insert(dirname2); } closedir(dir2); } } closedir(dir); } } static void scan_block(void) { char base[PATH_SIZE]; DIR *dir; struct dirent *dent; strlcpy(base, "/sys/block", sizeof(base)); dir = opendir(base); if (dir != NULL) { for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) { char dirname[PATH_SIZE]; DIR *dir2; struct dirent *dent2; if (dent->d_name[0] == '.') continue; strlcpy(dirname, base, sizeof(dirname)); strlcat(dirname, "/", sizeof(dirname)); strlcat(dirname, dent->d_name, sizeof(dirname)); if (device_list_insert(dirname) != 0) continue; /* look for partitions */ dir2 = opendir(dirname); if (dir2 != NULL) { for (dent2 = readdir(dir2); dent2 != NULL; dent2 = readdir(dir2)) { char dirname2[PATH_SIZE]; if (dent2->d_name[0] == '.') continue; if (!strcmp(dent2->d_name,"device")) continue; strlcpy(dirname2, dirname, sizeof(dirname2)); strlcat(dirname2, "/", sizeof(dirname2)); strlcat(dirname2, dent2->d_name, sizeof(dirname2)); device_list_insert(dirname2); } closedir(dir2); } } closedir(dir); } } static void scan_class(void) { char base[PATH_SIZE]; DIR *dir; struct dirent *dent; strlcpy(base, "/sys/class", sizeof(base)); dir = opendir(base); if (dir != NULL) { for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) { char dirname[PATH_SIZE]; DIR *dir2; struct dirent *dent2; if (dent->d_name[0] == '.') continue; strlcpy(dirname, base, sizeof(dirname)); strlcat(dirname, "/", sizeof(dirname)); strlcat(dirname, dent->d_name, sizeof(dirname)); dir2 = opendir(dirname); if (dir2 != NULL) { for (dent2 = readdir(dir2); dent2 != NULL; dent2 = readdir(dir2)) { char dirname2[PATH_SIZE]; if (dent2->d_name[0] == '.') continue; if (!strcmp(dent2->d_name, "device")) continue; strlcpy(dirname2, dirname, sizeof(dirname2)); strlcat(dirname2, "/", sizeof(dirname2)); strlcat(dirname2, dent2->d_name, sizeof(dirname2)); device_list_insert(dirname2); } closedir(dir2); } } closedir(dir); } } int main(int argc, char *argv[], char *envp[]) { char base[PATH_SIZE]; struct stat statbuf; int option; openlog("udevtrigger", LOG_PID | LOG_CONS, LOG_DAEMON); while (1) { option = getopt(argc, argv, "vnh"); if (option == -1) break; switch (option) { case 'v': verbose = 1; break; case 'n': dry_run = 1; break; case 'h': printf("Usage: udevtrigger OPTIONS\n" " -v print the list of devices while running\n" " -n do not actually trigger the events\n" " -h print this text\n" "\n"); goto exit; default: goto exit; } } /* if we have /sys/subsystem, forget all the old stuff */ scan_subsystem("bus"); scan_class(); /* scan "block" if it isn't a "class" */ strlcpy(base, "/sys/class/block", sizeof(base)); if (stat(base, &statbuf) != 0) scan_block(); exit: closelog(); return 0; }
the_stack_data/154829790.c
// SPDX-License-Identifier: BSD-3-Clause // // Copyright(c) 2017 Intel Corporation. All rights reserved. // // Author: Seppo Ingalsuo <[email protected]> #if CONFIG_INTEL_DMIC #include <sof/audio/coefficients/pdm_decim/pdm_decim_fir.h> #include <sof/audio/component.h> #include <sof/audio/format.h> #include <sof/debug/panic.h> #include <sof/drivers/dmic.h> #include <sof/drivers/interrupt.h> #include <sof/drivers/timestamp.h> #include <sof/lib/alloc.h> #include <sof/lib/cpu.h> #include <sof/lib/dai.h> #include <sof/lib/dma.h> #include <sof/lib/memory.h> #include <sof/lib/pm_runtime.h> #include <sof/lib/uuid.h> #include <sof/math/decibels.h> #include <sof/math/numbers.h> #include <sof/schedule/ll_schedule.h> #include <sof/schedule/schedule.h> #include <sof/schedule/task.h> #include <sof/spinlock.h> #include <sof/string.h> #include <ipc/dai.h> #include <ipc/dai-intel.h> #include <ipc/topology.h> #include <user/trace.h> #include <errno.h> #include <stddef.h> #include <stdint.h> /* aafc26fe-3b8d-498d-8bd6-248fc72efa31 */ DECLARE_SOF_UUID("dmic-dai", dmic_uuid, 0xaafc26fe, 0x3b8d, 0x498d, 0x8b, 0xd6, 0x24, 0x8f, 0xc7, 0x2e, 0xfa, 0x31); DECLARE_TR_CTX(dmic_tr, SOF_UUID(dmic_uuid), LOG_LEVEL_INFO); /* 59c87728-d8f9-42f6-b89d-5870a87b0e1e */ DECLARE_SOF_UUID("dmic-work", dmic_work_task_uuid, 0x59c87728, 0xd8f9, 0x42f6, 0xb8, 0x9d, 0x58, 0x70, 0xa8, 0x7b, 0x0e, 0x1e); /* Configuration ABI version, increment if not compatible with previous * version. */ #define DMIC_IPC_VERSION 1 /* Base addresses (in PDM scope) of 2ch PDM controllers and coefficient RAM. */ static const uint32_t base[4] = {PDM0, PDM1, PDM2, PDM3}; /* Global configuration request and state for DMIC */ static SHARED_DATA struct dmic_global_shared dmic_global; /* this ramps volume changes over time */ static enum task_state dmic_work(void *data) { struct dai *dai = (struct dai *)data; struct dmic_pdata *dmic = dai_get_drvdata(dai); int32_t gval; uint32_t val; int i; int ret; dai_dbg(dai, "dmic_work()"); ret = spin_try_lock(&dai->lock); if (!ret) { dai_dbg(dai, "dmic_work(): spin_try_lock(dai->lock, ret) failed: RESCHEDULE"); return SOF_TASK_STATE_RESCHEDULE; } /* Increment gain with logarithmic step. * Gain is Q2.30 and gain modifier is Q12.20. */ dmic->startcount++; dmic->gain = q_multsr_sat_32x32(dmic->gain, dmic->gain_coef, Q_SHIFT_GAIN_X_GAIN_COEF); /* Gain is stored as Q2.30, while HW register is Q1.19 so shift * the value right by 11. */ gval = dmic->gain >> 11; /* Note that DMIC gain value zero has a special purpose. Value zero * sets gain bypass mode in HW. Zero value will be applied after ramp * is complete. It is because exact 1.0 gain is not possible with Q1.19. */ if (gval > DMIC_HW_FIR_GAIN_MAX) gval = 0; /* Write gain to registers */ for (i = 0; i < DMIC_HW_CONTROLLERS; i++) { if (!dmic->enable[i]) continue; if (dmic->startcount == DMIC_UNMUTE_CIC) dai_update_bits(dai, base[i] + CIC_CONTROL, CIC_CONTROL_MIC_MUTE_BIT, 0); if (dmic->startcount == DMIC_UNMUTE_FIR) { switch (dai->index) { case 0: dai_update_bits(dai, base[i] + FIR_CONTROL_A, FIR_CONTROL_A_MUTE_BIT, 0); break; case 1: dai_update_bits(dai, base[i] + FIR_CONTROL_B, FIR_CONTROL_B_MUTE_BIT, 0); break; } } switch (dai->index) { case 0: val = OUT_GAIN_LEFT_A_GAIN(gval); dai_write(dai, base[i] + OUT_GAIN_LEFT_A, val); dai_write(dai, base[i] + OUT_GAIN_RIGHT_A, val); break; case 1: val = OUT_GAIN_LEFT_B_GAIN(gval); dai_write(dai, base[i] + OUT_GAIN_LEFT_B, val); dai_write(dai, base[i] + OUT_GAIN_RIGHT_B, val); break; } } spin_unlock(&dai->lock); return gval ? SOF_TASK_STATE_RESCHEDULE : SOF_TASK_STATE_COMPLETED; } /* get DMIC hw params */ static int dmic_get_hw_params(struct dai *dai, struct sof_ipc_stream_params *params, int dir) { #if CONFIG_INTEL_DMIC_TPLG_PARAMS return dmic_get_hw_params_computed(dai, params, dir); #elif CONFIG_INTEL_DMIC_NHLT return dmic_get_hw_params_nhlt(dai, params, dir); #else return -EINVAL; #endif } static int dmic_set_config(struct dai *dai, struct ipc_config_dai *common_config, void *spec_config) { struct dmic_pdata *dmic = dai_get_drvdata(dai); int32_t unmute_ramp_time_ms; int32_t step_db; int ret = 0; int di = dai->index; #if CONFIG_INTEL_DMIC_TPLG_PARAMS struct sof_ipc_dai_config *config = spec_config; int i; int j; #endif dai_info(dai, "dmic_set_config()"); if (di >= DMIC_HW_FIFOS) { dai_err(dai, "dmic_set_config(): DAI index exceeds number of FIFOs"); return -EINVAL; } if (!spec_config) { dai_err(dai, "dmic_set_config(): NULL config"); return -EINVAL; } assert(dmic); spin_lock(&dai->lock); #if CONFIG_INTEL_DMIC_TPLG_PARAMS /* * "config" might contain pdm controller params for only * the active controllers * "prm" is initialized with default params for all HW controllers */ if (config->dmic.driver_ipc_version != DMIC_IPC_VERSION) { dai_err(dai, "dmic_set_config(): wrong ipc version"); ret = -EINVAL; goto out; } if (config->dmic.num_pdm_active > DMIC_HW_CONTROLLERS) { dai_err(dai, "dmic_set_config(): the requested PDM controllers count exceeds platform capability"); ret = -EINVAL; goto out; } /* Get unmute gain ramp duration. Use the value from topology * if it is non-zero, otherwise use default length. */ if (config->dmic.unmute_ramp_time) unmute_ramp_time_ms = config->dmic.unmute_ramp_time; else unmute_ramp_time_ms = dmic_get_unmute_ramp_from_samplerate(config->dmic.fifo_fs); if (unmute_ramp_time_ms < LOGRAMP_TIME_MIN_MS || unmute_ramp_time_ms > LOGRAMP_TIME_MAX_MS) { dai_err(dai, "dmic_set_config(): Illegal ramp time = %d", unmute_ramp_time_ms); ret = -EINVAL; goto out; } /* Copy the new DMIC params header (all but not pdm[]) to persistent. * The last arrived request determines the parameters. */ ret = memcpy_s(&dmic->global->prm[di], sizeof(dmic->global->prm[di]), &config->dmic, offsetof(struct sof_ipc_dai_dmic_params, pdm)); assert(!ret); /* copy the pdm controller params from ipc */ for (i = 0; i < DMIC_HW_CONTROLLERS; i++) { dmic->global->prm[di].pdm[i].id = i; for (j = 0; j < config->dmic.num_pdm_active; j++) { /* copy the pdm controller params id the id's match */ if (dmic->global->prm[di].pdm[i].id == config->dmic.pdm[j].id) { ret = memcpy_s(&dmic->global->prm[di].pdm[i], sizeof(dmic->global->prm[di].pdm[i]), &config->dmic.pdm[j], sizeof(struct sof_ipc_dai_dmic_pdm_ctrl)); assert(!ret); } } } ret = dmic_set_config_computed(dai); #elif CONFIG_INTEL_DMIC_NHLT ret = dmic_set_config_nhlt(dai, spec_config); /* There's no unmute ramp duration in blob, so the default rate dependent is used. */ unmute_ramp_time_ms = dmic_get_unmute_ramp_from_samplerate(dmic->dai_rate); #else ret = -EINVAL; #endif if (ret < 0) { dai_err(dai, "dmic_set_config(): Failed to set the requested configuration."); goto out; } /* Compute unmute ramp gain update coefficient. */ step_db = LOGRAMP_CONST_TERM / unmute_ramp_time_ms; dmic->gain_coef = db2lin_fixed(step_db); dai_info(dai, "dmic_set_config(): unmute_ramp_time_ms = %d", unmute_ramp_time_ms); dmic->state = COMP_STATE_PREPARE; out: spin_unlock(&dai->lock); return ret; } /* start the DMIC for capture */ static void dmic_start(struct dai *dai) { struct dmic_pdata *dmic = dai_get_drvdata(dai); int i; int mic_a; int mic_b; int fir_a; int fir_b; /* enable port */ spin_lock(&dai->lock); dai_dbg(dai, "dmic_start()"); dmic->startcount = 0; /* Initial gain value, convert Q12.20 to Q2.30 */ dmic->gain = Q_SHIFT_LEFT(db2lin_fixed(LOGRAMP_START_DB), 20, 30); switch (dai->index) { case 0: dai_info(dai, "dmic_start(), dmic->fifo_a"); /* Clear FIFO A initialize, Enable interrupts to DSP, * Start FIFO A packer. */ dai_update_bits(dai, OUTCONTROL0, OUTCONTROL0_FINIT_BIT | OUTCONTROL0_SIP_BIT, OUTCONTROL0_SIP_BIT); break; case 1: dai_info(dai, "dmic_start(), dmic->fifo_b"); /* Clear FIFO B initialize, Enable interrupts to DSP, * Start FIFO B packer. */ dai_update_bits(dai, OUTCONTROL1, OUTCONTROL1_FINIT_BIT | OUTCONTROL1_SIP_BIT, OUTCONTROL1_SIP_BIT); } for (i = 0; i < DMIC_HW_CONTROLLERS; i++) { mic_a = dmic->enable[i] & 1; mic_b = (dmic->enable[i] & 2) >> 1; fir_a = (dmic->enable[i] > 0) ? 1 : 0; #if DMIC_HW_FIFOS > 1 fir_b = (dmic->enable[i] > 0) ? 1 : 0; #else fir_b = 0; #endif dai_info(dai, "dmic_start(), pdm%d mic_a = %u, mic_b = %u", i, mic_a, mic_b); /* If both microphones are needed start them simultaneously * to start them in sync. The reset may be cleared for another * FIFO already. If only one mic, start them independently. * This makes sure we do not clear start/en for another DAI. */ if (mic_a && mic_b) { dai_update_bits(dai, base[i] + CIC_CONTROL, CIC_CONTROL_CIC_START_A_BIT | CIC_CONTROL_CIC_START_B_BIT, CIC_CONTROL_CIC_START_A(1) | CIC_CONTROL_CIC_START_B(1)); dai_update_bits(dai, base[i] + MIC_CONTROL, MIC_CONTROL_PDM_EN_A_BIT | MIC_CONTROL_PDM_EN_B_BIT, MIC_CONTROL_PDM_EN_A(1) | MIC_CONTROL_PDM_EN_B(1)); } else if (mic_a) { dai_update_bits(dai, base[i] + CIC_CONTROL, CIC_CONTROL_CIC_START_A_BIT, CIC_CONTROL_CIC_START_A(1)); dai_update_bits(dai, base[i] + MIC_CONTROL, MIC_CONTROL_PDM_EN_A_BIT, MIC_CONTROL_PDM_EN_A(1)); } else if (mic_b) { dai_update_bits(dai, base[i] + CIC_CONTROL, CIC_CONTROL_CIC_START_B_BIT, CIC_CONTROL_CIC_START_B(1)); dai_update_bits(dai, base[i] + MIC_CONTROL, MIC_CONTROL_PDM_EN_B_BIT, MIC_CONTROL_PDM_EN_B(1)); } switch (dai->index) { case 0: dai_update_bits(dai, base[i] + FIR_CONTROL_A, FIR_CONTROL_A_START_BIT, FIR_CONTROL_A_START(fir_a)); break; case 1: dai_update_bits(dai, base[i] + FIR_CONTROL_B, FIR_CONTROL_B_START_BIT, FIR_CONTROL_B_START(fir_b)); break; } } /* Clear soft reset for all/used PDM controllers. This should * start capture in sync. */ for (i = 0; i < DMIC_HW_CONTROLLERS; i++) { dai_update_bits(dai, base[i] + CIC_CONTROL, CIC_CONTROL_SOFT_RESET_BIT, 0); } /* Set bit dai->index */ dmic->global->active_fifos_mask |= BIT(dai->index); dmic->global->pause_mask &= ~BIT(dai->index); dmic->state = COMP_STATE_ACTIVE; spin_unlock(&dai->lock); /* Currently there's no DMIC HW internal mutings and wait times * applied into this start sequence. It can be implemented here if * start of audio capture would contain clicks and/or noise and it * is not suppressed by gain ramp somewhere in the capture pipe. */ schedule_task(&dmic->dmicwork, DMIC_UNMUTE_RAMP_US, DMIC_UNMUTE_RAMP_US); dai_info(dai, "dmic_start(), dmic_active_fifos_mask = 0x%x", dmic->global->active_fifos_mask); } static void dmic_stop_fifo_packers(struct dai *dai, int fifo_index) { /* Stop FIFO packers and set FIFO initialize bits */ switch (fifo_index) { case 0: dai_update_bits(dai, OUTCONTROL0, OUTCONTROL0_SIP_BIT | OUTCONTROL0_FINIT_BIT, OUTCONTROL0_FINIT_BIT); break; case 1: dai_update_bits(dai, OUTCONTROL1, OUTCONTROL1_SIP_BIT | OUTCONTROL1_FINIT_BIT, OUTCONTROL1_FINIT_BIT); break; } } /* stop the DMIC for capture */ static void dmic_stop(struct dai *dai, bool stop_is_pause) { struct dmic_pdata *dmic = dai_get_drvdata(dai); int i; dai_dbg(dai, "dmic_stop()"); spin_lock(&dai->lock); dmic_stop_fifo_packers(dai, dai->index); /* Set soft reset and mute on for all PDM controllers. */ dai_info(dai, "dmic_stop(), dmic_active_fifos_mask = 0x%x", dmic->global->active_fifos_mask); /* Clear bit dai->index for active FIFO. If stop for pause, set pause mask bit. * If stop is not for pausing, it is safe to clear the pause bit. */ dmic->global->active_fifos_mask &= ~BIT(dai->index); if (stop_is_pause) dmic->global->pause_mask |= BIT(dai->index); else dmic->global->pause_mask &= ~BIT(dai->index); for (i = 0; i < DMIC_HW_CONTROLLERS; i++) { /* Don't stop CIC yet if one FIFO remains active */ if (dmic->global->active_fifos_mask == 0) { dai_update_bits(dai, base[i] + CIC_CONTROL, CIC_CONTROL_SOFT_RESET_BIT | CIC_CONTROL_MIC_MUTE_BIT, CIC_CONTROL_SOFT_RESET_BIT | CIC_CONTROL_MIC_MUTE_BIT); } switch (dai->index) { case 0: dai_update_bits(dai, base[i] + FIR_CONTROL_A, FIR_CONTROL_A_MUTE_BIT, FIR_CONTROL_A_MUTE_BIT); break; case 1: dai_update_bits(dai, base[i] + FIR_CONTROL_B, FIR_CONTROL_B_MUTE_BIT, FIR_CONTROL_B_MUTE_BIT); break; } } schedule_task_cancel(&dmic->dmicwork); spin_unlock(&dai->lock); } /* save DMIC context prior to entering D3 */ static int dmic_context_store(struct dai *dai) { /* Nothing stored at the moment. */ return 0; } /* restore DMIC context after leaving D3 */ static int dmic_context_restore(struct dai *dai) { /* Nothing restored at the moment. */ return 0; } static int dmic_trigger(struct dai *dai, int cmd, int direction) { struct dmic_pdata *dmic = dai_get_drvdata(dai); dai_dbg(dai, "dmic_trigger()"); /* dai private is set in dmic_probe(), error if not set */ if (!dmic) { dai_err(dai, "dmic_trigger(): dai not set"); return -EINVAL; } if (direction != DAI_DIR_CAPTURE) { dai_err(dai, "dmic_trigger(): direction != DAI_DIR_CAPTURE"); return -EINVAL; } switch (cmd) { case COMP_TRIGGER_RELEASE: case COMP_TRIGGER_START: if (dmic->state == COMP_STATE_PREPARE || dmic->state == COMP_STATE_PAUSED) { dmic_start(dai); } else { dai_err(dai, "dmic_trigger(): state is not prepare or paused, dmic->state = %u", dmic->state); } break; case COMP_TRIGGER_STOP: dmic->state = COMP_STATE_PREPARE; dmic_stop(dai, false); break; case COMP_TRIGGER_PAUSE: dmic->state = COMP_STATE_PAUSED; dmic_stop(dai, true); break; case COMP_TRIGGER_RESUME: dmic_context_restore(dai); break; case COMP_TRIGGER_SUSPEND: dmic_context_store(dai); break; default: break; } return 0; } /* On DMIC IRQ event trace the status register that contains the status and * error bit fields. */ static void dmic_irq_handler(void *data) { struct dai *dai = data; uint32_t val0; uint32_t val1; /* Trace OUTSTAT0 register */ val0 = dai_read(dai, OUTSTAT0); val1 = dai_read(dai, OUTSTAT1); dai_info(dai, "dmic_irq_handler(), OUTSTAT0 = 0x%x, OUTSTAT1 = 0x%x", val0, val1); if (val0 & OUTSTAT0_ROR_BIT) { dai_err(dai, "dmic_irq_handler(): full fifo A or PDM overrun"); dai_write(dai, OUTSTAT0, val0); dmic_stop_fifo_packers(dai, 0); } if (val1 & OUTSTAT1_ROR_BIT) { dai_err(dai, "dmic_irq_handler(): full fifo B or PDM overrun"); dai_write(dai, OUTSTAT1, val1); dmic_stop_fifo_packers(dai, 1); } } static int dmic_probe(struct dai *dai) { int irq = dmic_irq(dai); struct dmic_pdata *dmic; int ret; dai_info(dai, "dmic_probe()"); if (dai_get_drvdata(dai)) return -EEXIST; /* already created */ dmic = rzalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM, sizeof(*dmic)); if (!dmic) { dai_err(dai, "dmic_probe(): alloc failed"); return -ENOMEM; } dai_set_drvdata(dai, dmic); /* Common shared data for all DMIC DAI instances */ dmic->global = platform_shared_get(&dmic_global, sizeof(dmic_global)); /* Set state, note there is no playback direction support */ dmic->state = COMP_STATE_READY; /* register our IRQ handler */ dmic->irq = interrupt_get_irq(irq, dmic_irq_name(dai)); if (dmic->irq < 0) { ret = dmic->irq; rfree(dmic); return ret; } ret = interrupt_register(dmic->irq, dmic_irq_handler, dai); if (ret < 0) { dai_err(dai, "dmic failed to allocate IRQ"); rfree(dmic); return ret; } /* Initialize start sequence handler */ schedule_task_init_ll(&dmic->dmicwork, SOF_UUID(dmic_work_task_uuid), SOF_SCHEDULE_LL_TIMER, SOF_TASK_PRI_MED, dmic_work, dai, cpu_get_id(), 0); /* Enable DMIC power */ pm_runtime_get_sync(DMIC_POW, dai->index); /* Disable dynamic clock gating for dmic before touching any reg */ pm_runtime_get_sync(DMIC_CLK, dai->index); interrupt_enable(dmic->irq, dai); return 0; } static int dmic_remove(struct dai *dai) { struct dmic_pdata *dmic = dai_get_drvdata(dai); uint32_t active_fifos_mask = dmic->global->active_fifos_mask; uint32_t pause_mask = dmic->global->pause_mask; dai_info(dai, "dmic_remove()"); interrupt_disable(dmic->irq, dai); interrupt_unregister(dmic->irq, dai); /* remove scheduling */ schedule_task_free(&dmic->dmicwork); dai_info(dai, "dmic_remove(), dmic_active_fifos_mask = 0x%x, dmic_pause_mask = 0x%x", active_fifos_mask, pause_mask); dai_set_drvdata(dai, NULL); rfree(dmic); /* The next end tasks must be passed if another DAI FIFO still runs. * Note: dai_put() function that calls remove() applies the spinlock * so it is not needed here to protect access to mask bits. */ if (active_fifos_mask || pause_mask) return 0; /* Disable DMIC clock and power */ pm_runtime_put_sync(DMIC_CLK, dai->index); pm_runtime_put_sync(DMIC_POW, dai->index); return 0; } static int dmic_get_handshake(struct dai *dai, int direction, int stream_id) { return dai->plat_data.fifo[SOF_IPC_STREAM_CAPTURE].handshake; } static int dmic_get_fifo(struct dai *dai, int direction, int stream_id) { return dai->plat_data.fifo[SOF_IPC_STREAM_CAPTURE].offset; } const struct dai_driver dmic_driver = { .type = SOF_DAI_INTEL_DMIC, .uid = SOF_UUID(dmic_uuid), .tctx = &dmic_tr, .dma_caps = DMA_CAP_GP_LP | DMA_CAP_GP_HP, .dma_dev = DMA_DEV_DMIC, .ops = { .trigger = dmic_trigger, .set_config = dmic_set_config, .get_hw_params = dmic_get_hw_params, .pm_context_store = dmic_context_store, .pm_context_restore = dmic_context_restore, .get_handshake = dmic_get_handshake, .get_fifo = dmic_get_fifo, .probe = dmic_probe, .remove = dmic_remove, }, .ts_ops = { .ts_config = timestamp_dmic_config, .ts_start = timestamp_dmic_start, .ts_get = timestamp_dmic_get, .ts_stop = timestamp_dmic_stop, }, }; #endif
the_stack_data/29884.c
/* -*- Mode: C; tab-width: 4 -*- * * Copyright (c) 2004 Apple Computer, Inc. All rights reserved. * * 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 _LEGACY_NAT_TRAVERSAL_ #include "stdlib.h" // For strtol() #include "string.h" // For strlcpy(), For strncpy(), strncasecmp() #include "assert.h" // For assert() #if defined( WIN32 ) # include <winsock2.h> # include <ws2tcpip.h> # define strcasecmp _stricmp # define strncasecmp _strnicmp # define mDNSASLLog( UUID, SUBDOMAIN, RESULT, SIGNATURE, FORMAT, ... ) ; static int inet_pton( int family, const char * addr, void * dst ) { struct sockaddr_storage ss; int sslen = sizeof( ss ); ZeroMemory( &ss, sizeof( ss ) ); ss.ss_family = (ADDRESS_FAMILY)family; if ( WSAStringToAddressA( (LPSTR)addr, family, NULL, ( struct sockaddr* ) &ss, &sslen ) == 0 ) { if ( family == AF_INET ) { memcpy( dst, &( ( struct sockaddr_in* ) &ss)->sin_addr, sizeof( IN_ADDR ) ); return 1; } else if ( family == AF_INET6 ) { memcpy( dst, &( ( struct sockaddr_in6* ) &ss)->sin6_addr, sizeof( IN6_ADDR ) ); return 1; } else return 0; } else return 0; } #else # include <arpa/inet.h> // For inet_pton() #endif #include "mDNSEmbeddedAPI.h" #include "uDNS.h" // For natTraversalHandleAddressReply() etc. // used to format SOAP port mapping arguments typedef struct Property_struct { char *name; char *type; char *value; } Property; // All of the text parsing in this file is intentionally transparent so that we know exactly // what's being done to the text, with an eye towards preventing security problems. // This is an evolving list of useful acronyms to know. Please add to it at will. // ST Service Type // NT Notification Type // USN Unique Service Name // UDN Unique Device Name // UUID Universally Unique Identifier // URN/urn Universal Resource Name // Forward declaration because of circular reference: // SendPortMapRequest -> SendSOAPMsgControlAction -> MakeTCPConnection -> tcpConnectionCallback -> handleLNTPortMappingResponse // In the event of a port conflict, handleLNTPortMappingResponse then increments tcpInfo->retries and calls back to SendPortMapRequest to try again mDNSlocal mStatus SendPortMapRequest(mDNS *m, NATTraversalInfo *n); #define RequestedPortNum(n) (mDNSVal16(mDNSIPPortIsZero((n)->RequestedPort) ? (n)->IntPort : (n)->RequestedPort) + (mDNSu16)(n)->tcpInfo.retries) // Note that this function assumes src is already NULL terminated mDNSlocal void AllocAndCopy(mDNSu8 **const dst, const mDNSu8 *const src) { if (src == mDNSNULL) return; if ((*dst = mDNSPlatformMemAllocate((mDNSu32)strlen((char*)src) + 1)) == mDNSNULL) { LogMsg("AllocAndCopy: can't allocate string"); return; } strcpy((char*)*dst, (char*)src); } // This function does a simple parse of an HTTP URL that may include a hostname, port, and path // If found in the URL, addressAndPort and path out params will point to newly allocated space (and will leak if they were previously pointing at allocated space) mDNSlocal mStatus ParseHttpUrl(const mDNSu8 *ptr, const mDNSu8 *const end, mDNSu8 **const addressAndPort, mDNSIPPort *const port, mDNSu8 **const path) { // if the data begins with "http://", we assume there is a hostname and possibly a port number if (end - ptr >= 7 && strncasecmp((char*)ptr, "http://", 7) == 0) { int i; const mDNSu8 *stop = end; const mDNSu8 *addrPtr = mDNSNULL; ptr += 7; //skip over "http://" if (ptr >= end) { LogInfo("ParseHttpUrl: past end of buffer parsing host:port"); return mStatus_BadParamErr; } // find the end of the host:port addrPtr = ptr; for (i = 0; addrPtr && addrPtr != end; i++, addrPtr++) if (*addrPtr == '/') break; // allocate the buffer (len i+1 so we have space to terminate the string) if ((*addressAndPort = mDNSPlatformMemAllocate(i+1)) == mDNSNULL) { LogMsg("ParseHttpUrl: can't allocate address string"); return mStatus_NoMemoryErr; } strncpy((char*)*addressAndPort, (char*)ptr, i); (*addressAndPort)[i] = '\0'; // find the port number in the string, by looking backwards for the ':' stop = ptr; // can't go back farther than the original start ptr = addrPtr; // move ptr to the path part for (addrPtr--; addrPtr>stop; addrPtr--) { if (*addrPtr == ':') { addrPtr++; // skip over ':' *port = mDNSOpaque16fromIntVal((mDNSu16)strtol((char*)addrPtr, mDNSNULL, 10)); // store it properly converted break; } } } // ptr should now point to the first character we haven't yet processed // everything that remains is the path if (path && ptr < end) { if ((*path = mDNSPlatformMemAllocate((mDNSu32)(end - ptr) + 1)) == mDNSNULL) { LogMsg("ParseHttpUrl: can't mDNSPlatformMemAllocate path"); return mStatus_NoMemoryErr; } strncpy((char*)*path, (char*)ptr, end - ptr); (*path)[end - ptr] = '\0'; } return mStatus_NoError; } enum { HTTPCode_NeedMoreData = -1, // No code found in stream HTTPCode_Other = -2, // Valid code other than those below found in stream HTTPCode_Bad = -3, HTTPCode_200 = 200, HTTPCode_404 = 404, HTTPCode_500 = 500, }; mDNSlocal mDNSs16 ParseHTTPResponseCode(const mDNSu8 **const data, const mDNSu8 *const end) { const mDNSu8 *ptr = *data; const mDNSu8 *code; if (end - ptr < 5) return HTTPCode_NeedMoreData; if (strncasecmp((char*)ptr, "HTTP/", 5) != 0) return HTTPCode_Bad; ptr += 5; // should we care about the HTTP protocol version? // look for first space, which must come before first LF while (ptr && ptr != end) { if (*ptr == '\n') return HTTPCode_Bad; if (*ptr == ' ') break; ptr++; } if (ptr == end) return HTTPCode_NeedMoreData; ptr++; if (end - ptr < 3) return HTTPCode_NeedMoreData; code = ptr; ptr += 3; while (ptr && ptr != end) { if (*ptr == '\n') break; ptr++; } if (ptr == end) return HTTPCode_NeedMoreData; *data = ++ptr; if (memcmp((char*)code, "200", 3) == 0) return HTTPCode_200; if (memcmp((char*)code, "404", 3) == 0) return HTTPCode_404; if (memcmp((char*)code, "500", 3) == 0) return HTTPCode_500; LogInfo("ParseHTTPResponseCode found unexpected result code: %c%c%c", code[0], code[1], code[2]); return HTTPCode_Other; } // This function parses the xml body of the device description response from the router. Basically, we look to // make sure this is a response referencing a service we care about (WANIPConnection or WANPPPConnection), // look for the "controlURL" header immediately following, and copy the addressing and URL info we need mDNSlocal void handleLNTDeviceDescriptionResponse(tcpLNTInfo *tcpInfo) { mDNS *m = tcpInfo->m; const mDNSu8 *ptr = tcpInfo->Reply; const mDNSu8 *end = tcpInfo->Reply + tcpInfo->nread; const mDNSu8 *stop; mDNSs16 http_result; if (!mDNSIPPortIsZero(m->UPnPSOAPPort)) return; // already have the info we need http_result = ParseHTTPResponseCode(&ptr, end); // Note: modifies ptr if (http_result == HTTPCode_404) LNT_ClearState(m); if (http_result != HTTPCode_200) { mDNSASLLog((uuid_t *)&m->asl_uuid, "natt.legacy.DeviceDescription", "noop", "HTTP Result", "HTTP code: %d", http_result); return; } // Always reset our flag to use WANIPConnection. We'll use WANPPPConnection if we find it and don't find WANIPConnection. m->UPnPWANPPPConnection = mDNSfalse; // find either service we care about while (ptr && ptr < end) { if ((*ptr & 0xDF) == 'W' && (strncasecmp((char*)ptr, "WANIPConnection:1", 17) == 0)) break; ptr++; } if (ptr == end) { ptr = tcpInfo->Reply; while (ptr && ptr < end) { if ((*ptr & 0xDF) == 'W' && (strncasecmp((char*)ptr, "WANPPPConnection:1", 18) == 0)) { m->UPnPWANPPPConnection = mDNStrue; break; } ptr++; } } if (ptr == mDNSNULL || ptr == end) { LogInfo("handleLNTDeviceDescriptionResponse: didn't find WANIPConnection:1 or WANPPPConnection:1 string"); return; } // find "controlURL", starting from where we left off while (ptr && ptr < end) { if ((*ptr & 0xDF) == 'C' && (strncasecmp((char*)ptr, "controlURL", 10) == 0)) break; // find the first 'c'; is this controlURL? if not, keep looking ptr++; } if (ptr == mDNSNULL || ptr == end) { LogInfo("handleLNTDeviceDescriptionResponse: didn't find controlURL string"); return; } ptr += 11; // skip over "controlURL>" if (ptr >= end) { LogInfo("handleLNTDeviceDescriptionResponse: past end of buffer and no body!"); return; } // check ptr again in case we skipped over the end of the buffer // find the end of the controlURL element for (stop = ptr; stop < end; stop++) { if (*stop == '<') { end = stop; break; } } // fill in default port m->UPnPSOAPPort = m->UPnPRouterPort; // free string pointers and set to NULL if (m->UPnPSOAPAddressString != mDNSNULL) { mDNSPlatformMemFree(m->UPnPSOAPAddressString); m->UPnPSOAPAddressString = mDNSNULL; } if (m->UPnPSOAPURL != mDNSNULL) { mDNSPlatformMemFree(m->UPnPSOAPURL); m->UPnPSOAPURL = mDNSNULL; } if (ParseHttpUrl(ptr, end, &m->UPnPSOAPAddressString, &m->UPnPSOAPPort, &m->UPnPSOAPURL) != mStatus_NoError) return; // the SOAPURL should look something like "/uuid:0013-108c-4b3f0000f3dc" if (m->UPnPSOAPAddressString == mDNSNULL) { ptr = tcpInfo->Reply; while (ptr && ptr < end) { if ((*ptr & 0xDF) == 'U' && (strncasecmp((char*)ptr, "URLBase", 7) == 0)) break; ptr++; } if (ptr < end) // found URLBase { LogInfo("handleLNTDeviceDescriptionResponse: found URLBase"); ptr += 8; // skip over "URLBase>" // find the end of the URLBase element for (stop = ptr; stop < end; stop++) { if (*stop == '<') { end = stop; break; } } if (ParseHttpUrl(ptr, end, &m->UPnPSOAPAddressString, &m->UPnPSOAPPort, mDNSNULL) != mStatus_NoError) { LogInfo("handleLNTDeviceDescriptionResponse: failed to parse URLBase"); } } // if all else fails, use the router address string if (m->UPnPSOAPAddressString == mDNSNULL) AllocAndCopy(&m->UPnPSOAPAddressString, m->UPnPRouterAddressString); } if (m->UPnPSOAPAddressString == mDNSNULL) LogMsg("handleLNTDeviceDescriptionResponse: UPnPSOAPAddressString is NULL"); else LogInfo("handleLNTDeviceDescriptionResponse: SOAP address string [%s]", m->UPnPSOAPAddressString); if (m->UPnPSOAPURL == mDNSNULL) AllocAndCopy(&m->UPnPSOAPURL, m->UPnPRouterURL); if (m->UPnPSOAPURL == mDNSNULL) LogMsg("handleLNTDeviceDescriptionResponse: UPnPSOAPURL is NULL"); else LogInfo("handleLNTDeviceDescriptionResponse: SOAP URL [%s]", m->UPnPSOAPURL); } mDNSlocal void handleLNTGetExternalAddressResponse(tcpLNTInfo *tcpInfo) { mDNS *m = tcpInfo->m; mDNSu16 err = NATErr_None; mDNSv4Addr ExtAddr; const mDNSu8 *ptr = tcpInfo->Reply; const mDNSu8 *end = tcpInfo->Reply + tcpInfo->nread; mDNSu8 *addrend; static char tagname[20] = { 'N','e','w','E','x','t','e','r','n','a','l','I','P','A','d','d','r','e','s','s' }; // Array NOT including a terminating nul // LogInfo("handleLNTGetExternalAddressResponse: %s", ptr); mDNSs16 http_result = ParseHTTPResponseCode(&ptr, end); // Note: modifies ptr if (http_result == HTTPCode_404) LNT_ClearState(m); if (http_result != HTTPCode_200) { mDNSASLLog((uuid_t *)&m->asl_uuid, "natt.legacy.AddressRequest", "noop", "HTTP Result", "HTTP code: %d", http_result); return; } while (ptr < end && strncasecmp((char*)ptr, tagname, sizeof(tagname))) ptr++; ptr += sizeof(tagname); // Skip over "NewExternalIPAddress" while (ptr < end && *ptr != '>') ptr++; ptr += 1; // Skip over ">" // Find the end of the address and terminate the string so inet_pton() can convert it // (Might be better to copy this to a local string here -- this is overwriting tcpInfo->Reply in-place addrend = (mDNSu8*)ptr; while (addrend < end && (mDNSIsDigit(*addrend) || *addrend == '.')) addrend++; if (addrend >= end) return; *addrend = 0; if (inet_pton(AF_INET, (char*)ptr, &ExtAddr) <= 0) { mDNSASLLog((uuid_t *)&m->asl_uuid, "natt.legacy.AddressRequest", "noop", "inet_pton", ""); LogMsg("handleLNTGetExternalAddressResponse: Router returned bad address %s", ptr); err = NATErr_NetFail; ExtAddr = zerov4Addr; } if (!err) LogInfo("handleLNTGetExternalAddressResponse: External IP address is %.4a", &ExtAddr); natTraversalHandleAddressReply(m, err, ExtAddr); } mDNSlocal void handleLNTPortMappingResponse(tcpLNTInfo *tcpInfo) { mDNS *m = tcpInfo->m; mDNSIPPort extport = zeroIPPort; const mDNSu8 *ptr = tcpInfo->Reply; const mDNSu8 *const end = tcpInfo->Reply + tcpInfo->nread; NATTraversalInfo *natInfo; mDNSs16 http_result; for (natInfo = m->NATTraversals; natInfo; natInfo=natInfo->next) { if (natInfo == tcpInfo->parentNATInfo) break;} if (!natInfo) { LogInfo("handleLNTPortMappingResponse: can't find matching tcpInfo in NATTraversals!"); return; } http_result = ParseHTTPResponseCode(&ptr, end); // Note: modifies ptr if (http_result == HTTPCode_200) { LogInfo("handleLNTPortMappingResponse: got a valid response, sending reply to natTraversalHandlePortMapReply(internal %d external %d retries %d)", mDNSVal16(natInfo->IntPort), RequestedPortNum(natInfo), tcpInfo->retries); // Make sure to compute extport *before* we zero tcpInfo->retries extport = mDNSOpaque16fromIntVal(RequestedPortNum(natInfo)); tcpInfo->retries = 0; natTraversalHandlePortMapReply(m, natInfo, m->UPnPInterfaceID, mStatus_NoError, extport, NATMAP_DEFAULT_LEASE); } else if (http_result == HTTPCode_500) { while (ptr && ptr != end) { if (((*ptr & 0xDF) == 'C' && end - ptr >= 8 && strncasecmp((char*)ptr, "Conflict", 8) == 0) || (*ptr == '>' && end - ptr >= 15 && strncasecmp((char*)ptr, ">718</errorCode", 15) == 0)) { if (tcpInfo->retries < 100) { tcpInfo->retries++; SendPortMapRequest(tcpInfo->m, natInfo); mDNSASLLog((uuid_t *)&m->asl_uuid, "natt.legacy.PortMapRequest", "noop", "Conflict", "Retry %d", tcpInfo->retries); } else { LogMsg("handleLNTPortMappingResponse too many conflict retries %d %d", mDNSVal16(natInfo->IntPort), mDNSVal16(natInfo->RequestedPort)); mDNSASLLog((uuid_t *)&m->asl_uuid, "natt.legacy.PortMapRequest", "noop", "Conflict - too many retries", "Retries: %d", tcpInfo->retries); natTraversalHandlePortMapReply(m, natInfo, m->UPnPInterfaceID, NATErr_Res, zeroIPPort, 0); } return; } ptr++; } } else if (http_result == HTTPCode_Bad) LogMsg("handleLNTPortMappingResponse got data that was not a valid HTTP response"); else if (http_result == HTTPCode_Other) LogMsg("handleLNTPortMappingResponse got unexpected response code"); else if (http_result == HTTPCode_404) LNT_ClearState(m); if (http_result != HTTPCode_200 && http_result != HTTPCode_500) mDNSASLLog((uuid_t *)&m->asl_uuid, "natt.legacy.PortMapRequest", "noop", "HTTP Result", "HTTP code: %d", http_result); } mDNSlocal void DisposeInfoFromUnmapList(mDNS *m, tcpLNTInfo *tcpInfo) { tcpLNTInfo **ptr = &m->tcpInfoUnmapList; while (*ptr && *ptr != tcpInfo) ptr = &(*ptr)->next; if (*ptr) { *ptr = (*ptr)->next; mDNSPlatformMemFree(tcpInfo); } // If we found it, cut it from our list and free the memory } mDNSlocal void tcpConnectionCallback(TCPSocket *sock, void *context, mDNSBool ConnectionEstablished, mStatus err) { mStatus status = mStatus_NoError; tcpLNTInfo *tcpInfo = (tcpLNTInfo *)context; mDNSBool closed = mDNSfalse; long n = 0; long nsent = 0; static int LNTERRORcount = 0; if (tcpInfo == mDNSNULL) { LogInfo("tcpConnectionCallback: no tcpInfo context"); status = mStatus_Invalid; goto exit; } if (tcpInfo->sock != sock) { LogMsg("tcpConnectionCallback: WARNING- tcpInfo->sock(%p) != sock(%p) !!! Printing tcpInfo struct", tcpInfo->sock, sock); LogMsg("tcpConnectionCallback: tcpInfo->Address:Port [%#a:%d] tcpInfo->op[%d] tcpInfo->retries[%d] tcpInfo->Request[%s] tcpInfo->Reply[%s]", &tcpInfo->Address, mDNSVal16(tcpInfo->Port), tcpInfo->op, tcpInfo->retries, tcpInfo->Request, tcpInfo->Reply); } // The handlers below expect to be called with the lock held mDNS_Lock(tcpInfo->m); if (err) { LogInfo("tcpConnectionCallback: received error"); goto exit; } if (ConnectionEstablished) // connection is established - send the message { LogInfo("tcpConnectionCallback: connection established, sending message"); nsent = mDNSPlatformWriteTCP(sock, (char*)tcpInfo->Request, tcpInfo->requestLen); if (nsent != (long)tcpInfo->requestLen) { LogMsg("tcpConnectionCallback: error writing"); status = mStatus_UnknownErr; goto exit; } } else { n = mDNSPlatformReadTCP(sock, (char*)tcpInfo->Reply + tcpInfo->nread, tcpInfo->replyLen - tcpInfo->nread, &closed); LogInfo("tcpConnectionCallback: mDNSPlatformReadTCP read %d bytes", n); if (n < 0) { LogInfo("tcpConnectionCallback - read returned %d", n); status = mStatus_ConnFailed; goto exit; } else if (closed) { LogInfo("tcpConnectionCallback: socket closed by remote end %d", tcpInfo->nread); status = mStatus_ConnFailed; goto exit; } tcpInfo->nread += n; LogInfo("tcpConnectionCallback tcpInfo->nread %d", tcpInfo->nread); if (tcpInfo->nread > LNT_MAXBUFSIZE) { LogInfo("result truncated..."); tcpInfo->nread = LNT_MAXBUFSIZE; } switch (tcpInfo->op) { case LNTDiscoveryOp: handleLNTDeviceDescriptionResponse (tcpInfo); break; case LNTExternalAddrOp: handleLNTGetExternalAddressResponse(tcpInfo); break; case LNTPortMapOp: handleLNTPortMappingResponse (tcpInfo); break; case LNTPortMapDeleteOp: status = mStatus_ConfigChanged; break; default: LogMsg("tcpConnectionCallback: bad tcp operation! %d", tcpInfo->op); status = mStatus_Invalid; break; } } exit: if (err || status) { mDNS *m = tcpInfo->m; if ((++LNTERRORcount % 1000) == 0) { LogMsg("ERROR: tcpconnectioncallback -> got error status %d times", LNTERRORcount); assert(LNTERRORcount < 1000); // Recovery Mechanism to bail mDNSResponder out of trouble: It has been seen that we can get into // this loop: [tcpKQSocketCallback()--> doTcpSocketCallback()-->tcpconnectionCallback()-->mDNSASLLog()], // if mDNSPlatformTCPCloseConnection() does not close the TCPSocket. Instead of calling mDNSASLLog() // repeatedly and logging the same error msg causing 100% CPU usage, we // crash mDNSResponder using assert() and restart fresh. See advantages below: // 1.Better User Experience // 2.CrashLogs frequency can be monitored // 3.StackTrace can be used for more info } switch (tcpInfo->op) { case LNTDiscoveryOp: if (m->UPnPSOAPAddressString == mDNSNULL) mDNSASLLog((uuid_t *)&m->asl_uuid, "natt.legacy.DeviceDescription", "failure", "SOAP Address", ""); if (m->UPnPSOAPURL == mDNSNULL) mDNSASLLog((uuid_t *)&m->asl_uuid, "natt.legacy.DeviceDescription", "failure", "SOAP path", ""); if (m->UPnPSOAPAddressString && m->UPnPSOAPURL) mDNSASLLog((uuid_t *)&m->asl_uuid, "natt.legacy.DeviceDescription", "success", "success", ""); break; case LNTExternalAddrOp: mDNSASLLog((uuid_t *)&m->asl_uuid, "natt.legacy.AddressRequest", mDNSIPv4AddressIsZero(m->ExternalAddress) ? "failure" : "success", mDNSIPv4AddressIsZero(m->ExternalAddress) ? "failure" : "success", ""); break; case LNTPortMapOp: if (tcpInfo->parentNATInfo) mDNSASLLog((uuid_t *)&m->asl_uuid, "natt.legacy.PortMapRequest", (tcpInfo->parentNATInfo->Result) ? "failure" : "success", (tcpInfo->parentNATInfo->Result) ? "failure" : "success", "Result: %d", tcpInfo->parentNATInfo->Result); break; case LNTPortMapDeleteOp: break; default: break; } mDNSPlatformTCPCloseConnection(sock); tcpInfo->sock = mDNSNULL; if (tcpInfo->Request) { mDNSPlatformMemFree(tcpInfo->Request); tcpInfo->Request = mDNSNULL; } if (tcpInfo->Reply ) { mDNSPlatformMemFree(tcpInfo->Reply); tcpInfo->Reply = mDNSNULL; } } else { LNTERRORcount = 0; // clear LNTERRORcount } if (tcpInfo) mDNS_Unlock(tcpInfo->m); if (status == mStatus_ConfigChanged) DisposeInfoFromUnmapList(tcpInfo->m, tcpInfo); } mDNSlocal mStatus MakeTCPConnection(mDNS *const m, tcpLNTInfo *info, const mDNSAddr *const Addr, const mDNSIPPort Port, LNTOp_t op) { mStatus err = mStatus_NoError; mDNSIPPort srcport = zeroIPPort; if (mDNSIPv4AddressIsZero(Addr->ip.v4) || mDNSIPPortIsZero(Port)) { LogMsg("LNT MakeTCPConnection: bad address/port %#a:%d", Addr, mDNSVal16(Port)); return(mStatus_Invalid); } info->m = m; info->Address = *Addr; info->Port = Port; info->op = op; info->nread = 0; info->replyLen = LNT_MAXBUFSIZE; if (info->Reply != mDNSNULL) mDNSPlatformMemZero(info->Reply, LNT_MAXBUFSIZE); // reuse previously allocated buffer else if ((info->Reply = mDNSPlatformMemAllocate(LNT_MAXBUFSIZE)) == mDNSNULL) { LogInfo("can't allocate reply buffer"); return (mStatus_NoMemoryErr); } if (info->sock) { LogInfo("MakeTCPConnection: closing previous open connection"); mDNSPlatformTCPCloseConnection(info->sock); info->sock = mDNSNULL; } info->sock = mDNSPlatformTCPSocket(m, kTCPSocketFlags_Zero, &srcport, mDNSfalse); if (!info->sock) { LogMsg("LNT MakeTCPConnection: unable to create TCP socket"); mDNSPlatformMemFree(info->Reply); info->Reply = mDNSNULL; return(mStatus_NoMemoryErr); } LogInfo("MakeTCPConnection: connecting to %#a:%d", &info->Address, mDNSVal16(info->Port)); err = mDNSPlatformTCPConnect(info->sock, Addr, Port, mDNSNULL, 0, tcpConnectionCallback, info); if (err == mStatus_ConnPending) err = mStatus_NoError; else if (err == mStatus_ConnEstablished) { mDNS_DropLockBeforeCallback(); tcpConnectionCallback(info->sock, info, mDNStrue, mStatus_NoError); mDNS_ReclaimLockAfterCallback(); err = mStatus_NoError; } else { // Don't need to log this in customer builds -- it happens quite often during sleep, wake, configuration changes, etc. LogInfo("LNT MakeTCPConnection: connection failed"); mDNSPlatformTCPCloseConnection(info->sock); // Dispose the socket we created with mDNSPlatformTCPSocket() above info->sock = mDNSNULL; mDNSPlatformMemFree(info->Reply); info->Reply = mDNSNULL; } return(err); } mDNSlocal unsigned int AddSOAPArguments(char *const buf, const unsigned int maxlen, const int numArgs, const Property *const a) { static const char f1[] = "<%s>%s</%s>"; static const char f2[] = "<%s xmlns:dt=\"urn:schemas-microsoft-com:datatypes\" dt:dt=\"%s\">%s</%s>"; int i, len = 0; *buf = 0; for (i = 0; i < numArgs; i++) { if (a[i].type) len += mDNS_snprintf(buf + len, maxlen - len, f2, a[i].name, a[i].type, a[i].value, a[i].name); else len += mDNS_snprintf(buf + len, maxlen - len, f1, a[i].name, a[i].value, a[i].name); } return(len); } mDNSlocal mStatus SendSOAPMsgControlAction(mDNS *m, tcpLNTInfo *info, const char *const Action, const int numArgs, const Property *const Arguments, const LNTOp_t op) { // SOAP message header format - // - control URL // - action (string) // - router's host/port ("host:port") // - content-length static const char header[] = "POST %s HTTP/1.1\r\n" "Content-Type: text/xml; charset=\"utf-8\"\r\n" "SOAPAction: \"urn:schemas-upnp-org:service:WAN%sConnection:1#%s\"\r\n" "User-Agent: Mozilla/4.0 (compatible; UPnP/1.0; Windows 9x)\r\n" "Host: %s\r\n" "Content-Length: %d\r\n" "Connection: close\r\n" "Pragma: no-cache\r\n" "\r\n" "%s\r\n"; static const char body1[] = "<?xml version=\"1.0\"?>\r\n" "<SOAP-ENV:Envelope" " xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"" " SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" "<SOAP-ENV:Body>" "<m:%s xmlns:m=\"urn:schemas-upnp-org:service:WAN%sConnection:1\">"; static const char body2[] = "</m:%s>" "</SOAP-ENV:Body>" "</SOAP-ENV:Envelope>\r\n"; mStatus err; char *body = (char*)&m->omsg; // Typically requires 1110-1122 bytes; m->omsg is 8952 bytes, which is plenty int bodyLen; if (mDNSIPPortIsZero(m->UPnPSOAPPort) || m->UPnPSOAPURL == mDNSNULL || m->UPnPSOAPAddressString == mDNSNULL) // if no SOAP URL or address exists get out here { LogInfo("SendSOAPMsgControlAction: no SOAP port, URL or address string"); return mStatus_Invalid; } // Create body bodyLen = mDNS_snprintf (body, sizeof(m->omsg), body1, Action, m->UPnPWANPPPConnection ? "PPP" : "IP"); bodyLen += AddSOAPArguments(body + bodyLen, sizeof(m->omsg) - bodyLen, numArgs, Arguments); bodyLen += mDNS_snprintf (body + bodyLen, sizeof(m->omsg) - bodyLen, body2, Action); // Create info->Request; the header needs to contain the bodyLen in the "Content-Length" field if (!info->Request) info->Request = mDNSPlatformMemAllocate(LNT_MAXBUFSIZE); if (!info->Request) { LogMsg("SendSOAPMsgControlAction: Can't allocate info->Request"); return mStatus_NoMemoryErr; } info->requestLen = mDNS_snprintf((char*)info->Request, LNT_MAXBUFSIZE, header, m->UPnPSOAPURL, m->UPnPWANPPPConnection ? "PPP" : "IP", Action, m->UPnPSOAPAddressString, bodyLen, body); err = MakeTCPConnection(m, info, &m->Router, m->UPnPSOAPPort, op); if (err) { mDNSPlatformMemFree(info->Request); info->Request = mDNSNULL; } return err; } // Build port mapping request with new port (up to max) and send it mDNSlocal mStatus SendPortMapRequest(mDNS *m, NATTraversalInfo *n) { char externalPort[6]; char internalPort[6]; char localIPAddrString[30]; char publicPortString[40]; Property propArgs[8]; mDNSu16 ReqPortNum = RequestedPortNum(n); NATTraversalInfo *n2 = m->NATTraversals; // Scan our m->NATTraversals list to make sure the external port we're requesting is locally unique. // UPnP gateways will report conflicts if different devices request the same external port, but if two // clients on the same device request the same external port the second one just stomps over the first. // One way this can happen is like this: // 1. Client A binds local port 80 // 2. Client A requests external port 80 -> internal port 80 // 3. UPnP NAT gateway refuses external port 80 (some other client already has it) // 4. Client A tries again, and successfully gets external port 80 -> internal port 81 // 5. Client B on same machine tries to bind local port 80, and fails // 6. Client B tries again, and successfully binds local port 81 // 7. Client B now requests external port 81 -> internal port 81 // 8. UPnP NAT gateway allows this, stomping over Client A's existing mapping while (n2) { if (n2 == n || RequestedPortNum(n2) != ReqPortNum) n2=n2->next; else { if (n->tcpInfo.retries < 100) { n->tcpInfo.retries++; ReqPortNum = RequestedPortNum(n); // Pick a new port number n2 = m->NATTraversals; // And re-scan the list looking for conflicts } else { natTraversalHandlePortMapReply(m, n, m->UPnPInterfaceID, NATErr_Res, zeroIPPort, 0); return mStatus_NoError; } } } // create strings to use in the message mDNS_snprintf(externalPort, sizeof(externalPort), "%u", ReqPortNum); mDNS_snprintf(internalPort, sizeof(internalPort), "%u", mDNSVal16(n->IntPort)); mDNS_snprintf(publicPortString, sizeof(publicPortString), "iC%u", ReqPortNum); mDNS_snprintf(localIPAddrString, sizeof(localIPAddrString), "%u.%u.%u.%u", m->AdvertisedV4.ip.v4.b[0], m->AdvertisedV4.ip.v4.b[1], m->AdvertisedV4.ip.v4.b[2], m->AdvertisedV4.ip.v4.b[3]); // build the message mDNSPlatformMemZero(propArgs, sizeof(propArgs)); propArgs[0].name = "NewRemoteHost"; propArgs[0].type = "string"; propArgs[0].value = ""; propArgs[1].name = "NewExternalPort"; propArgs[1].type = "ui2"; propArgs[1].value = externalPort; propArgs[2].name = "NewProtocol"; propArgs[2].type = "string"; propArgs[2].value = (n->Protocol == NATOp_MapUDP) ? "UDP" : "TCP"; propArgs[3].name = "NewInternalPort"; propArgs[3].type = "ui2"; propArgs[3].value = internalPort; propArgs[4].name = "NewInternalClient"; propArgs[4].type = "string"; propArgs[4].value = localIPAddrString; propArgs[5].name = "NewEnabled"; propArgs[5].type = "boolean"; propArgs[5].value = "1"; propArgs[6].name = "NewPortMappingDescription"; propArgs[6].type = "string"; propArgs[6].value = publicPortString; propArgs[7].name = "NewLeaseDuration"; propArgs[7].type = "ui4"; propArgs[7].value = "0"; LogInfo("SendPortMapRequest: internal %u external %u", mDNSVal16(n->IntPort), ReqPortNum); return SendSOAPMsgControlAction(m, &n->tcpInfo, "AddPortMapping", 8, propArgs, LNTPortMapOp); } mDNSexport mStatus LNT_MapPort(mDNS *m, NATTraversalInfo *const n) { LogInfo("LNT_MapPort"); if (n->tcpInfo.sock) return(mStatus_NoError); // If we already have a connection up don't make another request for the same thing n->tcpInfo.parentNATInfo = n; n->tcpInfo.retries = 0; return SendPortMapRequest(m, n); } mDNSexport mStatus LNT_UnmapPort(mDNS *m, NATTraversalInfo *const n) { char externalPort[10]; Property propArgs[3]; tcpLNTInfo *info; tcpLNTInfo **infoPtr = &m->tcpInfoUnmapList; mStatus err; // If no NAT gateway to talk to, no need to do all this work for nothing if (mDNSIPPortIsZero(m->UPnPSOAPPort) || !m->UPnPSOAPURL || !m->UPnPSOAPAddressString) return mStatus_NoError; mDNS_snprintf(externalPort, sizeof(externalPort), "%u", mDNSVal16(mDNSIPPortIsZero(n->RequestedPort) ? n->IntPort : n->RequestedPort)); mDNSPlatformMemZero(propArgs, sizeof(propArgs)); propArgs[0].name = "NewRemoteHost"; propArgs[0].type = "string"; propArgs[0].value = ""; propArgs[1].name = "NewExternalPort"; propArgs[1].type = "ui2"; propArgs[1].value = externalPort; propArgs[2].name = "NewProtocol"; propArgs[2].type = "string"; propArgs[2].value = (n->Protocol == NATOp_MapUDP) ? "UDP" : "TCP"; n->tcpInfo.parentNATInfo = n; // clean up previous port mapping requests and allocations if (n->tcpInfo.sock) LogInfo("LNT_UnmapPort: closing previous open connection"); if (n->tcpInfo.sock ) { mDNSPlatformTCPCloseConnection(n->tcpInfo.sock); n->tcpInfo.sock = mDNSNULL; } if (n->tcpInfo.Request) { mDNSPlatformMemFree(n->tcpInfo.Request); n->tcpInfo.Request = mDNSNULL; } if (n->tcpInfo.Reply ) { mDNSPlatformMemFree(n->tcpInfo.Reply); n->tcpInfo.Reply = mDNSNULL; } // make a copy of the tcpInfo that we can clean up later (the one passed in will be destroyed by the client as soon as this returns) if ((info = mDNSPlatformMemAllocate(sizeof(tcpLNTInfo))) == mDNSNULL) { LogInfo("LNT_UnmapPort: can't allocate tcpInfo"); return(mStatus_NoMemoryErr); } *info = n->tcpInfo; while (*infoPtr) infoPtr = &(*infoPtr)->next; // find the end of the list *infoPtr = info; // append err = SendSOAPMsgControlAction(m, info, "DeletePortMapping", 3, propArgs, LNTPortMapDeleteOp); if (err) DisposeInfoFromUnmapList(m, info); return err; } mDNSexport mStatus LNT_GetExternalAddress(mDNS *m) { return SendSOAPMsgControlAction(m, &m->tcpAddrInfo, "GetExternalIPAddress", 0, mDNSNULL, LNTExternalAddrOp); } mDNSlocal mStatus GetDeviceDescription(mDNS *m, tcpLNTInfo *info) { // Device description format - // - device description URL // - host/port static const char szSSDPMsgDescribeDeviceFMT[] = "GET %s HTTP/1.1\r\n" "Accept: text/xml, application/xml\r\n" "User-Agent: Mozilla/4.0 (compatible; UPnP/1.0; Windows NT/5.1)\r\n" "Host: %s\r\n" "Connection: close\r\n" "\r\n"; if (!mDNSIPPortIsZero(m->UPnPSOAPPort)) return mStatus_NoError; // already have the info we need if (m->UPnPRouterURL == mDNSNULL || m->UPnPRouterAddressString == mDNSNULL) { LogInfo("GetDeviceDescription: no router URL or address string!"); return (mStatus_Invalid); } // build message if (info->Request != mDNSNULL) mDNSPlatformMemZero(info->Request, LNT_MAXBUFSIZE); // reuse previously allocated buffer else if ((info->Request = mDNSPlatformMemAllocate(LNT_MAXBUFSIZE)) == mDNSNULL) { LogInfo("can't allocate send buffer for discovery"); return (mStatus_NoMemoryErr); } info->requestLen = mDNS_snprintf((char*)info->Request, LNT_MAXBUFSIZE, szSSDPMsgDescribeDeviceFMT, m->UPnPRouterURL, m->UPnPRouterAddressString); LogInfo("Describe Device: [%s]", info->Request); return MakeTCPConnection(m, info, &m->Router, m->UPnPRouterPort, LNTDiscoveryOp); } // This function parses the response to our SSDP discovery message. Basically, we look to make sure this is a response // referencing a service we care about (WANIPConnection or WANPPPConnection), then look for the "Location:" header and copy the addressing and // URL info we need. mDNSexport void LNT_ConfigureRouterInfo(mDNS *m, const mDNSInterfaceID InterfaceID, const mDNSu8 *const data, const mDNSu16 len) { const mDNSu8 *ptr = data; const mDNSu8 *end = data + len; const mDNSu8 *stop = ptr; if (!mDNSIPPortIsZero(m->UPnPRouterPort)) return; // already have the info we need // The formatting of the HTTP header is not always the same when it comes to the placement of // the service and location strings, so we just look for each of them from the beginning for every response // figure out if this is a message from a service we care about while (ptr && ptr != end) { if ((*ptr & 0xDF) == 'W' && (strncasecmp((char*)ptr, "WANIPConnection:1", 17) == 0)) break; ptr++; } if (ptr == end) { ptr = data; while (ptr && ptr != end) { if ((*ptr & 0xDF) == 'W' && (strncasecmp((char*)ptr, "WANPPPConnection:1", 18) == 0)) break; ptr++; } } if (ptr == mDNSNULL || ptr == end) return; // not a message we care about // find "Location:", starting from the beginning ptr = data; while (ptr && ptr != end) { if ((*ptr & 0xDF) == 'L' && (strncasecmp((char*)ptr, "Location:", 9) == 0)) break; // find the first 'L'; is this Location? if not, keep looking ptr++; } if (ptr == mDNSNULL || ptr == end) { mDNSASLLog((uuid_t *)&m->asl_uuid, "natt.legacy.ssdp", "failure", "Location", ""); return; // not a message we care about } ptr += 9; //Skip over 'Location:' while (*ptr == ' ' && ptr < end) ptr++; // skip over spaces if (ptr >= end) return; // find the end of the line for (stop = ptr; stop != end; stop++) { if (*stop == '\r') { end = stop; break; } } // fill in default port m->UPnPRouterPort = mDNSOpaque16fromIntVal(80); // free string pointers and set to NULL if (m->UPnPRouterAddressString != mDNSNULL) { mDNSPlatformMemFree(m->UPnPRouterAddressString); m->UPnPRouterAddressString = mDNSNULL; } if (m->UPnPRouterURL != mDNSNULL) { mDNSPlatformMemFree(m->UPnPRouterURL); m->UPnPRouterURL = mDNSNULL; } // the Router URL should look something like "/dyndev/uuid:0013-108c-4b3f0000f3dc" if (ParseHttpUrl(ptr, end, &m->UPnPRouterAddressString, &m->UPnPRouterPort, &m->UPnPRouterURL) != mStatus_NoError) { mDNSASLLog((uuid_t *)&m->asl_uuid, "natt.legacy.ssdp", "failure", "Parse URL", ""); return; } m->UPnPInterfaceID = InterfaceID; if (m->UPnPRouterAddressString == mDNSNULL) { mDNSASLLog((uuid_t *)&m->asl_uuid, "natt.legacy.ssdp", "failure", "Router address", ""); LogMsg("LNT_ConfigureRouterInfo: UPnPRouterAddressString is NULL"); } else LogInfo("LNT_ConfigureRouterInfo: Router address string [%s]", m->UPnPRouterAddressString); if (m->UPnPRouterURL == mDNSNULL) { mDNSASLLog((uuid_t *)&m->asl_uuid, "natt.legacy.ssdp", "failure", "Router path", ""); LogMsg("LNT_ConfigureRouterInfo: UPnPRouterURL is NULL"); } else LogInfo("LNT_ConfigureRouterInfo: Router URL [%s]", m->UPnPRouterURL); LogInfo("LNT_ConfigureRouterInfo: Router port %d", mDNSVal16(m->UPnPRouterPort)); LogInfo("LNT_ConfigureRouterInfo: Router interface %d", m->UPnPInterfaceID); // Don't need the SSDP socket anymore if (m->SSDPSocket) { debugf("LNT_ConfigureRouterInfo destroying SSDPSocket %p", &m->SSDPSocket); mDNSPlatformUDPClose(m->SSDPSocket); m->SSDPSocket = mDNSNULL; } mDNSASLLog((uuid_t *)&m->asl_uuid, "natt.legacy.ssdp", "success", "success", ""); // now send message to get the device description GetDeviceDescription(m, &m->tcpDeviceInfo); } mDNSexport void LNT_SendDiscoveryMsg(mDNS *m) { static const char msg[] = "M-SEARCH * HTTP/1.1\r\n" "Host:239.255.255.250:1900\r\n" "ST:urn:schemas-upnp-org:service:WAN%sConnection:1\r\n" "Man:\"ssdp:discover\"\r\n" "MX:3\r\n\r\n"; static const mDNSAddr multicastDest = { mDNSAddrType_IPv4, { { { 239, 255, 255, 250 } } } }; mDNSu8 *buf = (mDNSu8*)&m->omsg; //m->omsg is 8952 bytes, which is plenty unsigned int bufLen; if (!mDNSIPPortIsZero(m->UPnPRouterPort)) { if (m->SSDPSocket) { debugf("LNT_SendDiscoveryMsg destroying SSDPSocket %p", &m->SSDPSocket); mDNSPlatformUDPClose(m->SSDPSocket); m->SSDPSocket = mDNSNULL; } if (mDNSIPPortIsZero(m->UPnPSOAPPort) && !m->tcpDeviceInfo.sock) GetDeviceDescription(m, &m->tcpDeviceInfo); return; } // Always query for WANIPConnection in the first SSDP packet if (m->retryIntervalGetAddr <= NATMAP_INIT_RETRY) m->SSDPWANPPPConnection = mDNSfalse; // Create message bufLen = mDNS_snprintf((char*)buf, sizeof(m->omsg), msg, m->SSDPWANPPPConnection ? "PPP" : "IP"); debugf("LNT_SendDiscoveryMsg Router %.4a Current External Address %.4a", &m->Router.ip.v4, &m->ExternalAddress); if (!mDNSIPv4AddressIsZero(m->Router.ip.v4)) { if (!m->SSDPSocket) { m->SSDPSocket = mDNSPlatformUDPSocket(m, zeroIPPort); debugf("LNT_SendDiscoveryMsg created SSDPSocket %p", &m->SSDPSocket); } mDNSPlatformSendUDP(m, buf, buf + bufLen, 0, m->SSDPSocket, &m->Router, SSDPPort, mDNSfalse); mDNSPlatformSendUDP(m, buf, buf + bufLen, 0, m->SSDPSocket, &multicastDest, SSDPPort, mDNSfalse); } m->SSDPWANPPPConnection = !m->SSDPWANPPPConnection; } mDNSexport void LNT_ClearState(mDNS *const m) { if (m->tcpAddrInfo.sock) { mDNSPlatformTCPCloseConnection(m->tcpAddrInfo.sock); m->tcpAddrInfo.sock = mDNSNULL; } if (m->tcpDeviceInfo.sock) { mDNSPlatformTCPCloseConnection(m->tcpDeviceInfo.sock); m->tcpDeviceInfo.sock = mDNSNULL; } m->UPnPSOAPPort = m->UPnPRouterPort = zeroIPPort; // Reset UPnP ports } #endif /* _LEGACY_NAT_TRAVERSAL_ */
the_stack_data/184518909.c
#include <stdio.h> int main(void) { const int MIN_PER_HOUR = 60; int min; int ahour, amin; // answer stored in these printf("This program converts time in minutes to time in hours and " "minutes.\n"); printf("Please enter the amount of time in minutes (<= 0 to quit): "); scanf("%d", &min); while (min > 0) { ahour = min / MIN_PER_HOUR; amin = min % MIN_PER_HOUR; printf("%d minutes is %d hours and %d minutes.\n", min, ahour, amin); printf("Please enter the amount of time in minutes " "(<= 0 to quit): "); scanf("%d", &min); } return 0; }
the_stack_data/67608.c
#include <stdio.h> int main() { int year; printf("Enter a year to check if it is a leap year\n"); scanf("%d", &year); if (year%400 == 0) // Exactly divisible by 400 e.g. 1600, 2000 printf("%d is a leap year.\n", year); else if (year%100 == 0) // Exactly divisible by 100 and not by 400 e.g. 1900, 2100 printf("%d isn't a leap year.\n", year); else if (year%4 == 0) // Exactly divisible by 4 and neither by 100 nor 400 e.g. 2020 printf("%d is a leap year.\n", year); else // Not divisible by 4 or 100 or 400 e.g. 2017, 2018, 2019 printf("%d isn't a leap year.\n", year); return 0; }
the_stack_data/165765725.c
/* * Hardware AES implementation for STM32L4 family ******************************************************************************* * Copyright (c) 2017, STMicroelectronics * 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. * */ #if (TARGET_STM32L4) #include "mbedtls/aes.h" #if defined(MBEDTLS_AES_ALT) #include <string.h> #include "mbedtls/platform.h" static int aes_set_key(mbedtls_aes_context *ctx, const unsigned char *key, unsigned int keybits) { switch (keybits) { case 128: ctx->hcryp_aes.Init.KeySize = CRYP_KEYSIZE_128B; memcpy(ctx->aes_key, key, 16); break; case 192: return (MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED); case 256: ctx->hcryp_aes.Init.KeySize = CRYP_KEYSIZE_256B; memcpy(ctx->aes_key, key, 32); break; default : return (MBEDTLS_ERR_AES_INVALID_KEY_LENGTH); } ctx->hcryp_aes.Init.DataType = CRYP_DATATYPE_8B; ctx->hcryp_aes.Instance = AES; /* Deinitializes the CRYP peripheral */ if (HAL_CRYP_DeInit(&ctx->hcryp_aes) == HAL_ERROR) { return (HAL_ERROR); } /* Enable CRYP clock */ __HAL_RCC_AES_CLK_ENABLE(); ctx->hcryp_aes.Init.pKey = ctx->aes_key; ctx->hcryp_aes.Init.KeyWriteFlag = CRYP_KEY_WRITE_ENABLE; if (HAL_CRYP_Init(&ctx->hcryp_aes) == HAL_ERROR) { return (HAL_ERROR); } /* allow multi-instance of CRYP use: save context for CRYP HW module CR */ ctx->ctx_save_cr = ctx->hcryp_aes.Instance->CR; return (0); } /* Implementation that should never be optimized out by the compiler */ static void mbedtls_zeroize(void *v, size_t n) { volatile unsigned char *p = (unsigned char *)v; while (n--) { *p++ = 0; } } void mbedtls_aes_init(mbedtls_aes_context *ctx) { memset(ctx, 0, sizeof(mbedtls_aes_context)); } void mbedtls_aes_free(mbedtls_aes_context *ctx) { if (ctx == NULL) { return; } #if defined(DUAL_CORE) while (LL_HSEM_1StepLock(HSEM, CFG_HW_RCC_SEMID)) { } #endif /* DUAL_CORE */ /* Force the CRYP Periheral Clock Reset */ __HAL_RCC_AES_FORCE_RESET(); /* Release the CRYP Periheral Clock Reset */ __HAL_RCC_AES_RELEASE_RESET(); #if defined(DUAL_CORE) LL_HSEM_ReleaseLock(HSEM, CFG_HW_RCC_SEMID, HSEM_CR_COREID_CURRENT); #endif /* DUAL_CORE */ mbedtls_zeroize(ctx, sizeof(mbedtls_aes_context)); } int mbedtls_aes_setkey_enc(mbedtls_aes_context *ctx, const unsigned char *key, unsigned int keybits) { int ret_val = 0; ret_val = aes_set_key(ctx, key, keybits); return (ret_val); } int mbedtls_aes_setkey_dec(mbedtls_aes_context *ctx, const unsigned char *key, unsigned int keybits) { int ret_val = 0; ret_val = aes_set_key(ctx, key, keybits); return (ret_val); } int mbedtls_aes_crypt_ecb(mbedtls_aes_context *ctx, int mode, const unsigned char input[16], unsigned char output[16]) { /* allow multi-instance of CRYP use: restore context for CRYP hw module */ ctx->hcryp_aes.Instance->CR = ctx->ctx_save_cr; ctx->hcryp_aes.Phase = HAL_CRYP_PHASE_READY; ctx->hcryp_aes.Init.DataType = CRYP_DATATYPE_8B; ctx->hcryp_aes.Init.pKey = ctx->aes_key; if (mode == MBEDTLS_AES_DECRYPT) { /* AES decryption */ if (mbedtls_internal_aes_decrypt(ctx, input, output)) { return ST_ERR_AES_BUSY; } } else { /* AES encryption */ if (mbedtls_internal_aes_encrypt(ctx, input, output)) { return ST_ERR_AES_BUSY; } } /* allow multi-instance of CRYP use: save context for CRYP HW module CR */ ctx->ctx_save_cr = ctx->hcryp_aes.Instance->CR; return (0); } #if defined(MBEDTLS_CIPHER_MODE_CBC) static int st_cbc_restore_context(mbedtls_aes_context *ctx) { uint32_t tickstart; tickstart = HAL_GetTick(); while ((ctx->hcryp_aes.Instance->SR & AES_SR_BUSY) != 0) { if ((HAL_GetTick() - tickstart) > ST_AES_TIMEOUT) { return ST_ERR_AES_BUSY; // timeout: CRYP processor is busy } } /* allow multi-instance of CRYP use: restore context for CRYP hw module */ ctx->hcryp_aes.Instance->CR = ctx->ctx_save_cr; return 0; } static int st_hal_cryp_cbc(mbedtls_aes_context *ctx, uint32_t opmode, size_t length, unsigned char iv[16], uint8_t *input, uint8_t *output) { ctx->hcryp_aes.Init.pInitVect = &iv[0]; // used in process, not in the init /* At this moment only, we know we have CBC mode: Re-initialize AES IP with proper parameters and apply key and IV for multi context usecase */ if (HAL_CRYP_DeInit(&ctx->hcryp_aes) != HAL_OK) { return ST_ERR_AES_BUSY; } ctx->hcryp_aes.Init.OperatingMode = opmode; ctx->hcryp_aes.Init.ChainingMode = CRYP_CHAINMODE_AES_CBC; ctx->hcryp_aes.Init.KeyWriteFlag = CRYP_KEY_WRITE_ENABLE; if (HAL_CRYP_Init(&ctx->hcryp_aes) != HAL_OK) { return ST_ERR_AES_BUSY; } if (HAL_CRYPEx_AES(&ctx->hcryp_aes, input, length, output, 10) != 0) { return ST_ERR_AES_BUSY; } return 0; } int mbedtls_aes_crypt_cbc(mbedtls_aes_context *ctx, int mode, size_t length, unsigned char iv[16], const unsigned char *input, unsigned char *output) { uint32_t tickstart; uint32_t *iv_ptr = (uint32_t *)&iv[0]; if (length % 16) { return (MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH); } ctx->hcryp_aes.Init.pInitVect = &iv[0]; if (st_cbc_restore_context(ctx) != 0) { return (ST_ERR_AES_BUSY); } if (mode == MBEDTLS_AES_DECRYPT) { if (st_hal_cryp_cbc(ctx, CRYP_ALGOMODE_KEYDERIVATION_DECRYPT, length, iv, (uint8_t *)input, (uint8_t *)output) != 0) { return ST_ERR_AES_BUSY; } /* Save the internal IV vector for multi context purpose */ tickstart = HAL_GetTick(); while ((ctx->hcryp_aes.Instance->SR & AES_SR_BUSY) != 0) { if ((HAL_GetTick() - tickstart) > ST_AES_TIMEOUT) { return ST_ERR_AES_BUSY; // timeout: CRYP processor is busy } } ctx->ctx_save_cr = ctx->hcryp_aes.Instance->CR; // save here before overwritten ctx->hcryp_aes.Instance->CR &= ~AES_CR_EN; *iv_ptr++ = ctx->hcryp_aes.Instance->IVR3; *iv_ptr++ = ctx->hcryp_aes.Instance->IVR2; *iv_ptr++ = ctx->hcryp_aes.Instance->IVR1; *iv_ptr++ = ctx->hcryp_aes.Instance->IVR0; } else { if (st_hal_cryp_cbc(ctx, CRYP_ALGOMODE_ENCRYPT, length, iv, (uint8_t *)input, (uint8_t *)output) != 0) { return ST_ERR_AES_BUSY; } memcpy(iv, output, 16); /* current output is the IV vector for the next call */ ctx->ctx_save_cr = ctx->hcryp_aes.Instance->CR; } return 0; } #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_CIPHER_MODE_CFB) int mbedtls_aes_crypt_cfb128(mbedtls_aes_context *ctx, int mode, size_t length, size_t *iv_off, unsigned char iv[16], const unsigned char *input, unsigned char *output) { int c; size_t n = *iv_off; if (mode == MBEDTLS_AES_DECRYPT) { while (length--) { if (n == 0) if (mbedtls_aes_crypt_ecb(ctx, MBEDTLS_AES_ENCRYPT, iv, iv) != 0) { return ST_ERR_AES_BUSY; } c = *input++; *output++ = (unsigned char)(c ^ iv[n]); iv[n] = (unsigned char) c; n = (n + 1) & 0x0F; } } else { while (length--) { if (n == 0) if (mbedtls_aes_crypt_ecb(ctx, MBEDTLS_AES_ENCRYPT, iv, iv) != 0) { return ST_ERR_AES_BUSY; } iv[n] = *output++ = (unsigned char)(iv[n] ^ *input++); n = (n + 1) & 0x0F; } } *iv_off = n; return (0); } int mbedtls_aes_crypt_cfb8(mbedtls_aes_context *ctx, int mode, size_t length, unsigned char iv[16], const unsigned char *input, unsigned char *output) { unsigned char c; unsigned char ov[17]; while (length--) { memcpy(ov, iv, 16); if (mbedtls_aes_crypt_ecb(ctx, MBEDTLS_AES_ENCRYPT, iv, iv) != 0) { return ST_ERR_AES_BUSY; } if (mode == MBEDTLS_AES_DECRYPT) { ov[16] = *input; } c = *output++ = (unsigned char)(iv[0] ^ *input++); if (mode == MBEDTLS_AES_ENCRYPT) { ov[16] = c; } memcpy(iv, ov + 1, 16); } return (0); } #endif /*MBEDTLS_CIPHER_MODE_CFB */ #if defined(MBEDTLS_CIPHER_MODE_CTR) int mbedtls_aes_crypt_ctr(mbedtls_aes_context *ctx, size_t length, size_t *nc_off, unsigned char nonce_counter[16], unsigned char stream_block[16], const unsigned char *input, unsigned char *output) { int c, i; size_t n = *nc_off; while (length--) { if (n == 0) { if (mbedtls_aes_crypt_ecb(ctx, MBEDTLS_AES_ENCRYPT, nonce_counter, stream_block) != 0) { return ST_ERR_AES_BUSY; } for (i = 16; i > 0; i--) if (++nonce_counter[i - 1] != 0) { break; } } c = *input++; *output++ = (unsigned char)(c ^ stream_block[n]); n = (n + 1) & 0x0F; } *nc_off = n; return (0); } #endif /* MBEDTLS_CIPHER_MODE_CTR */ int mbedtls_internal_aes_encrypt(mbedtls_aes_context *ctx, const unsigned char input[16], unsigned char output[16]) { if (HAL_CRYP_AESECB_Encrypt(&ctx->hcryp_aes, (uint8_t *)input, 16, (uint8_t *)output, 10) != HAL_OK) { // error found return ST_ERR_AES_BUSY; } return 0; } int mbedtls_internal_aes_decrypt(mbedtls_aes_context *ctx, const unsigned char input[16], unsigned char output[16]) { if (HAL_CRYP_AESECB_Decrypt(&ctx->hcryp_aes, (uint8_t *)input, 16, (uint8_t *)output, 10) != HAL_OK) { // error found return ST_ERR_AES_BUSY; } return 0; } #if !defined(MBEDTLS_DEPRECATED_REMOVED) void mbedtls_aes_encrypt(mbedtls_aes_context *ctx, const unsigned char input[16], unsigned char output[16]) { mbedtls_internal_aes_encrypt(ctx, input, output); } void mbedtls_aes_decrypt(mbedtls_aes_context *ctx, const unsigned char input[16], unsigned char output[16]) { mbedtls_internal_aes_decrypt(ctx, input, output); } #endif /* MBEDTLS_DEPRECATED_REMOVED */ #endif /*MBEDTLS_AES_ALT*/ #endif /* TARGET_STM32L4 */
the_stack_data/231391863.c
/* ======================================================================== * Copyright 2018 Eduardo Chappa * * 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 * * ======================================================================== */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> int main(int, char **); int main(int argc, char *argv[]) { int rv = 0, i; FILE *fph, *fpc, *fpa; char *opt; fph = fpc = fpa = NULL; if (argc < 2) { fprintf(stdout, "Not enough arguments.\n"); fprintf(stdout, "Usage: %s opt ...\n", argv[0]); fprintf(stdout, "opt can be drivers, mkauths, version, setproto or sslinit\n"); exit(1); } opt = argv[1]; if (!strcmp(opt, "drivers")) { fph = fopen("linkage.h", "w"); fpc = fopen("linkage.c", "w"); for (i = 2; i < argc; i++) { fprintf(fph, "extern DRIVER %sdriver;\n", argv[i]); fprintf(fpc, " mail_link (&%sdriver); /* link in the %s driver */\n", argv[i], argv[i]); } } else if (!strcmp(opt, "mkauths")) { fph = fopen("linkage.h", "a"); fpc = fopen("linkage.c", "a"); fpa = fopen("auths.c", "w"); for (i = 2; i < argc; i++) { fprintf(fph, "extern AUTHENTICATOR auth_%s;\n", argv[i]); fprintf(fpc, " auth_link (&auth_%s); /* link in the %s authenticator */\n", argv[i], argv[i]); fprintf(fpa, "#include \"auth_%s.c\"\n", argv[i]); } } else if (!strcmp(opt, "setproto")) { if (argc != 4) { fprintf(stdout, "setproto requires two additional arguments\n"); exit(1); } fph = fopen("linkage.h", "a"); fprintf(fph, "#define CREATEPROTO %sproto\n", argv[2]); fprintf(fph, "#define APPENDPROTO %sproto\n", argv[3]); } else if (!strcmp(opt, "sslinit")) { fpc = fopen("linkage.c", "a"); fprintf(fpc, "%s\n", "ssl_onceonlyinit();"); } else if (!strcmp(opt, "version")) { fpc = fopen("linkage.c", "a"); fprintf(fpc, "%s\n", "mail_versioncheck(CCLIENTVERSION);"); } else { fprintf(stdout, "Try: \"drivers\", \"mkauths\", \"setproto\", \"sslinit\", or \"version\".\n"); exit(1); } if (fpa != NULL) fclose(fpa); if (fpc != NULL) fclose(fpc); if (fph != NULL) fclose(fph); exit(0); }
the_stack_data/168892708.c
/* * Copyright (C) 2014, Galois, Inc. * This sotware is distributed under a standard, three-clause BSD license. * Please see the file LICENSE, distributed with this software, for specific * terms and conditions. */ #include <stdio.h> #include <errno.h> FILE *fopen(const char *path, const char *mode) { #ifdef PROFILING return profile_fopen(path, mode); #else errno = EACCES; return NULL; #endif }
the_stack_data/149777.c
#include<stdio.h> int main() { int n,K,a[10001],b[101],c[101],d[101],e[101],J[101],i,j,A,B; scanf("%d%d",&n,&K); for(i=0;i<n;i++){ scanf("%d",&a[i]); } int N(int l,int r) { int Add=0,i; for(i=l;i<=r;i++){ Add=(Add+a[i])%n; } return Add; } int M(int l,int r) { int Mul=1,i; for(i=l;i<=r;i++){ Mul=(Mul*a[i])%n; } return Mul; } int H(int l,int r) { int Or=a[l],i; for(i=l;i<r;i++){ Or=Or^a[i+1]; } return Or; } for(i=0;i<K;i++){ scanf("%d%d",&b[i],&c[i]); } for(i=0;i<K;i++){ d[i]=N(b[i],c[i]); e[i]=M(b[i],c[i]); if(d[i]<=e[i]){ A=d[i]; B=e[i]; } else { A=e[i]; B=d[i]; } J[i]=H(A,B); } for(i=0;i<K;i++){ printf("%d\n",J[i]); } return 0; }
the_stack_data/66580.c
/* * This source herein may be modified and/or distributed by anybody who * so desires, with the following restrictions: * 1.) No portion of this notice shall be removed. * 2.) Credit shall not be taken for the creation of this source. * 3.) This code is not to be traded, sold, or used for personal * gain or profit. */ /* Included in this file are all system dependent routines. Extensive use * of #ifdef's will be used to compile the appropriate code on each system: * * UNIX: all UNIX systems. * UNIX_BSD4_2: UNIX BSD 4.2 and later, UTEK, (4.1 BSD too?) * UNIX_SYSV: UNIX system V * UNIX_V7: UNIX version 7 * * All UNIX code should be included between the single "#ifdef UNIX" at the * top of this file, and the "#endif" at the bottom. * * To change a routine to include a new UNIX system, simply #ifdef the * existing routine, as in the following example: * * To make a routine compatible with UNIX system 5, change the first * function to the second: * * md_function() * { * code; * } * * md_function() * { * #ifdef UNIX_SYSV * sys5code; * #else * code; * #endif * } * * Appropriate variations of this are of course acceptible. * The use of "#elseif" is discouraged because of non-portability. * If the correct #define doesn't exist, "UNIX_SYSV" in this case, make it up * and insert it in the list at the top of the file. Alter the CFLAGS * in you Makefile appropriately. */ #ifdef UNIX #include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <sys/wait.h> #include <sys/file.h> #include <sys/stat.h> #include <pwd.h> #include <fcntl.h> #ifdef UNIX_BSD4_2 #include <sys/time.h> #include <sgtty.h> #endif #ifdef UNIX_SYSV #include <time.h> #include <termio.h> #endif #include <signal.h> #include "rogue.h" /* md_slurp: * * This routine throws away all keyboard input that has not * yet been read. It is used to get rid of input that the user may have * typed-ahead. * * This function is not necessary, so it may be stubbed. The might cause * message-line output to flash by because the game has continued to read * input without waiting for the user to read the message. Not such a * big deal. */ void md_slurp() { long ln = 0; #ifdef UNIX_BSD4_2 ioctl(0, FIONREAD, &ln); #endif #ifdef UNIX_SYSV ioctl(0, TCFLSH, &ln); ln = 0; #endif #ifndef CROSS ln += stdin->_cnt; #endif for (; ln > 0; ln--) { (void) getchar(); } } /* md_control_keyboard(): * * This routine is much like md_cbreak_no_echo_nonl() below. It sets up the * keyboard for appropriate input. Specifically, it prevents the tty driver * from stealing characters. For example, ^Y is needed as a command * character, but the tty driver intercepts it for another purpose. Any * such behavior should be stopped. This routine could be avoided if * we used RAW mode instead of CBREAK. But RAW mode does not allow the * generation of keyboard signals, which the program uses. * * The parameter 'mode' when true, indicates that the keyboard should * be set up to play rogue. When false, it should be restored if * necessary. * * This routine is not strictly necessary and may be stubbed. This may * cause certain command characters to be unavailable. */ void md_control_keybord(mode) boolean mode; { static boolean called_before = 0; #ifdef UNIX_BSD4_2 static struct ltchars ltc_orig; static struct tchars tc_orig; struct ltchars ltc_temp; struct tchars tc_temp; #endif #ifdef UNIX_SYSV static struct termio _oldtty; struct termio _tty; #endif if (!called_before) { called_before = 1; #ifdef UNIX_BSD4_2 ioctl(0, TIOCGETC, &tc_orig); ioctl(0, TIOCGLTC, &ltc_orig); #endif #ifdef UNIX_SYSV ioctl(0, TCGETA, &_oldtty); #endif } #ifdef UNIX_BSD4_2 ltc_temp = ltc_orig; tc_temp = tc_orig; #endif #ifdef UNIX_SYSV _tty = _oldtty; #endif if (!mode) { #ifdef UNIX_BSD4_2 ltc_temp.t_suspc = ltc_temp.t_dsuspc = -1; ltc_temp.t_rprntc = ltc_temp.t_flushc = -1; ltc_temp.t_werasc = ltc_temp.t_lnextc = -1; tc_temp.t_startc = tc_temp.t_stopc = -1; #endif #ifdef UNIX_SYSV _tty.c_cc[VSWTC] = 0; #endif } #ifdef UNIX_BSD4_2 ioctl(0, TIOCSETC, &tc_temp); ioctl(0, TIOCSLTC, &ltc_temp); #endif #ifdef UNIX_SYSV ioctl(0, TCSETA, &_tty); #endif } /* md_heed_signals(): * * This routine tells the program to call particular routines when * certain interrupts/events occur: * * SIGINT: call onintr() to interrupt fight with monster or long rest. * SIGQUIT: call byebye() to check for game termination. * SIGHUP: call error_save() to save game when terminal hangs up. * * On VMS, SIGINT and SIGQUIT correspond to ^C and ^Y. * * This routine is not strictly necessary and can be stubbed. This will * mean that the game cannot be interrupted properly with keyboard * input, this is not usually critical. */ void md_heed_signals() { signal(SIGINT, onintr); signal(SIGQUIT, byebye); signal(SIGHUP, error_save); } /* md_ignore_signals(): * * This routine tells the program to completely ignore the events mentioned * in md_heed_signals() above. The event handlers will later be turned on * by a future call to md_heed_signals(), so md_heed_signals() and * md_ignore_signals() need to work together. * * This function should be implemented or the user risks interrupting * critical sections of code, which could cause score file, or saved-game * file, corruption. */ void md_ignore_signals() { signal(SIGQUIT, SIG_IGN); signal(SIGINT, SIG_IGN); signal(SIGHUP, SIG_IGN); } /* md_get_file_id(): * * This function returns an integer that uniquely identifies the specified * file. It need not check for the file's existence. In UNIX, the inode * number is used. * * This function is used to identify saved-game files. */ int md_get_file_id(fname) char *fname; { struct stat sbuf; if (stat(fname, &sbuf)) { return(-1); } return((int) sbuf.st_ino); } /* md_link_count(): * * This routine returns the number of hard links to the specified file. * * This function is not strictly necessary. On systems without hard links * this routine can be stubbed by just returning 1. */ int md_link_count(fname) char *fname; { struct stat sbuf; stat(fname, &sbuf); return((int) sbuf.st_nlink); } /* md_gct(): (Get Current Time) * * This function returns the current year, month(1-12), day(1-31), hour(0-23), * minute(0-59), and second(0-59). This is used for identifying the time * at which a game is saved. * * This function is not strictly necessary. It can be stubbed by returning * zeros instead of the correct year, month, etc. If your operating * system doesn't provide all of the time units requested here, then you * can provide only those that it does, and return zeros for the others. * If you cannot provide good time values, then users may be able to copy * saved-game files and play them. */ void md_gct(rt_buf) struct rogue_time *rt_buf; { struct tm *t, *localtime(); long seconds; time(&seconds); t = localtime(&seconds); rt_buf->year = t->tm_year; rt_buf->month = t->tm_mon + 1; rt_buf->day = t->tm_mday; rt_buf->hour = t->tm_hour; rt_buf->minute = t->tm_min; rt_buf->second = t->tm_sec; } /* md_gfmt: (Get File Modification Time) * * This routine returns a file's date of last modification in the same format * as md_gct() above. * * This function is not strictly necessary. It is used to see if saved-game * files have been modified since they were saved. If you have stubbed the * routine md_gct() above by returning constant values, then you may do * exactly the same here. * Or if md_gct() is implemented correctly, but your system does not provide * file modification dates, you may return some date far in the past so * that the program will never know that a saved-game file being modified. * You may also do this if you wish to be able to restore games from * saved-games that have been modified. */ void md_gfmt(fname, rt_buf) char *fname; struct rogue_time *rt_buf; { struct stat sbuf; long seconds; struct tm *t; stat(fname, &sbuf); seconds = (long) sbuf.st_mtime; t = localtime(&seconds); rt_buf->year = t->tm_year; rt_buf->month = t->tm_mon + 1; rt_buf->day = t->tm_mday; rt_buf->hour = t->tm_hour; rt_buf->minute = t->tm_min; rt_buf->second = t->tm_sec; } /* md_df: (Delete File) * * This function deletes the specified file, and returns true (1) if the * operation was successful. This is used to delete saved-game files * after restoring games from them. * * Again, this function is not strictly necessary, and can be stubbed * by simply returning 1. In this case, saved-game files will not be * deleted and can be replayed. */ boolean md_df(fname) char *fname; { if (unlink(fname)) { return(0); } return(1); } /* md_gln: (Get login name) * * This routine returns the login name of the user. This string is * used mainly for identifying users in score files. * * A dummy string may be returned if you are unable to implement this * function, but then the score file would only have one name in it. */ char * md_gln() { struct passwd *p, *getpwuid(); if (!(p = getpwuid(getuid()))) return((char *)NULL); return(p->pw_name); } /* md_sleep: * * This routine causes the game to pause for the specified number of * seconds. * * This routine is not particularly necessary at all. It is used for * delaying execution, which is useful to this program at some times. */ void md_sleep(nsecs) int nsecs; { (void) sleep(nsecs); } /* md_getenv() * * This routine gets certain values from the user's environment. These * values are strings, and each string is identified by a name. The names * of the values needed, and their use, is as follows: * * TERMCAP * The name of the users's termcap file, NOT the termcap entries * themselves. This is used ONLY if the program is compiled with * CURSES defined (-DCURSES). Even in this case, the program need * not find a string for TERMCAP. If it does not, it will use the * default termcap file; * TERM * The name of the users's terminal. This is used ONLY if the program * is compiled with CURSES defined (-DCURSES). In this case, the string * value for TERM must be found, or the routines in curses.c cannot * function, and the program will quit. * ROGUEOPTS * A string containing the various game options. This need not be * defined. * HOME * The user's home directory. This is only used when the user specifies * '~' as the first character of a saved-game file. This string need * not be defined. * SHELL * The user's favorite shell. If not found, "/bin/sh" is assumed. * * If your system does not provide a means of searching for these values, * you will have to do it yourself. None of the values above really need * to be defined except TERM when the program is compiled with CURSES * defined. In this case, as a bare minimum, you can check the 'name' * parameter, and if it is "TERM" find the terminal name and return that, * else return zero. If the program is not compiled with CURSES, you can * get by with simply always returning zero. Returning zero indicates * that their is no defined value for the given string. */ char * md_getenv(name) char *name; { char *value; char *getenv(); value = getenv(name); return(value); } /* md_malloc() * * This routine allocates, and returns a pointer to, the specified number * of bytes. This routines absolutely MUST be implemented for your * particular system or the program will not run at all. Return zero * when no more memory can be allocated. */ char * md_malloc(n) int n; { char *t; t = malloc(n); return(t); } /* md_gseed() (Get Seed) * * This function returns a seed for the random number generator (RNG). This * seed causes the RNG to begin generating numbers at some point in it's * sequence. Without a random seed, the RNG will generate the same set * of numbers, and every game will start out exactly the same way. A good * number to use is the process id, given by getpid() on most UNIX systems. * * You need to find some single random integer, such as: * process id. * current time (minutes + seconds) returned from md_gct(), if implemented. * * It will not help to return "get_rand()" or "rand()" or the return value of * any pseudo-RNG. If you don't have a random number, you can just return 1, * but this means your games will ALWAYS start the same way, and will play * exactly the same way given the same input. */ int md_gseed() { return(getpid()); } /* md_exit(): * * This function causes the program to discontinue execution and exit. * This function must be implemented or the program will continue to * hang when it should quit. */ void md_exit(status) int status; { exit(status); } /* md_lock(): * * This function is intended to give the user exclusive access to the * score file. It does so by "creat"ing a lock file, which can only * be created if it does not already exist. The file is deleted when * score file processing is finished. The lock file should be located * in the same directory as the score file. These full path names should * be defined for any particular site in rogue.h. The constants SCORE_FILE * and LOCK_FILE define these file names. * * When the parameter 'l' is non-zero (true), a lock is requested. Otherwise * the lock is released by removing the lock file. */ void md_lock(l) boolean l; { int tries; char *lock_file = LOCK_FILE; if (l) { for (tries = 0; tries < 3; tries++) { if (md_get_file_id(lock_file) == -1) { if (creat(lock_file, 0444) != -1) { break; } else { message("cannot lock score file", 0); } } else { message("waiting to lock score file", 0); } sleep(1); } } else { (void) unlink(lock_file); } } /* md_shell(): * * This function spawns a shell for the user to use. When this shell is * terminated, the game continues. Since this program may often be run * setuid to gain access to privileged files, care is taken that the shell * is run with the user's REAL user id, and not the effective user id. * The effective user id is restored after the shell completes. */ void md_shell(shell) char *shell; { int w; if (fork() == 0) { int uid; uid = getuid(); setuid(uid); execl(shell, shell, (char*)0); } wait(&w); } /* If you have a viable curses/termlib library, then use it and don't bother * implementing the routines below. And don't compile with -DCURSES. */ #ifdef CURSES /* md_cbreak_no_echo_nonl: * * This routine sets up some terminal characteristics. The tty-driver * must be told to: * 1.) Not echo input. * 2.) Transmit input characters immediately upon typing. (cbreak mode) * 3.) Move the cursor down one line, without changing column, and * without generating a carriage-return, when it * sees a line-feed. This is only necessary if line-feed is ever * used in the termcap 'do' (cursor down) entry, in which case, * your system should must have a way of accomplishing this. * * When the parameter 'on' is true, the terminal is set up as specified * above. When this parameter is false, the terminal is restored to the * original state. * * Raw mode should not to be used. Keyboard signals/events/interrupts should * be sent, although they are not strictly necessary. See notes in * md_heed_signals(). * * This function must be implemented for rogue to run properly if the * program is compiled with CURSES defined to use the enclosed curses * emulation package. If you are not using this, then this routine is * totally unnecessary. * * Notice that information is saved between calls. This is used to * restore the terminal to an initial saved state. * */ void md_cbreak_no_echo_nonl(on) boolean on; { #ifdef UNIX_BSD4_2 static struct sgttyb tty_buf; static int tsave_flags; if (on) { ioctl(0, TIOCGETP, &tty_buf); tsave_flags = tty_buf.sg_flags; tty_buf.sg_flags |= CBREAK; tty_buf.sg_flags &= ~(ECHO | CRMOD); /* CRMOD: see note 3 above */ ioctl(0, TIOCSETP, &tty_buf); } else { tty_buf.sg_flags = tsave_flags; ioctl(0, TIOCSETP, &tty_buf); } #endif #ifdef UNIX_SYSV struct termio tty_buf; static struct termio tty_save; if (on) { ioctl(0, TCGETA, &tty_buf); tty_save = tty_buf; tty_buf.c_lflag &= ~(ICANON | ECHO); tty_buf.c_oflag &= ~ONLCR; tty_buf.c_cc[4] = 1; /* MIN */ tty_buf.c_cc[5] = 2; /* TIME */ ioctl(0, TCSETAF, &tty_buf); } else { ioctl(0, TCSETAF, &tty_save); } #endif } /* md_tstp(): * * This function puts the game to sleep and returns to the shell. This * only applies to UNIX 4.2 and 4.3. For other systems, the routine should * be provided as a do-nothing routine. md_tstp() will only be referenced * in the code when compiled with CURSES defined. * */ void md_tstp() { #ifdef UNIX_BSD4_2 kill(0, SIGTSTP); #endif } #endif #endif
the_stack_data/9512472.c
#include <stdio.h> typedef struct { char name[11]; char gender; char id[11]; int grade; }Student; int main(void) { int n; scanf("%d", &n); Student male_l, female_h; int l = 101, h = 0; int f = 0, m = 0; for (int i = 0; i < n; i++) { Student cur; scanf("%s %c %s %d", cur.name, &cur.gender, cur.id, &cur.grade); if (cur.gender == 'M' && cur.grade < l) { male_l = cur; l = male_l.grade; m = 1; } else if (cur.gender == 'F' && cur.grade > h) { female_h = cur; h = female_h.grade; f = 1; } } if (f) printf("%s %s\n", female_h.name, female_h.id); else printf("Absent\n"); if (m) printf("%s %s\n", male_l.name, male_l.id); else printf("Absent\n"); if (!f || !m) printf("NA"); else printf("%d", female_h.grade - male_l.grade); }
the_stack_data/111077201.c
/* Compile with gcc -Wall -g -shared -o libfoo.so foo.c. */ struct S { int m0; }; int f(struct S* s) {return s->m0;}
the_stack_data/812927.c
#include <stdio.h> void scilab_rt_display_s0i2_(char* name, int si00, int si01, int in0[si00][si01]) { int i; int j; int val0 = 0; printf("%s\n", name); for (i = 0; i < si00; ++i) { for (j = 0; j < si01; ++j) { val0 += in0[i][j]; } } printf("%d\n", val0); }
the_stack_data/153266904.c
#include <stdio.h> #include <stdlib.h> #define MIN_PID 300 #define MAX_PID 5000 // allocate_map int pid[MAX_PID - MIN_PID] = {0}; int allocate_pid(void) { int i, flag = 1; for (i = 0; i < MAX_PID - MIN_PID; i++) { if (pid[i] == 0) { pid[i] = 1; flag = 0; break; } } return flag ? 1 : i; } void release_pid(int id) { pid[id] = 0; }
the_stack_data/168893480.c
#include <assert.h> #include <errno.h> #include <fcntl.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/stat.h> char nonexistent_name[] = "noexist-##"; void create_file(const char *path, const char *buffer, int mode) { int fd = open(path, O_WRONLY | O_CREAT | O_EXCL, mode); assert(fd >= 0); assert(!errno); int err = write(fd, buffer, sizeof(char) * strlen(buffer)); assert(err == (sizeof(char) * strlen(buffer))); assert(!errno); close(fd); assert(!errno); } void setup() { create_file("test-file", "abcdef", 0777); mkdir("test-folder", 0777); assert(!errno); } void cleanup() { unlink("test-file"); rmdir("test-folder"); for (int i = 0; i < 3; i++) { for (int j = 0; j < 16; j++) { nonexistent_name[8] = 'a' + i; nonexistent_name[9] = 'a' + j; unlink(nonexistent_name); } } errno = 0; unlink("creat-me"); assert(!errno); } void test() { struct stat s; int modes[] = {O_RDONLY, O_WRONLY, O_RDWR}; for (int i = 0; i < 3; i++) { for (int j = 0; j < 16; j++) { int flags = modes[i]; if (j & 0x1) flags |= O_CREAT; if (j & 0x2) flags |= O_EXCL; if (j & 0x4) flags |= O_TRUNC; if (j & 0x8) flags |= O_APPEND; printf("EXISTING FILE %d,%d\n", i, j); int success = open("test-file", flags, 0777) != -1; printf("success: %d\n", success); printf("errno: %d\n", errno); if ((flags & O_CREAT) && (flags & O_EXCL)) { assert(!success); assert(errno == EEXIST); } else { assert(success); assert(errno == 0); } errno = 0; int ret = stat("test-file", &s); assert(ret == 0); assert(errno == 0); printf("st_mode: 0%o\n", s.st_mode & 037777777000); assert((s.st_mode & 037777777000) == 0100000); memset(&s, 0, sizeof s); printf("\n"); errno = 0; printf("EXISTING FOLDER %d,%d\n", i, j); success = open("test-folder", flags, 0777) != -1; printf("success: %d\n", success); printf("errno: %d\n", errno); if ((flags & O_CREAT) && (flags & O_EXCL)) { assert(!success); assert(errno == EEXIST); } else if ((flags & O_TRUNC) || i != 0 /*mode != O_RDONLY*/) { assert(!success); assert(errno == EISDIR); } else { assert(success); assert(errno == 0); } errno = 0; ret = stat("test-folder", &s); assert(ret == 0); assert(errno == 0); printf("st_mode: 0%o\n", s.st_mode & 037777777000); assert((s.st_mode & 037777777000) == 040000); memset(&s, 0, sizeof s); printf("\n"); errno = 0; nonexistent_name[8] = 'a' + i; nonexistent_name[9] = 'a' + j; printf("NON-EXISTING %d,%d\n", i, j); success = open(nonexistent_name, flags, 0777) != -1; printf("success: %d\n", success); printf("errno: %d\n", errno); if ((flags & O_CREAT)) { assert(success); assert(errno == 0); } else { assert(!success); assert(errno == ENOENT); } ret = stat(nonexistent_name, &s); printf("st_mode: 0%o\n", s.st_mode & 037777777000); if ((flags & O_CREAT)) { assert(ret == 0); assert((s.st_mode & 037777777000) == 0100000); } else { assert(ret != 0); assert((s.st_mode & 037777777000) == 0); } memset(&s, 0, sizeof s); printf("\n"); errno = 0; } } printf("CREAT\n"); printf("success: %d\n", creat("creat-me", 0777) != -1); printf("errno: %d\n", errno); errno = 0; } int main() { atexit(cleanup); signal(SIGABRT, cleanup); setup(); test(); #ifdef REPORT_RESULT int result = 0; REPORT_RESULT(); #endif return EXIT_SUCCESS; }
the_stack_data/231393530.c
/* * Copyright (c) 2007 Wayne Meissner. All rights reserved. * * For licensing, see LICENSE.SPECS */ #include <sys/types.h> #include <stdio.h> #include <string.h> #include <stdint.h> #if defined(__sparc) && defined(__sun__) #define fix_mem_access __asm("ta 6") #else #define fix_mem_access #endif typedef int8_t s8; typedef uint8_t u8; typedef int16_t s16; typedef uint16_t u16; typedef int32_t s32; typedef uint32_t u32; typedef int64_t s64; typedef uint64_t u64; typedef signed long sL; typedef unsigned long uL; typedef float f32; typedef double f64; typedef long double f128; #if !defined(__OpenBSD__) typedef unsigned long ulong; #endif #define ADD(T) T add_##T(T arg1, T arg2) { return arg1 + arg2; } #define SUB(T) T sub_##T(T arg1, T arg2) { return arg1 - arg2; } #define MUL(T) T mul_##T(T arg1, T arg2) { return arg1 * arg2; } #define DIV(T) T div_##T(T arg1, T arg2) { return arg1 / arg2; } #define RET(T) T ret_##T(T arg1) { return arg1; } #define SET(T) static T T##_;void set_##T(T arg1) { T##_ = arg1; } #define GET(T) T get_##T() { return T##_; } typedef char* ptr; #define TEST(T) ADD(T) SUB(T) MUL(T) DIV(T) RET(T) SET(T) GET(T) TEST(s8); TEST(u8); TEST(s16); TEST(u16); TEST(s32); TEST(u32); TEST(s64); TEST(u64); TEST(float); TEST(double); TEST(long); TEST(ulong); TEST(f128); #define ADD2(R, T1, T2) R add_##T1##T2##_##R(T1 arg1, T2 arg2) { return arg1 + arg2; } #define SUB2(R, T1, T2) R sub_##T1##T2##_##R(T1 arg1, T2 arg2) { return arg1 - arg2; } #define MUL2(R, T1, T2) R mul_##T1##T2##_##R(T1 arg1, T2 arg2) { return arg1 * arg2; } #define DIV2(R, T1, T2) R div_##T1##T2##_##R(T1 arg1, T2 arg2) { return arg1 / arg2; } #define T2__(R, T1, T2) ADD2(R, T1, T2) SUB2(R, T1, T2) MUL2(R, T1, T2) DIV2(R, T1, T2) #define T2_(R, T1) \ T2__(R, T1, s8) T2__(R, T1, u8) \ T2__(R, T1, s16) T2__(R, T1, u16) \ T2__(R, T1, s32) T2__(R, T1, u32) \ T2__(R, T1, sL) T2__(R, T1, uL) \ T2__(R, T1, s64) T2__(R, T1, u64) \ #define TEST2(R) \ T2_(R, s8) T2_(R, u8) T2_(R, s16) T2_(R, u16) T2_(R, s32) T2_(R, u32) \ T2_(R, sL) T2_(R, uL) T2_(R, s64) T2_(R, u64) #ifdef notyet TEST2(s32) TEST2(u32) TEST2(s64) TEST2(u64) #endif #define ADD3(R, T1, T2, T3) R add_##T1##T2##T3##_##R(T1 arg1, T2 arg2, T3 arg3) { return arg1 + arg2 + arg3; } #define pack_f32(buf, v) do { float f = v; memcpy((buf), &f, sizeof(f)); } while(0) #define pack_f64(buf, v) do { double f = v; memcpy((buf), &f, sizeof(f)); } while(0) #define pack_int(buf, v) do { *(buf) = v; } while(0) #define pack_s8 pack_int #define pack_u8 pack_int #define pack_s16 pack_int #define pack_u16 pack_int #define pack_s32 pack_int #define pack_u32 pack_int #define pack_s64 pack_int #define pack_u64 pack_int #define pack_sL pack_int #define pack_uL pack_int #define PACK3(R, T1, T2, T3) void pack_##T1##T2##T3##_##R(T1 arg1, T2 arg2, T3 arg3, R* r) { \ fix_mem_access; \ pack_##T1(&r[0], arg1); \ pack_##T2(&r[1], arg2); \ pack_##T3(&r[2], arg3); \ } #define T3___(R, T1, T2, T3) PACK3(R, T1, T2, T3) /* SUB2(R, T1, T2) MUL2(R, T1, T2) DIV2(R, T1, T2) */ #define T3__(R, T1, T2) \ T3___(R, T1, T2, s8) T3___(R, T1, T2, u8) \ T3___(R, T1, T2, s16) T3___(R, T1, T2, u16) \ T3___(R, T1, T2, s32) T3___(R, T1, T2, u32) \ T3___(R, T1, T2, sL) T3___(R, T1, T2, uL) \ T3___(R, T1, T2, s64) T3___(R, T1, T2, u64) \ T3___(R, T1, T2, f32) T3___(R, T1, T2, f64) \ #define T3_(R, T1) \ T3__(R, T1, s8) T3__(R, T1, u8) \ T3__(R, T1, s16) T3__(R, T1, u16) \ T3__(R, T1, s32) T3__(R, T1, u32) \ T3__(R, T1, sL) T3__(R, T1, uL) \ T3__(R, T1, s64) T3__(R, T1, u64) \ T3__(R, T1, f32) T3__(R, T1, f64) \ #define TEST3(R) \ T3_(R, s8) T3_(R, u8) T3_(R, s16) T3_(R, u16) T3_(R, s32) T3_(R, u32) \ T3_(R, sL) T3_(R, uL) T3_(R, s64) T3_(R, u64) T3_(R, f32) T3_(R, f64) TEST3(s64) void foo6(intptr_t i1, intptr_t i2, intptr_t i3, intptr_t i4, intptr_t i5, intptr_t i6) { } void foo5(intptr_t i1, intptr_t i2, intptr_t i3, intptr_t i4, intptr_t i5) { }
the_stack_data/70448932.c
extern void abort(void); void reach_error(){} extern void abort(void); void assume_abort_if_not(int cond) { if(!cond) {abort();} } void __VERIFIER_assert(int cond) { if (!(cond)) { ERROR: {reach_error();abort();} } return; } int __VERIFIER_nondet_int(); int main() { unsigned int i=0; int x=0, y=0; int n=__VERIFIER_nondet_int(); if (!(n>0)) return 0; for(i=0; 1; i++) { __VERIFIER_assert(x==0); } __VERIFIER_assert(x==0); }
the_stack_data/90764578.c
#include <stdio.h> extern void c_function() { printf("Hello from C!\n"); }
the_stack_data/104720.c
/* * cleanprofiles.c * * Created on: Aug 16, 2020 * Author: dad * * The program takes a single (optional) calling parameter that controls which stage * of the program is executed: If missing or "both", both stages are run. If "first" * then only the first is run. If "second, only the second. * * Note: be alert if inputting a Windows file into this program on linux. * The program expects an 8-bit ascii input file. Windows may produce * wide format (16 bit) characters. I recomemnd running dos2unix on all input files. * You should also delete any blank lines at the end of the files. * * To create the initial input file (StudentGroup.txt), run the following * command on a windows domain member in an elevated cmd window: * dsget group "CN=ICA students,OU=students,OU=ICA users,DC=campus,DC=islandchristianacademy,DC=com" -members > StudentGroup.txt * * The first output file (GetSutdentSIDs.ps1) converts the list of ICA STudent group members * to a list of SIDs. I run it as a powershell script back on your domain Windows computer. * (It should work in an elevated cmd window, too.) * * Copy the SIDs file created by the GetSutdentSIDs.ps1 script back to wherever you are * running this program and re-run it. The second run will produce the final output file * (CleanStudentProfiles.ps1). Run this second powershell script on each domain computer that you * wish to clean. Be patient, it might take a while to finish cleaning; it depends on the * number of profiles on the machine, the number of files to be deleted, and the fragmentation * of the registry file. If you don't want to wait around, you can try the following: * powershell -noexit "& ""C:\users\dad\desktop\CleanStudentProfiles.ps1""" * * Note: don't forget to run * set-executionpolicy remotesigned * in powershell before attempting to run the powershell scripts! * * Note: For help depolying the cleaning script using opsi, see: * [email protected]:ICA-IT/ica-clean-profiles.git * */ //#define _GNU_SOURCE #include <stdio.h> #include <stdlib.h> #include <string.h> #ifdef WINDOZE #define WIDECHAR // set WIDECHAR for the Windows version only! // Note that the test files included in git are NOT wide! #ifdef WIDECHAR #include <wchar.h> #endif #define ssize_t int ssize_t getline(char** lineptr, size_t* n, FILE* stream) { if ( fgets(*lineptr, (int)n, stream) == NULL ) return(-1); return strlen( *lineptr); } ssize_t getlinew(char** lineptr, size_t* n, FILE* stream) { wchar_t *linew; char* line; linew = (wchar_t*)malloc((*n) * 2); line = *lineptr; if (fgetws(linew, (int)n, stream) == NULL) return(-1); for (int i = 0; i < (int)wcslen(linew); ++i) { *line = wctob(linew[i]); line++; } free(linew); *line = '\000'; return strlen(*lineptr); } #endif void trimleadingandTrailing(char *s); int main(int argc, char* argv[]) { FILE *fp; FILE *fp2; char * line = NULL; size_t len = 250; ssize_t read; size_t size = 255; char * redir; char redir1[] = ">"; char redir2[] = ">>"; int first = 0; int second = 0; if (argc > 1) { if ((strcmp(argv[1], "both") == 0) | (strcmp(argv[1], "first") == 0)) first = 1; if ((strcmp(argv[1], "both") == 0) | (strcmp(argv[1], "second") == 0)) second = 1; } else { first = 1; second = 1; } if ( (first == 0) & (second == 0) ) { printf("\nProgram to generate Windows domain profile cleaning script:\n"); printf("Calling parameters:\n"); printf("cleanprofiles [first|second|both]\n\n"); printf("The program processes in two stages. The first produces a script to list SIDs.\n"); printf("The second produces a script to clean profiles.\n"); printf("The calling parameter controls which stage of the program is executed :\n"); printf("If missing or \"both\", both stages are run.\n"); printf("If \"first\", then only the first is run.\n"); printf("If \"second\", only the second.\n\n"); printf("First stage input file = StudentGroup.txt\n"); printf("First stage output file = GetSutdentSIDs.ps1\n"); printf("Second stage input file = studentSIDs.txt\n"); printf("Second stage output file = CleanStudentProfiles.ps1\n\n"); } redir = redir1; line = (char*)malloc(size); if (first) { fp = fopen("StudentGroup.txt", "r"); if (fp == NULL)return(1); fp2 = fopen("GetSutdentSIDs.ps1", "w"); if (fp2 == NULL)return(2); while ((read = getline(&line, &len, fp)) != -1) { // printf("Retrieved line of length %zu:\n", read); line[read - 1] = '\000'; printf(" line found : \"%s\"\n", line); if ( strlen(line) > 2 ) fprintf(fp2, "dsquery * %s -scope base -attr objectSid %s studentSIDs.txt\n", line, redir); redir = redir2; } fclose(fp); fclose(fp2); } if (second) { #ifdef WIDECHAR fp = fopen("studentSIDs.txt", "r,ccs=UTF-16LE"); #else fp = fopen("studentSIDs.txt", "r"); #endif if (fp == NULL)return(3); fp2 = fopen("CleanStudentProfiles.ps1", "w"); if (fp2 == NULL)return(4); #ifdef WIDECHAR while ((read = getlinew(&line, &len, fp)) != -1) { #else while ((read = getline(&line, &len, fp)) != -1) { #endif // printf("Retrieved line of length %zu:\n", read); if (read < 7) continue; // skip any BOM line[read - 1] = '\000'; trimleadingandTrailing(line); printf(" line found : \"%s\"\n", line); if (strcmp(line, "objectSid") != 0) return(5); #ifdef WIDECHAR if ((read = getlinew(&line, &len, fp)) == -1) return (6); #else if ((read = getline(&line, &len, fp)) == -1) return (6); #endif line[read - 1] = '\000'; trimleadingandTrailing(line); printf(" line found : \"%s\"\n", line); if (strlen(line) > 20) fprintf(fp2, "Get-CimInstance -Class Win32_UserProfile | Where-Object { $_.SID -eq \'%s\' } | Remove-CimInstance\n", line); } fclose(fp); fclose(fp2); } if (line)free(line); return (0); } void trimleadingandTrailing(char *s) { int i,j; for(i=0;s[i]==' '||s[i]=='\t';i++); for(j=0;s[i];i++) { s[j++]=s[i]; } s[j]='\0'; for(i=0;s[i]!='\0';i++) { if(s[i]!=' '&& s[i]!='\t') j=i; } s[j+1]='\0'; }