file
stringlengths 18
26
| data
stringlengths 3
1.04M
|
---|---|
the_stack_data/1034521.c | #include <stdio.h>
int main()
{
printf("Data abort example\n");
volatile int *p;
p =(int*)0x10000;
*p +=1;
return 0;
}
|
the_stack_data/143685.c | #include <stdio.h>
//This tests mod/ref behavior of extern var-arg functions
//We *should* special-case those we know about...
//..but for now we don't:
//XFAIL: *
//--build the code into a .bc
//RUN: clang -c -O0 %s -S -emit-llvm -o - | llvm-as > %t.bc
//--check if ds-aa breaks, or breaks opts
//RUN: dsaopt %t.bc -ds-aa -O3 -o /dev/null
//--check properties of this particular test
//RUN: dsaopt %t.bc -ds-aa -aa-eval -o /dev/null \
// RUN: -print-all-alias-modref-info >& %t.aa
//Unknown external function
//Everything going into this should be assumed to be mod/ref'd
extern void unknown_extern(int, ...);
int main()
{
int stack_val1 = 5;
int stack_val2 = 10;
int stack_val3 = 15;
int stack_val4 = 20;
int stack_val5 = 25;
int stack_val6 = 30;
//We should special case this--offhand, modref might be best
//RUN: cat %t.aa | grep {Ptr:.*stack_val1.*scanf} | grep {^\[ \]*ModRef}
//RUN: cat %t.aa | grep {Ptr:.*stack_val2.*scanf} | grep {^\[ \]*ModRef}
scanf("%d, %d\n", &stack_val1, stack_val2);
//We should special case this--ref's vars, not mod
//RUN: cat %t.aa | grep {Ptr:.*stack_val3.*printf} | grep {^\[ \]*Ref}
//RUN: cat %t.aa | grep {Ptr:.*stack_val4.*printf} | grep {^\[ \]*Ref}
printf("%d, %d\n", &stack_val3, &stack_val4);
//unknown--this these should be marked modref
//RUN: cat %t.aa | grep {Ptr:.*stack_val5.*unknown_extern} | grep {^\[ \]*ModRef}
//RUN: cat %t.aa | grep {Ptr:.*stack_val6.*unknown_extern} | grep {^\[ \]*ModRef}
unknown_extern( 0, &stack_val5, &stack_val6);
return 0;
}
|
the_stack_data/11074139.c | #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
int comb( int* arr, int n )
{
int swap_count = 0;// количество перестановок
double fakt = 1.2473309; // фактор уменьшения
int step = n - 1;
int i = 0, j = 0, temp = 0;
while ( step >= 1 )
{
for ( i = 0; i + step < n; i++ )
{
if ( arr[i] > arr[i + step] )
{
temp = arr[i];
arr[i] = arr[i + step];
arr[i + step] = temp;
swap_count++;
}
}
step /= fakt;
}
// сортировка пузырьком
for ( i = 0; i < n - 1; i++ )
{
bool swapped = false;
for ( j = 0; j < n - i - 1; j++ )
{
if ( arr[j] > arr[j + 1] )
{
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
swapped = true;
swap_count++;
}
}
if ( !swapped ) break;
}
return swap_count;
}
int main()
{
int n = 0;
scanf( "%d", &n );
int arr[n];
int i;
for( i = 0; i < n; i++ )
{
scanf( "%d", &arr[i] );
}
comb( arr, n );
for( i = 0; i < n; i++ )
{
printf( "%d ", arr[i] );
}
printf( "\n" );
return 0;
}
|
the_stack_data/151706931.c | #include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <signal.h>
#include <fcntl.h>
#include <wait.h>
#define MAXLINE 80
#define MAXBUFF 30000
#define MAXCLIENT 1
#define MAXQUEUE 20
typedef struct filedescripter{
int bible;
int index;
char * bibleNm;
struct filedescripter * next;
}FDs;
//전역변수
FDs * fd_index;
int num_of_word;
char *findwords[10];
int word_check_array[10];
int fd_bible;
int count;
int q[MAXQUEUE];
int front;
int rear;
//프로토타입
int connFunction(int connfd,char * input);
int wordfinder(int connfd, int mod);
int my_fgets(int fd, char *buf);
int get_word_buffer(char *src, char *dst, char dis, int offset);
int get_word(int fd,char *buf, char dis);
int append(char *src, char *dest, int bound);
char* strlwr(char * src);
char* cuttxt(char *bible);
void handler() {
pid_t pid;
int stat;
while ((pid = waitpid(-1, &stat,WNOHANG)) > 0);
count--;
return;
}
int main (int argc, char *argv[]) {
int i;
char tmp_buf[100]={0,};
FDs *cur=fd_index;
char bibleFileNm[]="./bible.txt";
//bible.txt를 읽고 index 파일들을 fd 링크드 리스트로 저장하는 루틴
fd_bible=open(bibleFileNm,O_RDONLY);
while(my_fgets(fd_bible,tmp_buf)){
FDs *new;
for(i=0;;i++){
if(tmp_buf[i]==' '){
tmp_buf[i]=0;
break;
}
}
new=(FDs*)malloc(sizeof(FDs));
new->next=NULL;
new->bible=open(tmp_buf,O_RDONLY);
new->index=open(&tmp_buf[i+1],O_RDONLY);
new->bibleNm=cuttxt(tmp_buf);
new->bibleNm=strlwr(new->bibleNm);
if(fd_index==NULL){
fd_index=new;
cur=fd_index;
}
else{
cur->next=new;
cur=cur->next;
}
}
int n, listenfd, connfd;
socklen_t caddrlen;
struct hostent *h;
struct sockaddr_in saddr, caddr;
char buf[MAXLINE];
int port = atoi(argv[1]);
if(argc<2){
printf("need more argument!\n");
exit(0);
}
if ((listenfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
printf("socket() failed.\n");
exit(1);
}
bzero((char *)&saddr, sizeof(saddr));
saddr.sin_family = AF_INET;
saddr.sin_addr.s_addr = htonl(INADDR_ANY);
saddr.sin_port = htons(port);
if (bind(listenfd, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) {
printf("bind() failed.\n");
exit(2);
}
if (listen(listenfd, 5) < 0) {
printf("listen() failed.\n");
exit(3);
}
pid_t pid[10]={0,};
signal(SIGCHLD, handler);
while (1) {
/*int wating=count-MAXCLIENT;
if(wating>0){
pid[count]=fork();
if(pid[count]==0){
printf("%d is front, %d is rear\n",front,rear);
while ((n = read(connfd, buf, MAXLINE)) > 0) {
buf[n]=0;
connFunction(connfd,buf);
bzero((char *)buf, sizeof(buf));
n=write(connfd,"\n\n\n",3);
if(n==0)
printf("write() failed\n");
//write(connfd, buf, n);
}
printf("connection terminated.\n");
close(connfd);
exit(0);
}
else{
count++;
printf("%d is count\n",count);
}
printf("wating list is not empty!, %d is waiting, %d is running\n", wating, count);
}
else{*/
caddrlen = sizeof(caddr);
if ((connfd = accept(listenfd, (struct sockaddr *)&caddr, &caddrlen)) < 0) {
printf ("accept() failed.\n");
continue;
}
q[rear++]=connfd;
if(rear>=MAXQUEUE)
rear=0;
printf("%d is front, %d is rear\n",front,rear);
h = gethostbyaddr((const char *)&caddr.sin_addr.s_addr,sizeof(caddr.sin_addr.s_addr), AF_INET);
printf("server connected to %s (%s)\n", h->h_name, inet_ntoa(*(struct in_addr *)&caddr.sin_addr));
connfd=q[front++];
if(front>=MAXQUEUE)
front=0;
pid[count]=fork();
if(pid[count]==0){
printf("%d is front, %d is rear\n",front,rear);
while ((n = read(connfd, buf, MAXLINE)) > 0) {
buf[n]=0;
connFunction(connfd,buf);
bzero((char *)buf, sizeof(buf));
n=write(connfd,"\n\n\n",3);
if(n==0)
printf("write() failed\n");
//write(connfd, buf, n);
}
printf("connection terminated.\n");
close(connfd);
exit(0);
}
else{
count++;
printf("%d is count\n",count);
}
//}
}
close(connfd);
}
int connFunction(int connfd, char *input){
int i;
char tmp_buf[100]={0,};
int mod=0;
//"으로 시작할때
if(input[0]==34){
mod=1;
int sum=0;
for(i=0;;i++){
int test;
test=get_word_buffer(input+1,tmp_buf,' ', sum);
sum=sum+test+1;
if(!strcmp(tmp_buf,"*")){
mod++;
i--;
continue;
}
int len=strlen(tmp_buf);
findwords[i]=(char*)malloc(sizeof(char)*len);
strcpy(findwords[i],tmp_buf);
if(test==-1) break;
}
num_of_word=i+1;
int l=strlen(findwords[i]);
findwords[i][l-1]=0;
wordfinder(connfd, mod);
}
//단일 단어 여러개일때
else{
int sum=0;
for(i=0;;i++){
int test;
test=get_word_buffer(input,tmp_buf,' ', sum);
int len=strlen(tmp_buf);
findwords[i]=(char*)malloc(sizeof(char)*len);
strcpy(findwords[i],tmp_buf);
sum=sum+test+1;
if(test==-1) break;
}
num_of_word=i+1;
wordfinder(connfd, mod);
}
for(i=0;i<10;i++){
if(findwords[i]==0) break;
free(findwords[i]);
}
return 1;
}
/*int connFunction(int connfd,char *input){
int l=strlen(input);
if(!write(connfd,input,l)){
printf("server write failed\n");
}
return 0;
}*/
int wordfinder(int connfd, int mod){
int i,j;
char tmp_buf[MAXBUFF]={0,};
char print_buffer[MAXBUFF]={0};
char tmp_print_buffer[MAXBUFF/2]={0,};
FDs *cur=fd_index;
int _flag=0, print_flag=0;
int b_flag=0;
while(cur){
lseek(cur->bible,0,SEEK_SET);
for(i=0;;i++){
if(!my_fgets(cur->bible,tmp_buf)){
break;
}
if(i==0) continue;
else{
int offset=0;
char word[100]={0,};
char *tmp_word;
int m2_flag=0;
append(print_buffer,cur->bibleNm,MAXBUFF);
append(print_buffer,":",MAXBUFF);
while(1){
int test=0;
test=get_word_buffer(tmp_buf,word,' ', offset);
if(test==-1) b_flag=1;
offset=offset+test+1;
tmp_word=strlwr(word);
if(mod==0){
// 분리된 단어 여러개 찾기
for(j=0;j<num_of_word;j++){
if(!strcmp(findwords[j],tmp_word)){
//일치할 때
_flag=1;
print_flag=1;
word_check_array[j]++;
}
}
if(_flag==1){
append(print_buffer, "[", MAXBUFF);
append(print_buffer,word,MAXBUFF);
append(print_buffer,"] ",MAXBUFF);
_flag=0;
}
else{
append(print_buffer,word,MAXBUFF);
append(print_buffer," ",MAXBUFF);
}
}
else if(mod==1){
//여러 단어가 이어진 구절 찾기
if(!strcmp(findwords[0],tmp_word)){
char t[100]={0,};
get_word_buffer(tmp_buf,t,' ', offset);
tmp_word=strlwr(word);
if(!strcmp(t, findwords[1])){
append(print_buffer,"[",MAXBUFF);
append(print_buffer,word,MAXBUFF);
append(print_buffer," ",MAXBUFF);
append(print_buffer,t,MAXBUFF);
append(print_buffer,"] ",MAXBUFF);
print_flag=1;
}
else{
append(print_buffer,word,MAXBUFF);
append(print_buffer," ",MAXBUFF);
}
}
else{
append(print_buffer,word,MAXBUFF);
append(print_buffer," ",MAXBUFF);
}
}
else if(mod==2){
// god * create
if(m2_flag==0){
if(!strcmp(findwords[0],tmp_word)){
append(print_buffer,"[",MAXBUFF);
append(print_buffer,word,MAXBUFF);
append(print_buffer," ",MAXBUFF);
if(test==-1) b_flag=1;
m2_flag=1;
}
else{
append(print_buffer,word,MAXBUFF);
append(print_buffer," ",MAXBUFF);
}
}
else if(m2_flag==1){
if(!strcmp(findwords[1],tmp_word)){
printf("m2 flag is 1!\n");
strcpy(tmp_print_buffer,print_buffer);
printf("%s\n",tmp_print_buffer);
append(print_buffer,word,MAXBUFF);
append(print_buffer,"] ",MAXBUFF);
if(test==-1) b_flag=1;
print_flag=1;
m2_flag=2;
}
else{
append(print_buffer,word,MAXBUFF);
append(print_buffer," ",MAXBUFF);
}
}
else if(m2_flag==2){
if(!strcmp(findwords[1],tmp_word)){
printf("m2 flag is 2!\n");
strcpy(print_buffer,tmp_print_buffer);
strcpy(tmp_print_buffer,print_buffer);
append(print_buffer,word,MAXBUFF);
append(print_buffer,"] ",MAXBUFF);
if(test==-1) b_flag=1;
}
else{
append(print_buffer,word,MAXBUFF);
append(print_buffer," ",MAXBUFF);
}
append(tmp_print_buffer,word,MAXBUFF);
append(tmp_print_buffer," ",MAXBUFF);
}
}
if(b_flag==1){
b_flag=0;
break;
}
}
}
if(mod==0){
for(int k=0;k<num_of_word;k++){
if(word_check_array[k]==0){
print_flag=0;
}
}
}
if(print_flag==1){
append(print_buffer,"\n",MAXBUFF);
if(!write(connfd,print_buffer,strlen(print_buffer))){
printf("server write failed\n");
}
print_flag=0;
}
bzero((char*)print_buffer,strlen(print_buffer));
bzero((char*)tmp_print_buffer,strlen(tmp_print_buffer));
for(int z=0;z<num_of_word;z++){
word_check_array[z]=0;
}
}
cur=cur->next;
_flag=0;
}
return 0;
}
int my_fgets(int fd, char *buf){
char tmp=0;
bzero((char *)buf, strlen(buf));
for(int i=0;;i++){
int test=read(fd,&tmp,1);
if(test==0){
buf[i]=0;
return 0;
}
else if(tmp=='\n'){
buf[i]=0;
return 1;
}
else{
buf[i]=tmp;
}
}
return 2;
}
int get_word_buffer(char *src, char *dst, char dis, int offset){
char tmp=0;
bzero((char *)dst, strlen(dst));
for(int i=0;;i++){
tmp = src[i+offset];
if(tmp==dis){
dst[i]=0;
return i;
}
else if(tmp==0 || tmp=='\n') return -1;
else{
dst[i]=src[i+offset];
}
}
return 0;
}
int get_word(int fd,char *buf, char dis){
char tmp=0;
bzero((char *)buf, strlen(buf));
for(int i=0;;i++){
int test=read(fd,&tmp,1);
if(test==0){
return 0;
}
if(tmp==dis){
buf[i]=0;
return 1;
}
else{
buf[i]=tmp;
}
}
return -1;
}
int append(char *src, char* dest, int bound){
int l1=strlen(src);
int l2=strlen(dest);
int i;
for(i=l1;i<l1+l2;i++){
if(i>bound) return -1;
src[i]=dest[i-l1];
}
return 1;
}
char* strlwr(char * src){
char * dst;
int l = strlen(src);
dst=(char*)malloc(sizeof(char)*l);
bzero((char*)dst, strlen(dst));
for(int i=0;i<l;i++){
if(src[i]>='A' && src[i]<='Z'){
dst[i]=src[i]-'A'+'a';
}
else if(src[i]==',' || src[i]=='.'|| src[i]==';'){
dst[i]=0;
return dst;
}
else
dst[i]=src[i];
}
return dst;
}
char* cuttxt(char *bible){
int i;
char * bibleNm=(char*)malloc(sizeof(char)*(strlen(bible)-4));
for(i=0;;i++){
if(bible[i]=='.'){
bibleNm[i]=0;
return bibleNm;
}
else
bibleNm[i]=bible[i];
}
return NULL;
} |
the_stack_data/783073.c | #include <stdio.h>
#include <stdlib.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
int main(int argc, char *argv[]) {
int fds, fdd;
int flag, ctr=0;
char buff;
if (argc == 0) {
printf("specificare gli argomenti in input\n");
exit(1);
}
fds = open(argv[1], O_RDONLY);
lseek(fds, 1, SEEK_END); /*Si posiziona alla fine del file*/
fdd = open("reverse.txt", O_CREAT | O_WRONLY, 0600);
lseek(fdd,0,SEEK_SET); /*Si posiziona all'inizio del file*/
while (1) /*legge il file al contrario: ad ogni passo sposta il puntatore di due passi indietro, perché la lettura lo aggiorna */
{
flag = lseek(fds, -2*sizeof(char), SEEK_CUR); // si posiziona -2*sizeof(char) poichè legge un char e si posiziona al byte prima del char letto
if(flag != -1){
read(fds, &buff, sizeof(char));
write(fdd, &buff, sizeof(char));
}
else{
return 1;
}
printf("%c",buff);
}
return 0;
}
|
the_stack_data/15763456.c | #include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <getopt.h>
#include <sys/time.h>
#define MINUTE (60)
#define HOUR (60 * MINUTE)
#define DAY (24 * HOUR)
void print_seconds(int seconds) {
if (seconds > DAY) {
int days = seconds / DAY;
seconds -= DAY * days;
printf("%d day%s,", days, days != 1 ? "s" : "");
}
if (seconds > HOUR) {
int hours = seconds / HOUR;
seconds -= HOUR * hours;
int minutes = seconds / MINUTE;
printf("%2d:%02d", hours, minutes);
return;
} else if (seconds > MINUTE) {
int minutes = seconds / MINUTE;
printf("%d minute%s,", minutes, minutes != 1 ? "s" : "");
seconds -= MINUTE * minutes;
}
printf("%2d second%s", seconds, seconds != 1 ? "s" : "");
}
void print_uptime(void) {
FILE * f = fopen("/proc/uptime", "r");
if (!f) return;
int seconds, subseconds;
fscanf(f, "%d.%2d", &seconds, &subseconds);
printf("up ");
print_seconds(seconds);
printf("\n");
}
int main(int argc, char * argv[]) {
print_uptime();
return 0;
}
|
the_stack_data/856659.c | /*
The MIT License (MIT)
Copyright (c) 2016-2017 Himanshu Goel
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
int main() {
return 1;
} |
the_stack_data/93078.c | int func10()
{
return 1;
}
|
the_stack_data/987560.c | /*
*****************************************************************************
* @file scope.c
* @author Y3288231
* @date Dec 15, 2014
* @brief This file contains oscilloscope functions
*****************************************************************************
*/
// Includes ===================================================================
#ifdef USE_GEN
#include "cmsis_os.h"
#include "mcu_config.h"
#include "comms.h"
#include "generator.h"
#include "dac.h"
#include "tim.h"
// External variables definitions =============================================
xQueueHandle generatorMessageQueue;
uint8_t validateGenBuffUsage(void);
void clearGenBuffer(void);
static volatile generatorTypeDef generator;
uint16_t blindValue=0;
uint16_t generatorBuffer[MAX_GENERATOR_BUFF_SIZE/2];
// Function definitions =======================================================
/**
* @brief Oscilloscope task function.
* task is getting messages from other tasks and takes care about oscilloscope functions
* @param Task handler, parameters pointer
* @retval None
*/
//portTASK_FUNCTION(vScopeTask, pvParameters){
void GeneratorTask(void const *argument){
generatorMessageQueue = xQueueCreate(5, 20);
generatorSetDefault();
char message[20];
while(1){
xQueueReceive(generatorMessageQueue, message, portMAX_DELAY);
if(message[0]=='1'){
}else if(message[0]=='2'){
}else if(message[0]=='3'){ //invalidate
if(generator.state==GENERATOR_IDLE){
}
}else if(message[0]=='4'){ //start
if(generator.state==GENERATOR_IDLE){
genInit();
GeneratingEnable();
generator.state=GENERATOR_RUN;
}
}else if(message[0]=='5'){ //stop
if(generator.state==GENERATOR_RUN){
GeneratingDisable();
generator.state=GENERATOR_IDLE;
}
}
}
}
/**
* @brief Oscilloscope set Default values
* @param None
* @retval None
*/
void generatorSetDefault(void){
generator.bufferMemory=generatorBuffer;
for(uint8_t i = 0;i<MAX_DAC_CHANNELS;i++){
generator.generatingFrequency[i]=DEFAULT_GENERATING_FREQ;
generator.realGenFrequency[i]=DEFAULT_GENERATING_FREQ;
}
generator.numOfChannles=1;
generator.maxOneChanSamples=MAX_GENERATOR_BUFF_SIZE/2;
generator.oneChanSamples[0]=MAX_GENERATOR_BUFF_SIZE/2;
generator.pChanMem[0]=generatorBuffer;
generator.state=GENERATOR_IDLE;
generator.DAC_res=DAC_DATA_DEPTH;
}
void genInit(void){
for(uint8_t i = 0;i<MAX_DAC_CHANNELS;i++){
TIM_Reconfig_gen(generator.generatingFrequency[i],i,0);
if(generator.numOfChannles>i){
DAC_DMA_Reconfig(i,(uint32_t *)generator.pChanMem[i], generator.oneChanSamples[i]);
}else{
DAC_DMA_Reconfig(i,(uint32_t *)&blindValue, 1);
}
}
}
uint8_t genSetData(uint16_t index,uint8_t length,uint8_t chan){
uint8_t result = GEN_INVALID_STATE;
if(generator.state==GENERATOR_IDLE ){
if ((index*2+length)/2<=generator.oneChanSamples[chan-1] && generator.numOfChannles>=chan){
if(commBufferReadNBytes((uint8_t *)generator.pChanMem[chan-1]+index*2,length)==length && commBufferReadByte(&result)==0 && result==';'){
result = 0;
xQueueSendToBack(generatorMessageQueue, "3Invalidate", portMAX_DELAY);
}else{
result = GEN_INVALID_DATA;
}
}else{
result = GEN_OUT_OF_MEMORY;
}
}
return result;
}
uint8_t genSetFrequency(uint32_t freq,uint8_t chan){
uint8_t result = GEN_TO_HIGH_FREQ;
uint32_t realFreq;
if(freq<=MAX_GENERATING_FREQ){
generator.generatingFrequency[chan-1] = freq;
result = TIM_Reconfig_gen(generator.generatingFrequency[chan-1],chan-1,&realFreq);
generator.realGenFrequency[chan-1] = realFreq;
}
return result;
}
void genSendRealSamplingFreq(void){
xQueueSendToBack(messageQueue, "2SendGenFreq", portMAX_DELAY);
}
void genDataOKSendNext(void){
xQueueSendToBack(messageQueue, "7GenNext", portMAX_DELAY);
}
void genStatusOK(void){
xQueueSendToBack(messageQueue, "8GenOK", portMAX_DELAY);
}
uint32_t genGetRealSmplFreq(uint8_t chan){
return generator.realGenFrequency[chan-1];
}
uint8_t genSetLength(uint32_t length,uint8_t chan){
uint8_t result=GEN_INVALID_STATE;
if(generator.state==GENERATOR_IDLE){
uint32_t smpTmp=generator.maxOneChanSamples;
if(length<=generator.maxOneChanSamples){
generator.oneChanSamples[chan-1]=length;
clearGenBuffer();
result=0;
}else{
result = GEN_BUFFER_SIZE_ERR;
}
xQueueSendToBack(generatorMessageQueue, "3Invalidate", portMAX_DELAY);
}
return result;
}
uint8_t genSetNumOfChannels(uint8_t chan){
uint8_t result=GEN_INVALID_STATE;
uint8_t chanTmp=generator.numOfChannles;
if(generator.state==GENERATOR_IDLE){
if(chan<=MAX_DAC_CHANNELS){
generator.numOfChannles=chan;
generator.maxOneChanSamples=MAX_GENERATOR_BUFF_SIZE/2/chan;
for(uint8_t i=0;i<chan;i++){
generator.pChanMem[i]=(uint16_t *)&generatorBuffer[i*generator.maxOneChanSamples];
}
result=0;
xQueueSendToBack(generatorMessageQueue, "3Invalidate", portMAX_DELAY);
}
}
return result;
}
/**
* @brief Checks if scope settings doesn't exceed memory
* @param None
* @retval err/ok
*/
uint8_t validateGenBuffUsage(){
uint8_t result=1;
uint32_t data_len=generator.maxOneChanSamples;
if(generator.DAC_res>8){
data_len=data_len*2;
}
data_len=data_len*generator.numOfChannles;
if(data_len<=MAX_GENERATOR_BUFF_SIZE){
result=0;
}
return result;
}
/**
* @brief Clears generator buffer
* @param None
* @retval None
*/
void clearGenBuffer(void){
for(uint32_t i=0;i<MAX_GENERATOR_BUFF_SIZE/2;i++){
generatorBuffer[i]=0;
}
}
void genSetOutputBuffer(void){
DACSetOutputBuffer();
}
void genUnsetOutputBuffer(void){
DACUnsetOutputBuffer();
}
/**
* @brief Start scope sampling
* @param None
* @retval None
*/
void genStart(void){
xQueueSendToBack(generatorMessageQueue, "4Start", portMAX_DELAY);
}
/**
* @brief Stop scope sampling
* @param None
* @retval None
*/
void genStop(void){
xQueueSendToBack(generatorMessageQueue, "5Stop", portMAX_DELAY);
}
#endif //USE_GEN
|
the_stack_data/412118.c | #include <stdio.h>
#include <string.h>
typedef struct _Data {
int id;
float temp;
} Data;
int saveFile(char* file) {
Data datas[] = {
{1, 100.0f},{2, 777.7f},{3, 200.3f}
};
FILE *out;
if ((out = fopen(file, "w")) == NULL) {
perror(file);
return -1;
}
for (int i = 0; i < 3; i++) {
fwrite(&datas[i], sizeof(Data), 1, out);
}
fclose(out);
return 0;
}
int readFile(char* file) {
FILE *in;
int n = 0;
if ((in = fopen(file, "r")) == NULL) {
perror(file);
return -1;
}
Data data;
memset(&data, sizeof(data), 0x00);
while ((n = fread(&data, sizeof(data), 1, in)) > 0) {
printf("%d : %0.1f\n", data.id, data.temp);
memset(&data, sizeof(data), 0x00);
}
}
int main(int argc, char **argv)
{
if (argc != 2) {
fprintf(stderr, "Usage: fcopy file1 file2\n");
return -1;
}
if (saveFile(argv[1]) < 0) {
fprintf(stderr, "writing failed\n");
return -1;
}
if (readFile(argv[1]) < 0) {
fprintf(stderr, "reading failed\n");
return -1;
}
return 0;
}
|
the_stack_data/12636548.c | #include <stdio.h>
int main() {
int a, b, x;
scanf("%d %d", &a, &b);
x = a + b;
printf("X = %d\n", x);
return 0;
} |
the_stack_data/156394272.c | /* Copyright (C) 2014 InfiniDB, 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; version 2 of
the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. */
// $Id$
#include <stdlib.h>
#include "unistd.h"
#if _MSC_VER < 1800
long long atoll(const char* nptr)
{
return strtoll(nptr, 0, 0);
}
#endif
|
the_stack_data/674784.c | #include<stdio.h>
int main() {
unsigned int num = 8;
printf("\nInitial:\n");
printf(" num = %x\n", num);
printf("\nLeft shift by 2:\n");
num = num << 2;
printf(" num = %x\n", num);
printf("\nRight shift by 4:\n");
num = num >> 4;
printf(" num = %x\n", num);
printf("\nLeft shift by 2:\n");
num = num << 2;
printf(" num = %x\n", num);
printf("\nBitwise operators:\n");
printf("num & 1 = %x\n", num & 1); /* Logical AND */
printf("num | 1 = %x\n", num | 1); /* Logical OR */
printf("num ^ 1 = %x\n", num ^ 1); /* Logical XOR */
printf("\n");
printf("num & 9 = %x\n", num & 9); /* Logical AND */
printf("num | 9 = %x\n", num | 9); /* Logical OR */
printf("num ^ 9 = %x\n", num ^ 9); /* Logical XOR */
return(0);
}
|
the_stack_data/940760.c | /*
* Copyright 2016-2019 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#if defined(_WIN32)
# include <windows.h>
#endif
#include <openssl/crypto.h>
#if defined(OPENSSL_THREADS) && !defined(CRYPTO_TDEBUG) && defined(OPENSSL_SYS_WINDOWS)
CRYPTO_RWLOCK *CRYPTO_THREAD_lock_new(void)
{
CRYPTO_RWLOCK *lock;
if ((lock = OPENSSL_zalloc(sizeof(CRITICAL_SECTION))) == NULL) {
/* Don't set error, to avoid recursion blowup. */
return NULL;
}
#if !defined(_WIN32_WCE)
/* 0x400 is the spin count value suggested in the documentation */
if (!InitializeCriticalSectionAndSpinCount(lock, 0x400)) {
OPENSSL_free(lock);
return NULL;
}
#else
InitializeCriticalSection(lock);
#endif
return lock;
}
int CRYPTO_THREAD_read_lock(CRYPTO_RWLOCK *lock)
{
EnterCriticalSection(lock);
return 1;
}
int CRYPTO_THREAD_write_lock(CRYPTO_RWLOCK *lock)
{
EnterCriticalSection(lock);
return 1;
}
int CRYPTO_THREAD_unlock(CRYPTO_RWLOCK *lock)
{
LeaveCriticalSection(lock);
return 1;
}
void CRYPTO_THREAD_lock_free(CRYPTO_RWLOCK *lock)
{
if (lock == NULL)
return;
DeleteCriticalSection(lock);
OPENSSL_free(lock);
return;
}
# define ONCE_UNINITED 0
# define ONCE_ININIT 1
# define ONCE_DONE 2
/*
* We don't use InitOnceExecuteOnce because that isn't available in WinXP which
* we still have to support.
*/
int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))
{
LONG volatile *lock = (LONG *)once;
LONG result;
if (*lock == ONCE_DONE)
return 1;
do {
result = InterlockedCompareExchange(lock, ONCE_ININIT, ONCE_UNINITED);
if (result == ONCE_UNINITED) {
init();
*lock = ONCE_DONE;
return 1;
}
} while (result == ONCE_ININIT);
return (*lock == ONCE_DONE);
}
int CRYPTO_THREAD_init_local(CRYPTO_THREAD_LOCAL *key, void (*cleanup)(void *))
{
*key = TlsAlloc();
if (*key == TLS_OUT_OF_INDEXES)
return 0;
return 1;
}
void *CRYPTO_THREAD_get_local(CRYPTO_THREAD_LOCAL *key)
{
DWORD last_error;
void *ret;
/*
* TlsGetValue clears the last error even on success, so that callers may
* distinguish it successfully returning NULL or failing. It is documented
* to never fail if the argument is a valid index from TlsAlloc, so we do
* not need to handle this.
*
* However, this error-mangling behavior interferes with the caller's use of
* GetLastError. In particular SSL_get_error queries the error queue to
* determine whether the caller should look at the OS's errors. To avoid
* destroying state, save and restore the Windows error.
*
* https://msdn.microsoft.com/en-us/library/windows/desktop/ms686812(v=vs.85).aspx
*/
last_error = GetLastError();
ret = TlsGetValue(*key);
SetLastError(last_error);
return ret;
}
int CRYPTO_THREAD_set_local(CRYPTO_THREAD_LOCAL *key, void *val)
{
if (TlsSetValue(*key, val) == 0)
return 0;
return 1;
}
int CRYPTO_THREAD_cleanup_local(CRYPTO_THREAD_LOCAL *key)
{
if (TlsFree(*key) == 0)
return 0;
return 1;
}
CRYPTO_THREAD_ID CRYPTO_THREAD_get_current_id(void)
{
return GetCurrentThreadId();
}
int CRYPTO_THREAD_compare_id(CRYPTO_THREAD_ID a, CRYPTO_THREAD_ID b)
{
return (a == b);
}
int CRYPTO_atomic_add(int *val, int amount, int *ret, CRYPTO_RWLOCK *lock)
{
*ret = InterlockedExchangeAdd(val, amount) + amount;
return 1;
}
int openssl_init_fork_handlers(void)
{
return 0;
}
#endif
|
the_stack_data/54278.c | /*
============================================================================
Author : Ztiany
Description : 可变参数
============================================================================
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
void fun(int a, ...) {
printf("%d %d \n", a, &a);
int *temp = &a;
temp++;
for (int i = 0; i < a; ++i) {
printf("%d %d \n", *temp, temp);
temp++;
}
}
/*ANSI标准形式的声明方式,括号内的省略号表示可选参数
获取可变参数:
typedef char* va_list;
void va_start ( va_list ap, prev_param );
type va_arg ( va_list ap, type );
void va_end ( va_list ap );
va_list 是一个字符指针,可以理解为指向当前参数的一个指针,取参必须通过这个指针进行。
step 1:在调用参数表之前,定义一个 va_list 类型的变量,(假设va_list 类型变量被定义为ap);
step 2:然后应该对ap 进行初始化,让它指向可变参数表里面的第一个参数,这是通过 va_start 来实现的,第一个参数是 ap 本身,第二个参数是在变参表前面紧挨着的一个变量,即“...”之前的那个参数;
step 3:然后是获取参数,调用va_arg,它的第一个参数是ap,第二个参数是要获取的参数的指定类型,然后返回这个指定类型的值,并且把 ap 的位置指向变参表的下一个变量位置;
step 4:获取所有的参数之后,我们有必要将这个 ap 指针关掉,以免发生危险,方法是调用 va_end,他是输入的参数 ap 置为 NULL,应该养成获取完参数表之后关闭指针的习惯。说白了,就是让我们的程序具有健壮性。通常va_start和va_end是成对出
*/
int demo(char *msg, ...) {
va_list argp;
int argno = 0;
char *para;
va_start(argp, msg);
while (1) {
para = va_arg(argp, char*);
if (strcmp(para, "") == 0)
break;
printf("parameter #%d is : %s\n", argno, para);
argno++;
}
va_end(argp);
return 0;
}
/* 参考:http://www.cnblogs.com/hanyonglu/archive/2011/05/07/2039916.html */
int main() {
int a = 1;
int b = 2;
int c = 3;
int d = 4;
fun(4, a, b, c, d);
system("pause");
demo("DEMO", "This", "is", "a", "demo!", "");
system("pause");
return EXIT_SUCCESS;
} |
the_stack_data/112945.c | // KASAN: use-after-free Read in __list_add_valid
// https://syzkaller.appspot.com/bug?id=d4407314a3f56eef21ecde3338300bf95da2556c
// status:fixed
// autogenerated by syzkaller (http://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h>
#include <linux/capability.h>
#include <linux/if.h>
#include <linux/if_ether.h>
#include <linux/if_tun.h>
#include <linux/ip.h>
#include <linux/tcp.h>
#include <net/if_arp.h>
#include <pthread.h>
#include <sched.h>
#include <setjmp.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/mount.h>
#include <sys/prctl.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <unistd.h>
const int kFailStatus = 67;
const int kRetryStatus = 69;
__attribute__((noreturn)) static void doexit(int status)
{
volatile unsigned i;
syscall(__NR_exit_group, status);
for (i = 0;; i++) {
}
}
__attribute__((noreturn)) static void fail(const char* msg, ...)
{
int e = errno;
fflush(stdout);
va_list args;
va_start(args, msg);
vfprintf(stderr, msg, args);
va_end(args);
fprintf(stderr, " (errno %d)\n", e);
doexit((e == ENOMEM || e == EAGAIN) ? kRetryStatus : kFailStatus);
}
static __thread int skip_segv;
static __thread jmp_buf segv_env;
static void segv_handler(int sig, siginfo_t* info, void* uctx)
{
uintptr_t addr = (uintptr_t)info->si_addr;
const uintptr_t prog_start = 1 << 20;
const uintptr_t prog_end = 100 << 20;
if (__atomic_load_n(&skip_segv, __ATOMIC_RELAXED) &&
(addr < prog_start || addr > prog_end)) {
_longjmp(segv_env, 1);
}
doexit(sig);
for (;;) {
}
}
static void install_segv_handler()
{
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = SIG_IGN;
syscall(SYS_rt_sigaction, 0x20, &sa, NULL, 8);
syscall(SYS_rt_sigaction, 0x21, &sa, NULL, 8);
memset(&sa, 0, sizeof(sa));
sa.sa_sigaction = segv_handler;
sa.sa_flags = SA_NODEFER | SA_SIGINFO;
sigaction(SIGSEGV, &sa, NULL);
sigaction(SIGBUS, &sa, NULL);
}
#define NONFAILING(...) \
{ \
__atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); \
if (_setjmp(segv_env) == 0) { \
__VA_ARGS__; \
} \
__atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); \
}
static void use_temporary_dir()
{
char tmpdir_template[] = "./syzkaller.XXXXXX";
char* tmpdir = mkdtemp(tmpdir_template);
if (!tmpdir)
fail("failed to mkdtemp");
if (chmod(tmpdir, 0777))
fail("failed to chmod");
if (chdir(tmpdir))
fail("failed to chdir");
}
static void vsnprintf_check(char* str, size_t size, const char* format,
va_list args)
{
int rv;
rv = vsnprintf(str, size, format, args);
if (rv < 0)
fail("tun: snprintf failed");
if ((size_t)rv >= size)
fail("tun: string '%s...' doesn't fit into buffer", str);
}
static void snprintf_check(char* str, size_t size, const char* format,
...)
{
va_list args;
va_start(args, format);
vsnprintf_check(str, size, format, args);
va_end(args);
}
#define COMMAND_MAX_LEN 128
static void execute_command(const char* format, ...)
{
va_list args;
char command[COMMAND_MAX_LEN];
int rv;
va_start(args, format);
vsnprintf_check(command, sizeof(command), format, args);
rv = system(command);
if (rv != 0)
fail("tun: command \"%s\" failed with code %d", &command[0], rv);
va_end(args);
}
static int tunfd = -1;
#define SYZ_TUN_MAX_PACKET_SIZE 1000
#define MAX_PIDS 32
#define ADDR_MAX_LEN 32
#define LOCAL_MAC "aa:aa:aa:aa:aa:%02hx"
#define REMOTE_MAC "bb:bb:bb:bb:bb:%02hx"
#define LOCAL_IPV4 "172.20.%d.170"
#define REMOTE_IPV4 "172.20.%d.187"
#define LOCAL_IPV6 "fe80::%02hxaa"
#define REMOTE_IPV6 "fe80::%02hxbb"
static void initialize_tun(uint64_t pid)
{
if (pid >= MAX_PIDS)
fail("tun: no more than %d executors", MAX_PIDS);
int id = pid;
tunfd = open("/dev/net/tun", O_RDWR | O_NONBLOCK);
if (tunfd == -1)
fail("tun: can't open /dev/net/tun");
char iface[IFNAMSIZ];
snprintf_check(iface, sizeof(iface), "syz%d", id);
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, iface, IFNAMSIZ);
ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
if (ioctl(tunfd, TUNSETIFF, (void*)&ifr) < 0)
fail("tun: ioctl(TUNSETIFF) failed");
char local_mac[ADDR_MAX_LEN];
snprintf_check(local_mac, sizeof(local_mac), LOCAL_MAC, id);
char remote_mac[ADDR_MAX_LEN];
snprintf_check(remote_mac, sizeof(remote_mac), REMOTE_MAC, id);
char local_ipv4[ADDR_MAX_LEN];
snprintf_check(local_ipv4, sizeof(local_ipv4), LOCAL_IPV4, id);
char remote_ipv4[ADDR_MAX_LEN];
snprintf_check(remote_ipv4, sizeof(remote_ipv4), REMOTE_IPV4, id);
char local_ipv6[ADDR_MAX_LEN];
snprintf_check(local_ipv6, sizeof(local_ipv6), LOCAL_IPV6, id);
char remote_ipv6[ADDR_MAX_LEN];
snprintf_check(remote_ipv6, sizeof(remote_ipv6), REMOTE_IPV6, id);
execute_command("sysctl -w net.ipv6.conf.%s.accept_dad=0", iface);
execute_command("sysctl -w net.ipv6.conf.%s.router_solicitations=0",
iface);
execute_command("ip link set dev %s address %s", iface, local_mac);
execute_command("ip addr add %s/24 dev %s", local_ipv4, iface);
execute_command("ip -6 addr add %s/120 dev %s", local_ipv6, iface);
execute_command("ip neigh add %s lladdr %s dev %s nud permanent",
remote_ipv4, remote_mac, iface);
execute_command("ip -6 neigh add %s lladdr %s dev %s nud permanent",
remote_ipv6, remote_mac, iface);
execute_command("ip link set dev %s up", iface);
}
static void setup_tun(uint64_t pid, bool enable_tun)
{
if (enable_tun)
initialize_tun(pid);
}
static void loop();
static void sandbox_common()
{
prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
setpgrp();
setsid();
struct rlimit rlim;
rlim.rlim_cur = rlim.rlim_max = 128 << 20;
setrlimit(RLIMIT_AS, &rlim);
rlim.rlim_cur = rlim.rlim_max = 8 << 20;
setrlimit(RLIMIT_MEMLOCK, &rlim);
rlim.rlim_cur = rlim.rlim_max = 1 << 20;
setrlimit(RLIMIT_FSIZE, &rlim);
rlim.rlim_cur = rlim.rlim_max = 1 << 20;
setrlimit(RLIMIT_STACK, &rlim);
rlim.rlim_cur = rlim.rlim_max = 0;
setrlimit(RLIMIT_CORE, &rlim);
unshare(CLONE_NEWNS);
unshare(CLONE_NEWIPC);
unshare(CLONE_IO);
}
static bool write_file(const char* file, const char* what, ...)
{
char buf[1024];
va_list args;
va_start(args, what);
vsnprintf(buf, sizeof(buf), what, args);
va_end(args);
buf[sizeof(buf) - 1] = 0;
int len = strlen(buf);
int fd = open(file, O_WRONLY | O_CLOEXEC);
if (fd == -1)
return false;
if (write(fd, buf, len) != len) {
close(fd);
return false;
}
close(fd);
return true;
}
static int real_uid;
static int real_gid;
static int epid;
static bool etun;
__attribute__((aligned(64 << 10))) static char sandbox_stack[1 << 20];
static int namespace_sandbox_proc(void* arg)
{
sandbox_common();
write_file("/proc/self/setgroups", "deny");
if (!write_file("/proc/self/uid_map", "0 %d 1\n", real_uid))
fail("write of /proc/self/uid_map failed");
if (!write_file("/proc/self/gid_map", "0 %d 1\n", real_gid))
fail("write of /proc/self/gid_map failed");
setup_tun(epid, etun);
if (mkdir("./syz-tmp", 0777))
fail("mkdir(syz-tmp) failed");
if (mount("", "./syz-tmp", "tmpfs", 0, NULL))
fail("mount(tmpfs) failed");
if (mkdir("./syz-tmp/newroot", 0777))
fail("mkdir failed");
if (mkdir("./syz-tmp/newroot/dev", 0700))
fail("mkdir failed");
if (mount("/dev", "./syz-tmp/newroot/dev", NULL,
MS_BIND | MS_REC | MS_PRIVATE, NULL))
fail("mount(dev) failed");
if (mkdir("./syz-tmp/newroot/proc", 0700))
fail("mkdir failed");
if (mount(NULL, "./syz-tmp/newroot/proc", "proc", 0, NULL))
fail("mount(proc) failed");
if (mkdir("./syz-tmp/pivot", 0777))
fail("mkdir failed");
if (syscall(SYS_pivot_root, "./syz-tmp", "./syz-tmp/pivot")) {
if (chdir("./syz-tmp"))
fail("chdir failed");
} else {
if (chdir("/"))
fail("chdir failed");
if (umount2("./pivot", MNT_DETACH))
fail("umount failed");
}
if (chroot("./newroot"))
fail("chroot failed");
if (chdir("/"))
fail("chdir failed");
struct __user_cap_header_struct cap_hdr = {};
struct __user_cap_data_struct cap_data[2] = {};
cap_hdr.version = _LINUX_CAPABILITY_VERSION_3;
cap_hdr.pid = getpid();
if (syscall(SYS_capget, &cap_hdr, &cap_data))
fail("capget failed");
cap_data[0].effective &= ~(1 << CAP_SYS_PTRACE);
cap_data[0].permitted &= ~(1 << CAP_SYS_PTRACE);
cap_data[0].inheritable &= ~(1 << CAP_SYS_PTRACE);
if (syscall(SYS_capset, &cap_hdr, &cap_data))
fail("capset failed");
loop();
doexit(1);
}
static int do_sandbox_namespace(int executor_pid, bool enable_tun)
{
real_uid = getuid();
real_gid = getgid();
epid = executor_pid;
etun = enable_tun;
mprotect(sandbox_stack, 4096, PROT_NONE);
return clone(
namespace_sandbox_proc,
&sandbox_stack[sizeof(sandbox_stack) - 64],
CLONE_NEWUSER | CLONE_NEWPID | CLONE_NEWUTS | CLONE_NEWNET, NULL);
}
static void test();
void loop()
{
while (1) {
test();
}
}
long r[29];
void* thr(void* arg)
{
switch ((long)arg) {
case 0:
r[0] = syscall(__NR_mmap, 0x20000000ul, 0x1000ul, 0x3ul, 0x32ul,
0xfffffffffffffffful, 0x0ul);
break;
case 1:
NONFAILING(*(uint32_t*)0x20000ffc = (uint32_t)0x1);
r[2] = syscall(__NR_setsockopt, 0xfffffffffffffffful, 0x101ul,
0x4ul, 0x20000ffcul, 0x4ul);
break;
case 2:
r[3] = syscall(__NR_mmap, 0x20000000ul, 0xfff000ul, 0x3ul, 0x32ul,
0xfffffffffffffffful, 0x0ul);
break;
case 3:
NONFAILING(*(uint32_t*)0x20f1a000 = (uint32_t)0x4);
r[5] = syscall(__NR_getsockopt, 0xfffffffffffffffful, 0x1ul, 0x25ul,
0x20293000ul, 0x20f1a000ul);
break;
case 4:
r[6] = syscall(__NR_socketpair, 0x2ul, 0x0ul, 0x0ul, 0x203ceff8ul);
break;
case 5:
r[7] = syscall(__NR_socket, 0x11ul, 0x802ul, 0x300ul);
break;
case 6:
NONFAILING(*(uint32_t*)0x20010000 = (uint32_t)0xb);
r[9] = syscall(__NR_getsockopt, r[7], 0x84ul, 0xbul, 0x20de3000ul,
0x20010000ul);
break;
case 7:
r[10] = syscall(__NR_ioctl, r[7], 0x5411ul, 0x2065dffcul);
break;
case 8:
NONFAILING(*(uint16_t*)0x203ceff8 = (uint16_t)0x1);
NONFAILING(*(uint8_t*)0x203ceffa = (uint8_t)0x0);
NONFAILING(*(uint32_t*)0x203ceffc = (uint32_t)0x4e21);
r[14] = syscall(__NR_recvfrom, r[7], 0x206b4000ul, 0x0ul,
0x40000160ul, 0x203ceff8ul, 0x8ul);
break;
case 9:
r[15] = syscall(__NR_ioctl, 0xfffffffffffffffful, 0x8904ul,
0x20305ffcul);
break;
case 10:
NONFAILING(*(uint32_t*)0x20172ff8 = (uint32_t)0x0);
NONFAILING(*(uint32_t*)0x20172ffc = (uint32_t)0x0);
r[18] = syscall(__NR_setsockopt, r[7], 0x84ul, 0x14ul, 0x20172ff8ul,
0x8ul);
break;
case 11:
NONFAILING(*(uint32_t*)0x20df7ffc = (uint32_t)0x10001);
r[20] = syscall(__NR_setsockopt, r[7], 0x84ul, 0x8ul, 0x20df7ffcul,
0x4ul);
break;
case 12:
r[21] = syscall(__NR_socketpair, 0x2ul, 0x80802ul, 0x80000001ul,
0x20ad9ff8ul);
break;
case 13:
NONFAILING(*(uint16_t*)0x20fe2000 = (uint16_t)0x11);
NONFAILING(memcpy(
(void*)0x20fe2002,
"\x00\x00\x01\x00\x00\x00\x00\x00\x08\x00\x44\x94\x4e\xeb\xa7"
"\x1a\x49\x76\xe2\x52\x92\x2c\xb1\x8f\x6e\x2e\x2a\xba\x00\x00"
"\x00\x01\x2e\x0b\x38\x36\x00\x54\x04\xb0\xe0\x30\x1a\x4c\xe8"
"\x75\xf2\xe3\xff\x5f\x16\x3e\xe3\x40\xb7\x67\x95\x00\x80\x00"
"\x00\x00\x00\x00\x00\x00\x00\x08\x00\x58\x11\x03\x9e\x15\x77"
"\x50\x27\xec\xce\x66\xfd\x79\x2b\xbf\x0e\x5b\xf5\xff\x1b\x08"
"\x16\xf3\xf6\xdb\x1c\x00\x01\x00\x00\x00\x00\x00\x00\x00\x49"
"\x74\x00\x00\x00\x00\x00\x00\x00\x06\xad\x8e\x5e\xcc\x32\x6d"
"\x3a\x09\xff\xc2\xc6\x54",
126));
r[24] = syscall(__NR_bind, r[7], 0x20fe2000ul, 0x80ul);
break;
case 14:
NONFAILING(*(uint16_t*)0x208d0ffc = (uint16_t)0x7);
NONFAILING(*(uint8_t*)0x208d0ffe = (uint8_t)0x2);
NONFAILING(*(uint8_t*)0x208d0fff = (uint8_t)0x10a38e3bdb5c0051);
r[28] = syscall(__NR_setsockopt, r[7], 0x107ul, 0x12ul,
0x208d0ffcul, 0x4ul);
break;
}
return 0;
}
void test()
{
long i;
pthread_t th[30];
memset(r, -1, sizeof(r));
srand(getpid());
for (i = 0; i < 15; i++) {
pthread_create(&th[i], 0, thr, (void*)i);
usleep(rand() % 10000);
}
for (i = 0; i < 15; i++) {
pthread_create(&th[15 + i], 0, thr, (void*)i);
if (rand() % 2)
usleep(rand() % 10000);
}
usleep(rand() % 100000);
}
int main()
{
install_segv_handler();
use_temporary_dir();
int pid = do_sandbox_namespace(0, true);
int status = 0;
while (waitpid(pid, &status, __WALL) != pid) {
}
return 0;
}
|
the_stack_data/176704606.c | #include<stdio.h>
int main(){
int op,n1,n2;
scanf("%d\n%d\n%d",&op,&n1,&n2);
if((n1+n2)%2==0 && op == 0){
printf("0\n");
}
if((n1+n2)%2==0 && op == 1){
printf("1\n");
}
if((n1+n2)%2!=0 && op == 0){
printf("1\n");
}
if((n1+n2)%2!=0 && op == 1){
printf("0\n");
}
} |
the_stack_data/1064969.c | /* Test step/next in presence of #line directives.
Copyright (C) 2001-2021 Free Software Foundation, Inc.
This file is part of GDB.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
void dummy (int, int);
int f1 (int);
int f2 (int);
int
main (int argc, char **argv)
{
int i;
i = f1 (4);
i = f1 (i);
dummy (0, i);
return 0;
}
int
f1 (int i)
{
#line 40 "step-line.c"
dummy (1, i);
#line 24 "step-line.inp"
i = f2 (i);
#line 44 "step-line.c"
dummy (2, i);
#line 25 "step-line.inp"
i = f2 (i);
#line 48 "step-line.c"
dummy (3, i);
#line 26 "step-line.inp"
return i;
#line 52 "step-line.c"
}
int
f2 (int i)
{
#line 31 "step-line.inp"
int j;
#line 60 "step-line.c"
dummy (4, i);
#line 32 "step-line.inp"
j = i;
#line 64 "step-line.c"
dummy (5, i);
dummy (6, j);
#line 33 "step-line.inp"
j = j + 1;
#line 69 "step-line.c"
dummy (7, i);
dummy (8, j);
#line 34 "step-line.inp"
j = j - i;
#line 74 "step-line.c"
dummy (9, i);
dummy (10, j);
#line 35 "step-line.inp"
return i;
#line 79 "step-line.c"
}
void
dummy (int num, int i)
{
}
|
the_stack_data/28262695.c | #include <stdio.h>
#include <stdlib.h>
#define R 0
#define C 1
void solve(int count, int start, int **grid, int size, int **solution, int **stack, int *best);
int complete(int **grid, int size);
void apply(int **grid, int **solution, int count);
void print(int **grid, int size);
/* ===========================================================================
* Alternative form using supersets
* ===========================================================================
*/
int main(void)
{
// Open file
FILE *input = fopen("input.txt", "r");
if(input == NULL)
{
fprintf(stderr, "ERROR: Failed to open file.\n");
exit(1);
}
// Get size of problem
int size;
fscanf(input, "%d", &size);
// Create and read grid
int **grid = (int **) malloc(size * sizeof(int *));
for(int i = 0; i < size; ++i)
grid[i] = (int *) malloc(size * sizeof(int));
int read;
for(int r = 0; r < size; ++r)
for(int c = 0; c < size; ++c)
{
fscanf(input, "%d", &read);
grid[r][c] = read;
}
fclose(input);
// Allocate solution vector and temporary vector
int **solution = (int **) malloc((size * size) * sizeof(int *));
for(int i = 0; i < (size * size); ++i)
solution[i] = (int *) malloc(2 * sizeof(int));
int **stack = (int **) malloc((size * size) * sizeof(int *));
for(int i = 0; i < (size * size); ++i)
stack[i] = (int *) malloc(2 * sizeof(int));
// Solve problem
int counter = ((size * size) + 1);
solve(0, 0, grid, size, solution, stack, &counter);
// Print results
printf("We need to eliminate %d entries:\n", counter);
apply(grid, solution, counter);
print(grid, size);
// Free allocated memory and exit
for(int i = 0; i < size; ++i)
free(grid[i]);
free(grid);
return 0;
}
void solve(int count, int start, int **grid, int size, int **solution, int **stack, int *best)
{
// Skip recursion if we're already at a worse point than best
if(count >= *best)
return;
// Termination condition
if(start >= (size * size))
{
if(complete(grid, size))
{
if(count < *best)
{
*best = count;
for(int i = 0; i < count; ++i)
{
solution[i][R] = stack[i][R];
solution[i][C] = stack[i][C];
}
}
}
return;
}
for(int i = start; i < (size * size); ++i)
{
int r = i / size;
int c = i % size;
if(grid[r][c] == -1)
continue;
int pop = grid[r][c];
grid[r][c] = -1;
stack[count][R] = r;
stack[count][C] = c;
solve((count + 1), i, grid, size, solution, stack, best);
grid[r][c] = pop;
}
solve(count, (size * size), grid, size, solution, stack, best);
}
int complete(int **grid, int size)
{
for(int r = 0; r < size; ++r)
for(int c = 0; c < size; ++c)
{
for(int rr = 0; rr < size; ++rr)
if(rr != r && grid[r][c] != -1 && grid[rr][c] == grid[r][c])
return 0;
for(int cc = 0; cc < size; ++cc)
if(cc != c && grid[r][c] != -1 && grid[r][cc] == grid[r][c])
return 0;
}
return 1;
}
void apply(int **grid, int **solution, int count)
{
for(int i = 0; i < count; ++i)
grid[solution[i][R]][solution[i][C]] = -1;
}
void print(int **grid, int size)
{
putchar('\n');
for(int r = 0; r < size; ++r)
{
putchar('\t');
for(int c = 0; c < size; ++c)
printf("%c ", (grid[r][c] != -1) ? '0' + grid[r][c] : ' ');
putchar('\n');
}
} |
the_stack_data/804742.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()
{
bool _EL_X_2376, _x__EL_X_2376;
bool _EL_X_2381, _x__EL_X_2381;
float x_7, _x_x_7;
float x_8, _x_x_8;
float x_24, _x_x_24;
float x_9, _x_x_9;
float x_2, _x_x_2;
float x_0, _x_x_0;
float x_3, _x_x_3;
float x_18, _x_x_18;
float x_4, _x_x_4;
float x_19, _x_x_19;
float x_10, _x_x_10;
float x_22, _x_x_22;
float x_11, _x_x_11;
float x_25, _x_x_25;
float x_12, _x_x_12;
bool _EL_U_2379, _x__EL_U_2379;
float x_13, _x_x_13;
float x_16, _x_x_16;
float x_17, _x_x_17;
float x_20, _x_x_20;
float x_21, _x_x_21;
float x_26, _x_x_26;
float x_1, _x_x_1;
float x_27, _x_x_27;
float x_15, _x_x_15;
float x_6, _x_x_6;
float x_14, _x_x_14;
float x_23, _x_x_23;
float x_5, _x_x_5;
int __steps_to_fair = __VERIFIER_nondet_int();
_EL_X_2376 = __VERIFIER_nondet_bool();
_EL_X_2381 = __VERIFIER_nondet_bool();
x_7 = __VERIFIER_nondet_float();
x_8 = __VERIFIER_nondet_float();
x_24 = __VERIFIER_nondet_float();
x_9 = __VERIFIER_nondet_float();
x_2 = __VERIFIER_nondet_float();
x_0 = __VERIFIER_nondet_float();
x_3 = __VERIFIER_nondet_float();
x_18 = __VERIFIER_nondet_float();
x_4 = __VERIFIER_nondet_float();
x_19 = __VERIFIER_nondet_float();
x_10 = __VERIFIER_nondet_float();
x_22 = __VERIFIER_nondet_float();
x_11 = __VERIFIER_nondet_float();
x_25 = __VERIFIER_nondet_float();
x_12 = __VERIFIER_nondet_float();
_EL_U_2379 = __VERIFIER_nondet_bool();
x_13 = __VERIFIER_nondet_float();
x_16 = __VERIFIER_nondet_float();
x_17 = __VERIFIER_nondet_float();
x_20 = __VERIFIER_nondet_float();
x_21 = __VERIFIER_nondet_float();
x_26 = __VERIFIER_nondet_float();
x_1 = __VERIFIER_nondet_float();
x_27 = __VERIFIER_nondet_float();
x_15 = __VERIFIER_nondet_float();
x_6 = __VERIFIER_nondet_float();
x_14 = __VERIFIER_nondet_float();
x_23 = __VERIFIER_nondet_float();
x_5 = __VERIFIER_nondet_float();
bool __ok = (1 && ( !(_EL_X_2381 || _EL_X_2376)));
while (__steps_to_fair >= 0 && __ok) {
if (((15.0 <= (x_21 + (-1.0 * x_23))) || ( !((15.0 <= (x_21 + (-1.0 * x_23))) || _EL_U_2379)))) {
__steps_to_fair = __VERIFIER_nondet_int();
} else {
__steps_to_fair--;
}
_x__EL_X_2376 = __VERIFIER_nondet_bool();
_x__EL_X_2381 = __VERIFIER_nondet_bool();
_x_x_7 = __VERIFIER_nondet_float();
_x_x_8 = __VERIFIER_nondet_float();
_x_x_24 = __VERIFIER_nondet_float();
_x_x_9 = __VERIFIER_nondet_float();
_x_x_2 = __VERIFIER_nondet_float();
_x_x_0 = __VERIFIER_nondet_float();
_x_x_3 = __VERIFIER_nondet_float();
_x_x_18 = __VERIFIER_nondet_float();
_x_x_4 = __VERIFIER_nondet_float();
_x_x_19 = __VERIFIER_nondet_float();
_x_x_10 = __VERIFIER_nondet_float();
_x_x_22 = __VERIFIER_nondet_float();
_x_x_11 = __VERIFIER_nondet_float();
_x_x_25 = __VERIFIER_nondet_float();
_x_x_12 = __VERIFIER_nondet_float();
_x__EL_U_2379 = __VERIFIER_nondet_bool();
_x_x_13 = __VERIFIER_nondet_float();
_x_x_16 = __VERIFIER_nondet_float();
_x_x_17 = __VERIFIER_nondet_float();
_x_x_20 = __VERIFIER_nondet_float();
_x_x_21 = __VERIFIER_nondet_float();
_x_x_26 = __VERIFIER_nondet_float();
_x_x_1 = __VERIFIER_nondet_float();
_x_x_27 = __VERIFIER_nondet_float();
_x_x_15 = __VERIFIER_nondet_float();
_x_x_6 = __VERIFIER_nondet_float();
_x_x_14 = __VERIFIER_nondet_float();
_x_x_23 = __VERIFIER_nondet_float();
_x_x_5 = __VERIFIER_nondet_float();
__ok = ((((((((((((((((((((((((((((((((x_27 + (-1.0 * _x_x_0)) <= -16.0) && (((x_25 + (-1.0 * _x_x_0)) <= -5.0) && (((x_23 + (-1.0 * _x_x_0)) <= -13.0) && (((x_22 + (-1.0 * _x_x_0)) <= -17.0) && (((x_20 + (-1.0 * _x_x_0)) <= -11.0) && (((x_18 + (-1.0 * _x_x_0)) <= -6.0) && (((x_14 + (-1.0 * _x_x_0)) <= -8.0) && (((x_11 + (-1.0 * _x_x_0)) <= -17.0) && (((x_10 + (-1.0 * _x_x_0)) <= -20.0) && (((x_8 + (-1.0 * _x_x_0)) <= -11.0) && (((x_5 + (-1.0 * _x_x_0)) <= -20.0) && (((x_4 + (-1.0 * _x_x_0)) <= -17.0) && (((x_1 + (-1.0 * _x_x_0)) <= -2.0) && ((x_2 + (-1.0 * _x_x_0)) <= -14.0)))))))))))))) && (((x_27 + (-1.0 * _x_x_0)) == -16.0) || (((x_25 + (-1.0 * _x_x_0)) == -5.0) || (((x_23 + (-1.0 * _x_x_0)) == -13.0) || (((x_22 + (-1.0 * _x_x_0)) == -17.0) || (((x_20 + (-1.0 * _x_x_0)) == -11.0) || (((x_18 + (-1.0 * _x_x_0)) == -6.0) || (((x_14 + (-1.0 * _x_x_0)) == -8.0) || (((x_11 + (-1.0 * _x_x_0)) == -17.0) || (((x_10 + (-1.0 * _x_x_0)) == -20.0) || (((x_8 + (-1.0 * _x_x_0)) == -11.0) || (((x_5 + (-1.0 * _x_x_0)) == -20.0) || (((x_4 + (-1.0 * _x_x_0)) == -17.0) || (((x_1 + (-1.0 * _x_x_0)) == -2.0) || ((x_2 + (-1.0 * _x_x_0)) == -14.0))))))))))))))) && ((((x_26 + (-1.0 * _x_x_1)) <= -5.0) && (((x_25 + (-1.0 * _x_x_1)) <= -15.0) && (((x_24 + (-1.0 * _x_x_1)) <= -11.0) && (((x_22 + (-1.0 * _x_x_1)) <= -11.0) && (((x_20 + (-1.0 * _x_x_1)) <= -5.0) && (((x_18 + (-1.0 * _x_x_1)) <= -2.0) && (((x_16 + (-1.0 * _x_x_1)) <= -18.0) && (((x_12 + (-1.0 * _x_x_1)) <= -9.0) && (((x_10 + (-1.0 * _x_x_1)) <= -17.0) && (((x_6 + (-1.0 * _x_x_1)) <= -12.0) && (((x_5 + (-1.0 * _x_x_1)) <= -12.0) && (((x_3 + (-1.0 * _x_x_1)) <= -12.0) && (((x_0 + (-1.0 * _x_x_1)) <= -2.0) && ((x_1 + (-1.0 * _x_x_1)) <= -14.0)))))))))))))) && (((x_26 + (-1.0 * _x_x_1)) == -5.0) || (((x_25 + (-1.0 * _x_x_1)) == -15.0) || (((x_24 + (-1.0 * _x_x_1)) == -11.0) || (((x_22 + (-1.0 * _x_x_1)) == -11.0) || (((x_20 + (-1.0 * _x_x_1)) == -5.0) || (((x_18 + (-1.0 * _x_x_1)) == -2.0) || (((x_16 + (-1.0 * _x_x_1)) == -18.0) || (((x_12 + (-1.0 * _x_x_1)) == -9.0) || (((x_10 + (-1.0 * _x_x_1)) == -17.0) || (((x_6 + (-1.0 * _x_x_1)) == -12.0) || (((x_5 + (-1.0 * _x_x_1)) == -12.0) || (((x_3 + (-1.0 * _x_x_1)) == -12.0) || (((x_0 + (-1.0 * _x_x_1)) == -2.0) || ((x_1 + (-1.0 * _x_x_1)) == -14.0)))))))))))))))) && ((((x_26 + (-1.0 * _x_x_2)) <= -14.0) && (((x_25 + (-1.0 * _x_x_2)) <= -17.0) && (((x_24 + (-1.0 * _x_x_2)) <= -9.0) && (((x_22 + (-1.0 * _x_x_2)) <= -2.0) && (((x_21 + (-1.0 * _x_x_2)) <= -20.0) && (((x_19 + (-1.0 * _x_x_2)) <= -1.0) && (((x_18 + (-1.0 * _x_x_2)) <= -5.0) && (((x_16 + (-1.0 * _x_x_2)) <= -13.0) && (((x_14 + (-1.0 * _x_x_2)) <= -1.0) && (((x_8 + (-1.0 * _x_x_2)) <= -2.0) && (((x_6 + (-1.0 * _x_x_2)) <= -3.0) && (((x_5 + (-1.0 * _x_x_2)) <= -13.0) && (((x_1 + (-1.0 * _x_x_2)) <= -5.0) && ((x_4 + (-1.0 * _x_x_2)) <= -12.0)))))))))))))) && (((x_26 + (-1.0 * _x_x_2)) == -14.0) || (((x_25 + (-1.0 * _x_x_2)) == -17.0) || (((x_24 + (-1.0 * _x_x_2)) == -9.0) || (((x_22 + (-1.0 * _x_x_2)) == -2.0) || (((x_21 + (-1.0 * _x_x_2)) == -20.0) || (((x_19 + (-1.0 * _x_x_2)) == -1.0) || (((x_18 + (-1.0 * _x_x_2)) == -5.0) || (((x_16 + (-1.0 * _x_x_2)) == -13.0) || (((x_14 + (-1.0 * _x_x_2)) == -1.0) || (((x_8 + (-1.0 * _x_x_2)) == -2.0) || (((x_6 + (-1.0 * _x_x_2)) == -3.0) || (((x_5 + (-1.0 * _x_x_2)) == -13.0) || (((x_1 + (-1.0 * _x_x_2)) == -5.0) || ((x_4 + (-1.0 * _x_x_2)) == -12.0)))))))))))))))) && ((((x_26 + (-1.0 * _x_x_3)) <= -19.0) && (((x_25 + (-1.0 * _x_x_3)) <= -9.0) && (((x_24 + (-1.0 * _x_x_3)) <= -11.0) && (((x_22 + (-1.0 * _x_x_3)) <= -13.0) && (((x_21 + (-1.0 * _x_x_3)) <= -19.0) && (((x_20 + (-1.0 * _x_x_3)) <= -10.0) && (((x_19 + (-1.0 * _x_x_3)) <= -1.0) && (((x_18 + (-1.0 * _x_x_3)) <= -16.0) && (((x_15 + (-1.0 * _x_x_3)) <= -8.0) && (((x_13 + (-1.0 * _x_x_3)) <= -9.0) && (((x_10 + (-1.0 * _x_x_3)) <= -19.0) && (((x_9 + (-1.0 * _x_x_3)) <= -3.0) && (((x_0 + (-1.0 * _x_x_3)) <= -2.0) && ((x_1 + (-1.0 * _x_x_3)) <= -12.0)))))))))))))) && (((x_26 + (-1.0 * _x_x_3)) == -19.0) || (((x_25 + (-1.0 * _x_x_3)) == -9.0) || (((x_24 + (-1.0 * _x_x_3)) == -11.0) || (((x_22 + (-1.0 * _x_x_3)) == -13.0) || (((x_21 + (-1.0 * _x_x_3)) == -19.0) || (((x_20 + (-1.0 * _x_x_3)) == -10.0) || (((x_19 + (-1.0 * _x_x_3)) == -1.0) || (((x_18 + (-1.0 * _x_x_3)) == -16.0) || (((x_15 + (-1.0 * _x_x_3)) == -8.0) || (((x_13 + (-1.0 * _x_x_3)) == -9.0) || (((x_10 + (-1.0 * _x_x_3)) == -19.0) || (((x_9 + (-1.0 * _x_x_3)) == -3.0) || (((x_0 + (-1.0 * _x_x_3)) == -2.0) || ((x_1 + (-1.0 * _x_x_3)) == -12.0)))))))))))))))) && ((((x_26 + (-1.0 * _x_x_4)) <= -7.0) && (((x_22 + (-1.0 * _x_x_4)) <= -20.0) && (((x_21 + (-1.0 * _x_x_4)) <= -12.0) && (((x_20 + (-1.0 * _x_x_4)) <= -10.0) && (((x_19 + (-1.0 * _x_x_4)) <= -3.0) && (((x_18 + (-1.0 * _x_x_4)) <= -16.0) && (((x_17 + (-1.0 * _x_x_4)) <= -8.0) && (((x_16 + (-1.0 * _x_x_4)) <= -16.0) && (((x_14 + (-1.0 * _x_x_4)) <= -13.0) && (((x_12 + (-1.0 * _x_x_4)) <= -14.0) && (((x_10 + (-1.0 * _x_x_4)) <= -20.0) && (((x_7 + (-1.0 * _x_x_4)) <= -17.0) && (((x_0 + (-1.0 * _x_x_4)) <= -10.0) && ((x_2 + (-1.0 * _x_x_4)) <= -8.0)))))))))))))) && (((x_26 + (-1.0 * _x_x_4)) == -7.0) || (((x_22 + (-1.0 * _x_x_4)) == -20.0) || (((x_21 + (-1.0 * _x_x_4)) == -12.0) || (((x_20 + (-1.0 * _x_x_4)) == -10.0) || (((x_19 + (-1.0 * _x_x_4)) == -3.0) || (((x_18 + (-1.0 * _x_x_4)) == -16.0) || (((x_17 + (-1.0 * _x_x_4)) == -8.0) || (((x_16 + (-1.0 * _x_x_4)) == -16.0) || (((x_14 + (-1.0 * _x_x_4)) == -13.0) || (((x_12 + (-1.0 * _x_x_4)) == -14.0) || (((x_10 + (-1.0 * _x_x_4)) == -20.0) || (((x_7 + (-1.0 * _x_x_4)) == -17.0) || (((x_0 + (-1.0 * _x_x_4)) == -10.0) || ((x_2 + (-1.0 * _x_x_4)) == -8.0)))))))))))))))) && ((((x_27 + (-1.0 * _x_x_5)) <= -2.0) && (((x_23 + (-1.0 * _x_x_5)) <= -12.0) && (((x_22 + (-1.0 * _x_x_5)) <= -14.0) && (((x_21 + (-1.0 * _x_x_5)) <= -7.0) && (((x_20 + (-1.0 * _x_x_5)) <= -12.0) && (((x_19 + (-1.0 * _x_x_5)) <= -18.0) && (((x_18 + (-1.0 * _x_x_5)) <= -9.0) && (((x_16 + (-1.0 * _x_x_5)) <= -1.0) && (((x_14 + (-1.0 * _x_x_5)) <= -18.0) && (((x_13 + (-1.0 * _x_x_5)) <= -16.0) && (((x_11 + (-1.0 * _x_x_5)) <= -15.0) && (((x_8 + (-1.0 * _x_x_5)) <= -13.0) && (((x_2 + (-1.0 * _x_x_5)) <= -4.0) && ((x_3 + (-1.0 * _x_x_5)) <= -7.0)))))))))))))) && (((x_27 + (-1.0 * _x_x_5)) == -2.0) || (((x_23 + (-1.0 * _x_x_5)) == -12.0) || (((x_22 + (-1.0 * _x_x_5)) == -14.0) || (((x_21 + (-1.0 * _x_x_5)) == -7.0) || (((x_20 + (-1.0 * _x_x_5)) == -12.0) || (((x_19 + (-1.0 * _x_x_5)) == -18.0) || (((x_18 + (-1.0 * _x_x_5)) == -9.0) || (((x_16 + (-1.0 * _x_x_5)) == -1.0) || (((x_14 + (-1.0 * _x_x_5)) == -18.0) || (((x_13 + (-1.0 * _x_x_5)) == -16.0) || (((x_11 + (-1.0 * _x_x_5)) == -15.0) || (((x_8 + (-1.0 * _x_x_5)) == -13.0) || (((x_2 + (-1.0 * _x_x_5)) == -4.0) || ((x_3 + (-1.0 * _x_x_5)) == -7.0)))))))))))))))) && ((((x_27 + (-1.0 * _x_x_6)) <= -4.0) && (((x_26 + (-1.0 * _x_x_6)) <= -15.0) && (((x_25 + (-1.0 * _x_x_6)) <= -18.0) && (((x_24 + (-1.0 * _x_x_6)) <= -6.0) && (((x_22 + (-1.0 * _x_x_6)) <= -4.0) && (((x_21 + (-1.0 * _x_x_6)) <= -9.0) && (((x_19 + (-1.0 * _x_x_6)) <= -17.0) && (((x_17 + (-1.0 * _x_x_6)) <= -8.0) && (((x_11 + (-1.0 * _x_x_6)) <= -17.0) && (((x_10 + (-1.0 * _x_x_6)) <= -4.0) && (((x_9 + (-1.0 * _x_x_6)) <= -15.0) && (((x_6 + (-1.0 * _x_x_6)) <= -16.0) && (((x_1 + (-1.0 * _x_x_6)) <= -16.0) && ((x_2 + (-1.0 * _x_x_6)) <= -14.0)))))))))))))) && (((x_27 + (-1.0 * _x_x_6)) == -4.0) || (((x_26 + (-1.0 * _x_x_6)) == -15.0) || (((x_25 + (-1.0 * _x_x_6)) == -18.0) || (((x_24 + (-1.0 * _x_x_6)) == -6.0) || (((x_22 + (-1.0 * _x_x_6)) == -4.0) || (((x_21 + (-1.0 * _x_x_6)) == -9.0) || (((x_19 + (-1.0 * _x_x_6)) == -17.0) || (((x_17 + (-1.0 * _x_x_6)) == -8.0) || (((x_11 + (-1.0 * _x_x_6)) == -17.0) || (((x_10 + (-1.0 * _x_x_6)) == -4.0) || (((x_9 + (-1.0 * _x_x_6)) == -15.0) || (((x_6 + (-1.0 * _x_x_6)) == -16.0) || (((x_1 + (-1.0 * _x_x_6)) == -16.0) || ((x_2 + (-1.0 * _x_x_6)) == -14.0)))))))))))))))) && ((((x_27 + (-1.0 * _x_x_7)) <= -17.0) && (((x_26 + (-1.0 * _x_x_7)) <= -7.0) && (((x_25 + (-1.0 * _x_x_7)) <= -13.0) && (((x_24 + (-1.0 * _x_x_7)) <= -12.0) && (((x_21 + (-1.0 * _x_x_7)) <= -6.0) && (((x_20 + (-1.0 * _x_x_7)) <= -11.0) && (((x_18 + (-1.0 * _x_x_7)) <= -13.0) && (((x_8 + (-1.0 * _x_x_7)) <= -1.0) && (((x_7 + (-1.0 * _x_x_7)) <= -2.0) && (((x_6 + (-1.0 * _x_x_7)) <= -10.0) && (((x_3 + (-1.0 * _x_x_7)) <= -15.0) && (((x_2 + (-1.0 * _x_x_7)) <= -14.0) && (((x_0 + (-1.0 * _x_x_7)) <= -6.0) && ((x_1 + (-1.0 * _x_x_7)) <= -14.0)))))))))))))) && (((x_27 + (-1.0 * _x_x_7)) == -17.0) || (((x_26 + (-1.0 * _x_x_7)) == -7.0) || (((x_25 + (-1.0 * _x_x_7)) == -13.0) || (((x_24 + (-1.0 * _x_x_7)) == -12.0) || (((x_21 + (-1.0 * _x_x_7)) == -6.0) || (((x_20 + (-1.0 * _x_x_7)) == -11.0) || (((x_18 + (-1.0 * _x_x_7)) == -13.0) || (((x_8 + (-1.0 * _x_x_7)) == -1.0) || (((x_7 + (-1.0 * _x_x_7)) == -2.0) || (((x_6 + (-1.0 * _x_x_7)) == -10.0) || (((x_3 + (-1.0 * _x_x_7)) == -15.0) || (((x_2 + (-1.0 * _x_x_7)) == -14.0) || (((x_0 + (-1.0 * _x_x_7)) == -6.0) || ((x_1 + (-1.0 * _x_x_7)) == -14.0)))))))))))))))) && ((((x_24 + (-1.0 * _x_x_8)) <= -19.0) && (((x_23 + (-1.0 * _x_x_8)) <= -11.0) && (((x_21 + (-1.0 * _x_x_8)) <= -5.0) && (((x_19 + (-1.0 * _x_x_8)) <= -7.0) && (((x_16 + (-1.0 * _x_x_8)) <= -3.0) && (((x_13 + (-1.0 * _x_x_8)) <= -13.0) && (((x_11 + (-1.0 * _x_x_8)) <= -5.0) && (((x_9 + (-1.0 * _x_x_8)) <= -13.0) && (((x_8 + (-1.0 * _x_x_8)) <= -2.0) && (((x_7 + (-1.0 * _x_x_8)) <= -4.0) && (((x_5 + (-1.0 * _x_x_8)) <= -15.0) && (((x_4 + (-1.0 * _x_x_8)) <= -7.0) && (((x_0 + (-1.0 * _x_x_8)) <= -11.0) && ((x_1 + (-1.0 * _x_x_8)) <= -14.0)))))))))))))) && (((x_24 + (-1.0 * _x_x_8)) == -19.0) || (((x_23 + (-1.0 * _x_x_8)) == -11.0) || (((x_21 + (-1.0 * _x_x_8)) == -5.0) || (((x_19 + (-1.0 * _x_x_8)) == -7.0) || (((x_16 + (-1.0 * _x_x_8)) == -3.0) || (((x_13 + (-1.0 * _x_x_8)) == -13.0) || (((x_11 + (-1.0 * _x_x_8)) == -5.0) || (((x_9 + (-1.0 * _x_x_8)) == -13.0) || (((x_8 + (-1.0 * _x_x_8)) == -2.0) || (((x_7 + (-1.0 * _x_x_8)) == -4.0) || (((x_5 + (-1.0 * _x_x_8)) == -15.0) || (((x_4 + (-1.0 * _x_x_8)) == -7.0) || (((x_0 + (-1.0 * _x_x_8)) == -11.0) || ((x_1 + (-1.0 * _x_x_8)) == -14.0)))))))))))))))) && ((((x_26 + (-1.0 * _x_x_9)) <= -11.0) && (((x_21 + (-1.0 * _x_x_9)) <= -6.0) && (((x_20 + (-1.0 * _x_x_9)) <= -9.0) && (((x_18 + (-1.0 * _x_x_9)) <= -5.0) && (((x_17 + (-1.0 * _x_x_9)) <= -18.0) && (((x_16 + (-1.0 * _x_x_9)) <= -13.0) && (((x_11 + (-1.0 * _x_x_9)) <= -7.0) && (((x_9 + (-1.0 * _x_x_9)) <= -13.0) && (((x_7 + (-1.0 * _x_x_9)) <= -13.0) && (((x_5 + (-1.0 * _x_x_9)) <= -10.0) && (((x_4 + (-1.0 * _x_x_9)) <= -11.0) && (((x_2 + (-1.0 * _x_x_9)) <= -14.0) && (((x_0 + (-1.0 * _x_x_9)) <= -14.0) && ((x_1 + (-1.0 * _x_x_9)) <= -14.0)))))))))))))) && (((x_26 + (-1.0 * _x_x_9)) == -11.0) || (((x_21 + (-1.0 * _x_x_9)) == -6.0) || (((x_20 + (-1.0 * _x_x_9)) == -9.0) || (((x_18 + (-1.0 * _x_x_9)) == -5.0) || (((x_17 + (-1.0 * _x_x_9)) == -18.0) || (((x_16 + (-1.0 * _x_x_9)) == -13.0) || (((x_11 + (-1.0 * _x_x_9)) == -7.0) || (((x_9 + (-1.0 * _x_x_9)) == -13.0) || (((x_7 + (-1.0 * _x_x_9)) == -13.0) || (((x_5 + (-1.0 * _x_x_9)) == -10.0) || (((x_4 + (-1.0 * _x_x_9)) == -11.0) || (((x_2 + (-1.0 * _x_x_9)) == -14.0) || (((x_0 + (-1.0 * _x_x_9)) == -14.0) || ((x_1 + (-1.0 * _x_x_9)) == -14.0)))))))))))))))) && ((((x_26 + (-1.0 * _x_x_10)) <= -20.0) && (((x_25 + (-1.0 * _x_x_10)) <= -9.0) && (((x_23 + (-1.0 * _x_x_10)) <= -18.0) && (((x_22 + (-1.0 * _x_x_10)) <= -11.0) && (((x_18 + (-1.0 * _x_x_10)) <= -15.0) && (((x_16 + (-1.0 * _x_x_10)) <= -13.0) && (((x_15 + (-1.0 * _x_x_10)) <= -8.0) && (((x_13 + (-1.0 * _x_x_10)) <= -13.0) && (((x_12 + (-1.0 * _x_x_10)) <= -9.0) && (((x_10 + (-1.0 * _x_x_10)) <= -4.0) && (((x_8 + (-1.0 * _x_x_10)) <= -12.0) && (((x_4 + (-1.0 * _x_x_10)) <= -5.0) && (((x_1 + (-1.0 * _x_x_10)) <= -16.0) && ((x_3 + (-1.0 * _x_x_10)) <= -20.0)))))))))))))) && (((x_26 + (-1.0 * _x_x_10)) == -20.0) || (((x_25 + (-1.0 * _x_x_10)) == -9.0) || (((x_23 + (-1.0 * _x_x_10)) == -18.0) || (((x_22 + (-1.0 * _x_x_10)) == -11.0) || (((x_18 + (-1.0 * _x_x_10)) == -15.0) || (((x_16 + (-1.0 * _x_x_10)) == -13.0) || (((x_15 + (-1.0 * _x_x_10)) == -8.0) || (((x_13 + (-1.0 * _x_x_10)) == -13.0) || (((x_12 + (-1.0 * _x_x_10)) == -9.0) || (((x_10 + (-1.0 * _x_x_10)) == -4.0) || (((x_8 + (-1.0 * _x_x_10)) == -12.0) || (((x_4 + (-1.0 * _x_x_10)) == -5.0) || (((x_1 + (-1.0 * _x_x_10)) == -16.0) || ((x_3 + (-1.0 * _x_x_10)) == -20.0)))))))))))))))) && ((((x_27 + (-1.0 * _x_x_11)) <= -12.0) && (((x_26 + (-1.0 * _x_x_11)) <= -13.0) && (((x_25 + (-1.0 * _x_x_11)) <= -5.0) && (((x_22 + (-1.0 * _x_x_11)) <= -6.0) && (((x_21 + (-1.0 * _x_x_11)) <= -1.0) && (((x_20 + (-1.0 * _x_x_11)) <= -19.0) && (((x_18 + (-1.0 * _x_x_11)) <= -4.0) && (((x_16 + (-1.0 * _x_x_11)) <= -17.0) && (((x_15 + (-1.0 * _x_x_11)) <= -18.0) && (((x_14 + (-1.0 * _x_x_11)) <= -8.0) && (((x_10 + (-1.0 * _x_x_11)) <= -3.0) && (((x_4 + (-1.0 * _x_x_11)) <= -12.0) && (((x_2 + (-1.0 * _x_x_11)) <= -20.0) && ((x_3 + (-1.0 * _x_x_11)) <= -9.0)))))))))))))) && (((x_27 + (-1.0 * _x_x_11)) == -12.0) || (((x_26 + (-1.0 * _x_x_11)) == -13.0) || (((x_25 + (-1.0 * _x_x_11)) == -5.0) || (((x_22 + (-1.0 * _x_x_11)) == -6.0) || (((x_21 + (-1.0 * _x_x_11)) == -1.0) || (((x_20 + (-1.0 * _x_x_11)) == -19.0) || (((x_18 + (-1.0 * _x_x_11)) == -4.0) || (((x_16 + (-1.0 * _x_x_11)) == -17.0) || (((x_15 + (-1.0 * _x_x_11)) == -18.0) || (((x_14 + (-1.0 * _x_x_11)) == -8.0) || (((x_10 + (-1.0 * _x_x_11)) == -3.0) || (((x_4 + (-1.0 * _x_x_11)) == -12.0) || (((x_2 + (-1.0 * _x_x_11)) == -20.0) || ((x_3 + (-1.0 * _x_x_11)) == -9.0)))))))))))))))) && ((((x_26 + (-1.0 * _x_x_12)) <= -13.0) && (((x_25 + (-1.0 * _x_x_12)) <= -20.0) && (((x_24 + (-1.0 * _x_x_12)) <= -13.0) && (((x_23 + (-1.0 * _x_x_12)) <= -1.0) && (((x_16 + (-1.0 * _x_x_12)) <= -5.0) && (((x_14 + (-1.0 * _x_x_12)) <= -19.0) && (((x_13 + (-1.0 * _x_x_12)) <= -9.0) && (((x_12 + (-1.0 * _x_x_12)) <= -7.0) && (((x_11 + (-1.0 * _x_x_12)) <= -10.0) && (((x_10 + (-1.0 * _x_x_12)) <= -9.0) && (((x_6 + (-1.0 * _x_x_12)) <= -15.0) && (((x_5 + (-1.0 * _x_x_12)) <= -8.0) && (((x_0 + (-1.0 * _x_x_12)) <= -7.0) && ((x_1 + (-1.0 * _x_x_12)) <= -19.0)))))))))))))) && (((x_26 + (-1.0 * _x_x_12)) == -13.0) || (((x_25 + (-1.0 * _x_x_12)) == -20.0) || (((x_24 + (-1.0 * _x_x_12)) == -13.0) || (((x_23 + (-1.0 * _x_x_12)) == -1.0) || (((x_16 + (-1.0 * _x_x_12)) == -5.0) || (((x_14 + (-1.0 * _x_x_12)) == -19.0) || (((x_13 + (-1.0 * _x_x_12)) == -9.0) || (((x_12 + (-1.0 * _x_x_12)) == -7.0) || (((x_11 + (-1.0 * _x_x_12)) == -10.0) || (((x_10 + (-1.0 * _x_x_12)) == -9.0) || (((x_6 + (-1.0 * _x_x_12)) == -15.0) || (((x_5 + (-1.0 * _x_x_12)) == -8.0) || (((x_0 + (-1.0 * _x_x_12)) == -7.0) || ((x_1 + (-1.0 * _x_x_12)) == -19.0)))))))))))))))) && ((((x_27 + (-1.0 * _x_x_13)) <= -7.0) && (((x_26 + (-1.0 * _x_x_13)) <= -11.0) && (((x_24 + (-1.0 * _x_x_13)) <= -11.0) && (((x_21 + (-1.0 * _x_x_13)) <= -6.0) && (((x_18 + (-1.0 * _x_x_13)) <= -2.0) && (((x_17 + (-1.0 * _x_x_13)) <= -16.0) && (((x_16 + (-1.0 * _x_x_13)) <= -5.0) && (((x_15 + (-1.0 * _x_x_13)) <= -8.0) && (((x_12 + (-1.0 * _x_x_13)) <= -10.0) && (((x_8 + (-1.0 * _x_x_13)) <= -11.0) && (((x_6 + (-1.0 * _x_x_13)) <= -11.0) && (((x_4 + (-1.0 * _x_x_13)) <= -13.0) && (((x_0 + (-1.0 * _x_x_13)) <= -14.0) && ((x_3 + (-1.0 * _x_x_13)) <= -12.0)))))))))))))) && (((x_27 + (-1.0 * _x_x_13)) == -7.0) || (((x_26 + (-1.0 * _x_x_13)) == -11.0) || (((x_24 + (-1.0 * _x_x_13)) == -11.0) || (((x_21 + (-1.0 * _x_x_13)) == -6.0) || (((x_18 + (-1.0 * _x_x_13)) == -2.0) || (((x_17 + (-1.0 * _x_x_13)) == -16.0) || (((x_16 + (-1.0 * _x_x_13)) == -5.0) || (((x_15 + (-1.0 * _x_x_13)) == -8.0) || (((x_12 + (-1.0 * _x_x_13)) == -10.0) || (((x_8 + (-1.0 * _x_x_13)) == -11.0) || (((x_6 + (-1.0 * _x_x_13)) == -11.0) || (((x_4 + (-1.0 * _x_x_13)) == -13.0) || (((x_0 + (-1.0 * _x_x_13)) == -14.0) || ((x_3 + (-1.0 * _x_x_13)) == -12.0)))))))))))))))) && ((((x_27 + (-1.0 * _x_x_14)) <= -19.0) && (((x_26 + (-1.0 * _x_x_14)) <= -10.0) && (((x_23 + (-1.0 * _x_x_14)) <= -6.0) && (((x_21 + (-1.0 * _x_x_14)) <= -16.0) && (((x_18 + (-1.0 * _x_x_14)) <= -2.0) && (((x_14 + (-1.0 * _x_x_14)) <= -11.0) && (((x_12 + (-1.0 * _x_x_14)) <= -3.0) && (((x_11 + (-1.0 * _x_x_14)) <= -17.0) && (((x_9 + (-1.0 * _x_x_14)) <= -16.0) && (((x_6 + (-1.0 * _x_x_14)) <= -3.0) && (((x_5 + (-1.0 * _x_x_14)) <= -9.0) && (((x_4 + (-1.0 * _x_x_14)) <= -4.0) && (((x_2 + (-1.0 * _x_x_14)) <= -6.0) && ((x_3 + (-1.0 * _x_x_14)) <= -3.0)))))))))))))) && (((x_27 + (-1.0 * _x_x_14)) == -19.0) || (((x_26 + (-1.0 * _x_x_14)) == -10.0) || (((x_23 + (-1.0 * _x_x_14)) == -6.0) || (((x_21 + (-1.0 * _x_x_14)) == -16.0) || (((x_18 + (-1.0 * _x_x_14)) == -2.0) || (((x_14 + (-1.0 * _x_x_14)) == -11.0) || (((x_12 + (-1.0 * _x_x_14)) == -3.0) || (((x_11 + (-1.0 * _x_x_14)) == -17.0) || (((x_9 + (-1.0 * _x_x_14)) == -16.0) || (((x_6 + (-1.0 * _x_x_14)) == -3.0) || (((x_5 + (-1.0 * _x_x_14)) == -9.0) || (((x_4 + (-1.0 * _x_x_14)) == -4.0) || (((x_2 + (-1.0 * _x_x_14)) == -6.0) || ((x_3 + (-1.0 * _x_x_14)) == -3.0)))))))))))))))) && ((((x_25 + (-1.0 * _x_x_15)) <= -4.0) && (((x_23 + (-1.0 * _x_x_15)) <= -5.0) && (((x_22 + (-1.0 * _x_x_15)) <= -13.0) && (((x_21 + (-1.0 * _x_x_15)) <= -17.0) && (((x_19 + (-1.0 * _x_x_15)) <= -15.0) && (((x_18 + (-1.0 * _x_x_15)) <= -8.0) && (((x_13 + (-1.0 * _x_x_15)) <= -4.0) && (((x_12 + (-1.0 * _x_x_15)) <= -1.0) && (((x_8 + (-1.0 * _x_x_15)) <= -18.0) && (((x_7 + (-1.0 * _x_x_15)) <= -19.0) && (((x_6 + (-1.0 * _x_x_15)) <= -20.0) && (((x_4 + (-1.0 * _x_x_15)) <= -3.0) && (((x_0 + (-1.0 * _x_x_15)) <= -10.0) && ((x_3 + (-1.0 * _x_x_15)) <= -5.0)))))))))))))) && (((x_25 + (-1.0 * _x_x_15)) == -4.0) || (((x_23 + (-1.0 * _x_x_15)) == -5.0) || (((x_22 + (-1.0 * _x_x_15)) == -13.0) || (((x_21 + (-1.0 * _x_x_15)) == -17.0) || (((x_19 + (-1.0 * _x_x_15)) == -15.0) || (((x_18 + (-1.0 * _x_x_15)) == -8.0) || (((x_13 + (-1.0 * _x_x_15)) == -4.0) || (((x_12 + (-1.0 * _x_x_15)) == -1.0) || (((x_8 + (-1.0 * _x_x_15)) == -18.0) || (((x_7 + (-1.0 * _x_x_15)) == -19.0) || (((x_6 + (-1.0 * _x_x_15)) == -20.0) || (((x_4 + (-1.0 * _x_x_15)) == -3.0) || (((x_0 + (-1.0 * _x_x_15)) == -10.0) || ((x_3 + (-1.0 * _x_x_15)) == -5.0)))))))))))))))) && ((((x_25 + (-1.0 * _x_x_16)) <= -14.0) && (((x_24 + (-1.0 * _x_x_16)) <= -12.0) && (((x_21 + (-1.0 * _x_x_16)) <= -1.0) && (((x_18 + (-1.0 * _x_x_16)) <= -11.0) && (((x_17 + (-1.0 * _x_x_16)) <= -15.0) && (((x_16 + (-1.0 * _x_x_16)) <= -9.0) && (((x_15 + (-1.0 * _x_x_16)) <= -14.0) && (((x_14 + (-1.0 * _x_x_16)) <= -13.0) && (((x_13 + (-1.0 * _x_x_16)) <= -20.0) && (((x_10 + (-1.0 * _x_x_16)) <= -2.0) && (((x_9 + (-1.0 * _x_x_16)) <= -12.0) && (((x_5 + (-1.0 * _x_x_16)) <= -18.0) && (((x_0 + (-1.0 * _x_x_16)) <= -15.0) && ((x_4 + (-1.0 * _x_x_16)) <= -4.0)))))))))))))) && (((x_25 + (-1.0 * _x_x_16)) == -14.0) || (((x_24 + (-1.0 * _x_x_16)) == -12.0) || (((x_21 + (-1.0 * _x_x_16)) == -1.0) || (((x_18 + (-1.0 * _x_x_16)) == -11.0) || (((x_17 + (-1.0 * _x_x_16)) == -15.0) || (((x_16 + (-1.0 * _x_x_16)) == -9.0) || (((x_15 + (-1.0 * _x_x_16)) == -14.0) || (((x_14 + (-1.0 * _x_x_16)) == -13.0) || (((x_13 + (-1.0 * _x_x_16)) == -20.0) || (((x_10 + (-1.0 * _x_x_16)) == -2.0) || (((x_9 + (-1.0 * _x_x_16)) == -12.0) || (((x_5 + (-1.0 * _x_x_16)) == -18.0) || (((x_0 + (-1.0 * _x_x_16)) == -15.0) || ((x_4 + (-1.0 * _x_x_16)) == -4.0)))))))))))))))) && ((((x_27 + (-1.0 * _x_x_17)) <= -5.0) && (((x_26 + (-1.0 * _x_x_17)) <= -10.0) && (((x_21 + (-1.0 * _x_x_17)) <= -11.0) && (((x_20 + (-1.0 * _x_x_17)) <= -18.0) && (((x_18 + (-1.0 * _x_x_17)) <= -11.0) && (((x_15 + (-1.0 * _x_x_17)) <= -15.0) && (((x_14 + (-1.0 * _x_x_17)) <= -19.0) && (((x_13 + (-1.0 * _x_x_17)) <= -12.0) && (((x_9 + (-1.0 * _x_x_17)) <= -2.0) && (((x_8 + (-1.0 * _x_x_17)) <= -3.0) && (((x_6 + (-1.0 * _x_x_17)) <= -20.0) && (((x_4 + (-1.0 * _x_x_17)) <= -14.0) && (((x_0 + (-1.0 * _x_x_17)) <= -9.0) && ((x_3 + (-1.0 * _x_x_17)) <= -14.0)))))))))))))) && (((x_27 + (-1.0 * _x_x_17)) == -5.0) || (((x_26 + (-1.0 * _x_x_17)) == -10.0) || (((x_21 + (-1.0 * _x_x_17)) == -11.0) || (((x_20 + (-1.0 * _x_x_17)) == -18.0) || (((x_18 + (-1.0 * _x_x_17)) == -11.0) || (((x_15 + (-1.0 * _x_x_17)) == -15.0) || (((x_14 + (-1.0 * _x_x_17)) == -19.0) || (((x_13 + (-1.0 * _x_x_17)) == -12.0) || (((x_9 + (-1.0 * _x_x_17)) == -2.0) || (((x_8 + (-1.0 * _x_x_17)) == -3.0) || (((x_6 + (-1.0 * _x_x_17)) == -20.0) || (((x_4 + (-1.0 * _x_x_17)) == -14.0) || (((x_0 + (-1.0 * _x_x_17)) == -9.0) || ((x_3 + (-1.0 * _x_x_17)) == -14.0)))))))))))))))) && ((((x_25 + (-1.0 * _x_x_18)) <= -16.0) && (((x_24 + (-1.0 * _x_x_18)) <= -6.0) && (((x_22 + (-1.0 * _x_x_18)) <= -16.0) && (((x_20 + (-1.0 * _x_x_18)) <= -16.0) && (((x_18 + (-1.0 * _x_x_18)) <= -4.0) && (((x_17 + (-1.0 * _x_x_18)) <= -9.0) && (((x_15 + (-1.0 * _x_x_18)) <= -12.0) && (((x_14 + (-1.0 * _x_x_18)) <= -9.0) && (((x_12 + (-1.0 * _x_x_18)) <= -4.0) && (((x_10 + (-1.0 * _x_x_18)) <= -11.0) && (((x_7 + (-1.0 * _x_x_18)) <= -13.0) && (((x_5 + (-1.0 * _x_x_18)) <= -6.0) && (((x_2 + (-1.0 * _x_x_18)) <= -4.0) && ((x_3 + (-1.0 * _x_x_18)) <= -16.0)))))))))))))) && (((x_25 + (-1.0 * _x_x_18)) == -16.0) || (((x_24 + (-1.0 * _x_x_18)) == -6.0) || (((x_22 + (-1.0 * _x_x_18)) == -16.0) || (((x_20 + (-1.0 * _x_x_18)) == -16.0) || (((x_18 + (-1.0 * _x_x_18)) == -4.0) || (((x_17 + (-1.0 * _x_x_18)) == -9.0) || (((x_15 + (-1.0 * _x_x_18)) == -12.0) || (((x_14 + (-1.0 * _x_x_18)) == -9.0) || (((x_12 + (-1.0 * _x_x_18)) == -4.0) || (((x_10 + (-1.0 * _x_x_18)) == -11.0) || (((x_7 + (-1.0 * _x_x_18)) == -13.0) || (((x_5 + (-1.0 * _x_x_18)) == -6.0) || (((x_2 + (-1.0 * _x_x_18)) == -4.0) || ((x_3 + (-1.0 * _x_x_18)) == -16.0)))))))))))))))) && ((((x_25 + (-1.0 * _x_x_19)) <= -14.0) && (((x_22 + (-1.0 * _x_x_19)) <= -10.0) && (((x_20 + (-1.0 * _x_x_19)) <= -19.0) && (((x_18 + (-1.0 * _x_x_19)) <= -19.0) && (((x_16 + (-1.0 * _x_x_19)) <= -17.0) && (((x_13 + (-1.0 * _x_x_19)) <= -4.0) && (((x_11 + (-1.0 * _x_x_19)) <= -1.0) && (((x_9 + (-1.0 * _x_x_19)) <= -3.0) && (((x_8 + (-1.0 * _x_x_19)) <= -12.0) && (((x_7 + (-1.0 * _x_x_19)) <= -20.0) && (((x_6 + (-1.0 * _x_x_19)) <= -6.0) && (((x_5 + (-1.0 * _x_x_19)) <= -12.0) && (((x_0 + (-1.0 * _x_x_19)) <= -5.0) && ((x_3 + (-1.0 * _x_x_19)) <= -17.0)))))))))))))) && (((x_25 + (-1.0 * _x_x_19)) == -14.0) || (((x_22 + (-1.0 * _x_x_19)) == -10.0) || (((x_20 + (-1.0 * _x_x_19)) == -19.0) || (((x_18 + (-1.0 * _x_x_19)) == -19.0) || (((x_16 + (-1.0 * _x_x_19)) == -17.0) || (((x_13 + (-1.0 * _x_x_19)) == -4.0) || (((x_11 + (-1.0 * _x_x_19)) == -1.0) || (((x_9 + (-1.0 * _x_x_19)) == -3.0) || (((x_8 + (-1.0 * _x_x_19)) == -12.0) || (((x_7 + (-1.0 * _x_x_19)) == -20.0) || (((x_6 + (-1.0 * _x_x_19)) == -6.0) || (((x_5 + (-1.0 * _x_x_19)) == -12.0) || (((x_0 + (-1.0 * _x_x_19)) == -5.0) || ((x_3 + (-1.0 * _x_x_19)) == -17.0)))))))))))))))) && ((((x_27 + (-1.0 * _x_x_20)) <= -10.0) && (((x_23 + (-1.0 * _x_x_20)) <= -1.0) && (((x_19 + (-1.0 * _x_x_20)) <= -7.0) && (((x_18 + (-1.0 * _x_x_20)) <= -5.0) && (((x_16 + (-1.0 * _x_x_20)) <= -13.0) && (((x_15 + (-1.0 * _x_x_20)) <= -16.0) && (((x_14 + (-1.0 * _x_x_20)) <= -13.0) && (((x_12 + (-1.0 * _x_x_20)) <= -10.0) && (((x_11 + (-1.0 * _x_x_20)) <= -12.0) && (((x_10 + (-1.0 * _x_x_20)) <= -17.0) && (((x_8 + (-1.0 * _x_x_20)) <= -15.0) && (((x_6 + (-1.0 * _x_x_20)) <= -7.0) && (((x_1 + (-1.0 * _x_x_20)) <= -7.0) && ((x_5 + (-1.0 * _x_x_20)) <= -12.0)))))))))))))) && (((x_27 + (-1.0 * _x_x_20)) == -10.0) || (((x_23 + (-1.0 * _x_x_20)) == -1.0) || (((x_19 + (-1.0 * _x_x_20)) == -7.0) || (((x_18 + (-1.0 * _x_x_20)) == -5.0) || (((x_16 + (-1.0 * _x_x_20)) == -13.0) || (((x_15 + (-1.0 * _x_x_20)) == -16.0) || (((x_14 + (-1.0 * _x_x_20)) == -13.0) || (((x_12 + (-1.0 * _x_x_20)) == -10.0) || (((x_11 + (-1.0 * _x_x_20)) == -12.0) || (((x_10 + (-1.0 * _x_x_20)) == -17.0) || (((x_8 + (-1.0 * _x_x_20)) == -15.0) || (((x_6 + (-1.0 * _x_x_20)) == -7.0) || (((x_1 + (-1.0 * _x_x_20)) == -7.0) || ((x_5 + (-1.0 * _x_x_20)) == -12.0)))))))))))))))) && ((((x_27 + (-1.0 * _x_x_21)) <= -16.0) && (((x_22 + (-1.0 * _x_x_21)) <= -2.0) && (((x_21 + (-1.0 * _x_x_21)) <= -9.0) && (((x_20 + (-1.0 * _x_x_21)) <= -13.0) && (((x_18 + (-1.0 * _x_x_21)) <= -8.0) && (((x_17 + (-1.0 * _x_x_21)) <= -11.0) && (((x_13 + (-1.0 * _x_x_21)) <= -5.0) && (((x_12 + (-1.0 * _x_x_21)) <= -16.0) && (((x_11 + (-1.0 * _x_x_21)) <= -5.0) && (((x_9 + (-1.0 * _x_x_21)) <= -6.0) && (((x_6 + (-1.0 * _x_x_21)) <= -10.0) && (((x_5 + (-1.0 * _x_x_21)) <= -12.0) && (((x_2 + (-1.0 * _x_x_21)) <= -14.0) && ((x_4 + (-1.0 * _x_x_21)) <= -5.0)))))))))))))) && (((x_27 + (-1.0 * _x_x_21)) == -16.0) || (((x_22 + (-1.0 * _x_x_21)) == -2.0) || (((x_21 + (-1.0 * _x_x_21)) == -9.0) || (((x_20 + (-1.0 * _x_x_21)) == -13.0) || (((x_18 + (-1.0 * _x_x_21)) == -8.0) || (((x_17 + (-1.0 * _x_x_21)) == -11.0) || (((x_13 + (-1.0 * _x_x_21)) == -5.0) || (((x_12 + (-1.0 * _x_x_21)) == -16.0) || (((x_11 + (-1.0 * _x_x_21)) == -5.0) || (((x_9 + (-1.0 * _x_x_21)) == -6.0) || (((x_6 + (-1.0 * _x_x_21)) == -10.0) || (((x_5 + (-1.0 * _x_x_21)) == -12.0) || (((x_2 + (-1.0 * _x_x_21)) == -14.0) || ((x_4 + (-1.0 * _x_x_21)) == -5.0)))))))))))))))) && ((((x_25 + (-1.0 * _x_x_22)) <= -8.0) && (((x_24 + (-1.0 * _x_x_22)) <= -12.0) && (((x_22 + (-1.0 * _x_x_22)) <= -16.0) && (((x_21 + (-1.0 * _x_x_22)) <= -19.0) && (((x_20 + (-1.0 * _x_x_22)) <= -16.0) && (((x_19 + (-1.0 * _x_x_22)) <= -18.0) && (((x_16 + (-1.0 * _x_x_22)) <= -19.0) && (((x_15 + (-1.0 * _x_x_22)) <= -14.0) && (((x_12 + (-1.0 * _x_x_22)) <= -6.0) && (((x_11 + (-1.0 * _x_x_22)) <= -1.0) && (((x_10 + (-1.0 * _x_x_22)) <= -14.0) && (((x_8 + (-1.0 * _x_x_22)) <= -16.0) && (((x_4 + (-1.0 * _x_x_22)) <= -10.0) && ((x_6 + (-1.0 * _x_x_22)) <= -18.0)))))))))))))) && (((x_25 + (-1.0 * _x_x_22)) == -8.0) || (((x_24 + (-1.0 * _x_x_22)) == -12.0) || (((x_22 + (-1.0 * _x_x_22)) == -16.0) || (((x_21 + (-1.0 * _x_x_22)) == -19.0) || (((x_20 + (-1.0 * _x_x_22)) == -16.0) || (((x_19 + (-1.0 * _x_x_22)) == -18.0) || (((x_16 + (-1.0 * _x_x_22)) == -19.0) || (((x_15 + (-1.0 * _x_x_22)) == -14.0) || (((x_12 + (-1.0 * _x_x_22)) == -6.0) || (((x_11 + (-1.0 * _x_x_22)) == -1.0) || (((x_10 + (-1.0 * _x_x_22)) == -14.0) || (((x_8 + (-1.0 * _x_x_22)) == -16.0) || (((x_4 + (-1.0 * _x_x_22)) == -10.0) || ((x_6 + (-1.0 * _x_x_22)) == -18.0)))))))))))))))) && ((((x_26 + (-1.0 * _x_x_23)) <= -12.0) && (((x_25 + (-1.0 * _x_x_23)) <= -9.0) && (((x_24 + (-1.0 * _x_x_23)) <= -7.0) && (((x_17 + (-1.0 * _x_x_23)) <= -10.0) && (((x_15 + (-1.0 * _x_x_23)) <= -12.0) && (((x_14 + (-1.0 * _x_x_23)) <= -15.0) && (((x_12 + (-1.0 * _x_x_23)) <= -12.0) && (((x_11 + (-1.0 * _x_x_23)) <= -16.0) && (((x_9 + (-1.0 * _x_x_23)) <= -10.0) && (((x_7 + (-1.0 * _x_x_23)) <= -6.0) && (((x_6 + (-1.0 * _x_x_23)) <= -10.0) && (((x_4 + (-1.0 * _x_x_23)) <= -6.0) && (((x_2 + (-1.0 * _x_x_23)) <= -18.0) && ((x_3 + (-1.0 * _x_x_23)) <= -1.0)))))))))))))) && (((x_26 + (-1.0 * _x_x_23)) == -12.0) || (((x_25 + (-1.0 * _x_x_23)) == -9.0) || (((x_24 + (-1.0 * _x_x_23)) == -7.0) || (((x_17 + (-1.0 * _x_x_23)) == -10.0) || (((x_15 + (-1.0 * _x_x_23)) == -12.0) || (((x_14 + (-1.0 * _x_x_23)) == -15.0) || (((x_12 + (-1.0 * _x_x_23)) == -12.0) || (((x_11 + (-1.0 * _x_x_23)) == -16.0) || (((x_9 + (-1.0 * _x_x_23)) == -10.0) || (((x_7 + (-1.0 * _x_x_23)) == -6.0) || (((x_6 + (-1.0 * _x_x_23)) == -10.0) || (((x_4 + (-1.0 * _x_x_23)) == -6.0) || (((x_2 + (-1.0 * _x_x_23)) == -18.0) || ((x_3 + (-1.0 * _x_x_23)) == -1.0)))))))))))))))) && ((((x_27 + (-1.0 * _x_x_24)) <= -3.0) && (((x_26 + (-1.0 * _x_x_24)) <= -11.0) && (((x_22 + (-1.0 * _x_x_24)) <= -19.0) && (((x_17 + (-1.0 * _x_x_24)) <= -18.0) && (((x_16 + (-1.0 * _x_x_24)) <= -18.0) && (((x_15 + (-1.0 * _x_x_24)) <= -15.0) && (((x_13 + (-1.0 * _x_x_24)) <= -2.0) && (((x_12 + (-1.0 * _x_x_24)) <= -14.0) && (((x_10 + (-1.0 * _x_x_24)) <= -11.0) && (((x_9 + (-1.0 * _x_x_24)) <= -1.0) && (((x_8 + (-1.0 * _x_x_24)) <= -1.0) && (((x_3 + (-1.0 * _x_x_24)) <= -15.0) && (((x_0 + (-1.0 * _x_x_24)) <= -17.0) && ((x_1 + (-1.0 * _x_x_24)) <= -12.0)))))))))))))) && (((x_27 + (-1.0 * _x_x_24)) == -3.0) || (((x_26 + (-1.0 * _x_x_24)) == -11.0) || (((x_22 + (-1.0 * _x_x_24)) == -19.0) || (((x_17 + (-1.0 * _x_x_24)) == -18.0) || (((x_16 + (-1.0 * _x_x_24)) == -18.0) || (((x_15 + (-1.0 * _x_x_24)) == -15.0) || (((x_13 + (-1.0 * _x_x_24)) == -2.0) || (((x_12 + (-1.0 * _x_x_24)) == -14.0) || (((x_10 + (-1.0 * _x_x_24)) == -11.0) || (((x_9 + (-1.0 * _x_x_24)) == -1.0) || (((x_8 + (-1.0 * _x_x_24)) == -1.0) || (((x_3 + (-1.0 * _x_x_24)) == -15.0) || (((x_0 + (-1.0 * _x_x_24)) == -17.0) || ((x_1 + (-1.0 * _x_x_24)) == -12.0)))))))))))))))) && ((((x_25 + (-1.0 * _x_x_25)) <= -19.0) && (((x_23 + (-1.0 * _x_x_25)) <= -8.0) && (((x_20 + (-1.0 * _x_x_25)) <= -15.0) && (((x_18 + (-1.0 * _x_x_25)) <= -11.0) && (((x_15 + (-1.0 * _x_x_25)) <= -18.0) && (((x_10 + (-1.0 * _x_x_25)) <= -15.0) && (((x_9 + (-1.0 * _x_x_25)) <= -2.0) && (((x_8 + (-1.0 * _x_x_25)) <= -19.0) && (((x_5 + (-1.0 * _x_x_25)) <= -1.0) && (((x_4 + (-1.0 * _x_x_25)) <= -11.0) && (((x_3 + (-1.0 * _x_x_25)) <= -19.0) && (((x_2 + (-1.0 * _x_x_25)) <= -16.0) && (((x_0 + (-1.0 * _x_x_25)) <= -9.0) && ((x_1 + (-1.0 * _x_x_25)) <= -1.0)))))))))))))) && (((x_25 + (-1.0 * _x_x_25)) == -19.0) || (((x_23 + (-1.0 * _x_x_25)) == -8.0) || (((x_20 + (-1.0 * _x_x_25)) == -15.0) || (((x_18 + (-1.0 * _x_x_25)) == -11.0) || (((x_15 + (-1.0 * _x_x_25)) == -18.0) || (((x_10 + (-1.0 * _x_x_25)) == -15.0) || (((x_9 + (-1.0 * _x_x_25)) == -2.0) || (((x_8 + (-1.0 * _x_x_25)) == -19.0) || (((x_5 + (-1.0 * _x_x_25)) == -1.0) || (((x_4 + (-1.0 * _x_x_25)) == -11.0) || (((x_3 + (-1.0 * _x_x_25)) == -19.0) || (((x_2 + (-1.0 * _x_x_25)) == -16.0) || (((x_0 + (-1.0 * _x_x_25)) == -9.0) || ((x_1 + (-1.0 * _x_x_25)) == -1.0)))))))))))))))) && ((((x_26 + (-1.0 * _x_x_26)) <= -15.0) && (((x_25 + (-1.0 * _x_x_26)) <= -6.0) && (((x_22 + (-1.0 * _x_x_26)) <= -6.0) && (((x_19 + (-1.0 * _x_x_26)) <= -19.0) && (((x_18 + (-1.0 * _x_x_26)) <= -13.0) && (((x_16 + (-1.0 * _x_x_26)) <= -20.0) && (((x_13 + (-1.0 * _x_x_26)) <= -19.0) && (((x_12 + (-1.0 * _x_x_26)) <= -20.0) && (((x_9 + (-1.0 * _x_x_26)) <= -5.0) && (((x_8 + (-1.0 * _x_x_26)) <= -17.0) && (((x_7 + (-1.0 * _x_x_26)) <= -13.0) && (((x_5 + (-1.0 * _x_x_26)) <= -18.0) && (((x_3 + (-1.0 * _x_x_26)) <= -8.0) && ((x_4 + (-1.0 * _x_x_26)) <= -16.0)))))))))))))) && (((x_26 + (-1.0 * _x_x_26)) == -15.0) || (((x_25 + (-1.0 * _x_x_26)) == -6.0) || (((x_22 + (-1.0 * _x_x_26)) == -6.0) || (((x_19 + (-1.0 * _x_x_26)) == -19.0) || (((x_18 + (-1.0 * _x_x_26)) == -13.0) || (((x_16 + (-1.0 * _x_x_26)) == -20.0) || (((x_13 + (-1.0 * _x_x_26)) == -19.0) || (((x_12 + (-1.0 * _x_x_26)) == -20.0) || (((x_9 + (-1.0 * _x_x_26)) == -5.0) || (((x_8 + (-1.0 * _x_x_26)) == -17.0) || (((x_7 + (-1.0 * _x_x_26)) == -13.0) || (((x_5 + (-1.0 * _x_x_26)) == -18.0) || (((x_3 + (-1.0 * _x_x_26)) == -8.0) || ((x_4 + (-1.0 * _x_x_26)) == -16.0)))))))))))))))) && ((((x_27 + (-1.0 * _x_x_27)) <= -4.0) && (((x_26 + (-1.0 * _x_x_27)) <= -17.0) && (((x_21 + (-1.0 * _x_x_27)) <= -5.0) && (((x_20 + (-1.0 * _x_x_27)) <= -5.0) && (((x_17 + (-1.0 * _x_x_27)) <= -4.0) && (((x_16 + (-1.0 * _x_x_27)) <= -14.0) && (((x_13 + (-1.0 * _x_x_27)) <= -15.0) && (((x_12 + (-1.0 * _x_x_27)) <= -17.0) && (((x_11 + (-1.0 * _x_x_27)) <= -20.0) && (((x_10 + (-1.0 * _x_x_27)) <= -9.0) && (((x_4 + (-1.0 * _x_x_27)) <= -2.0) && (((x_3 + (-1.0 * _x_x_27)) <= -3.0) && (((x_0 + (-1.0 * _x_x_27)) <= -5.0) && ((x_2 + (-1.0 * _x_x_27)) <= -5.0)))))))))))))) && (((x_27 + (-1.0 * _x_x_27)) == -4.0) || (((x_26 + (-1.0 * _x_x_27)) == -17.0) || (((x_21 + (-1.0 * _x_x_27)) == -5.0) || (((x_20 + (-1.0 * _x_x_27)) == -5.0) || (((x_17 + (-1.0 * _x_x_27)) == -4.0) || (((x_16 + (-1.0 * _x_x_27)) == -14.0) || (((x_13 + (-1.0 * _x_x_27)) == -15.0) || (((x_12 + (-1.0 * _x_x_27)) == -17.0) || (((x_11 + (-1.0 * _x_x_27)) == -20.0) || (((x_10 + (-1.0 * _x_x_27)) == -9.0) || (((x_4 + (-1.0 * _x_x_27)) == -2.0) || (((x_3 + (-1.0 * _x_x_27)) == -3.0) || (((x_0 + (-1.0 * _x_x_27)) == -5.0) || ((x_2 + (-1.0 * _x_x_27)) == -5.0)))))))))))))))) && ((_EL_X_2376 == (7.0 <= (_x_x_1 + (-1.0 * _x_x_9)))) && ((_EL_U_2379 == (_x__EL_U_2379 || (15.0 <= (_x_x_21 + (-1.0 * _x_x_23))))) && (_EL_X_2381 == ( !(_x__EL_U_2379 || (15.0 <= (_x_x_21 + (-1.0 * _x_x_23)))))))));
_EL_X_2376 = _x__EL_X_2376;
_EL_X_2381 = _x__EL_X_2381;
x_7 = _x_x_7;
x_8 = _x_x_8;
x_24 = _x_x_24;
x_9 = _x_x_9;
x_2 = _x_x_2;
x_0 = _x_x_0;
x_3 = _x_x_3;
x_18 = _x_x_18;
x_4 = _x_x_4;
x_19 = _x_x_19;
x_10 = _x_x_10;
x_22 = _x_x_22;
x_11 = _x_x_11;
x_25 = _x_x_25;
x_12 = _x_x_12;
_EL_U_2379 = _x__EL_U_2379;
x_13 = _x_x_13;
x_16 = _x_x_16;
x_17 = _x_x_17;
x_20 = _x_x_20;
x_21 = _x_x_21;
x_26 = _x_x_26;
x_1 = _x_x_1;
x_27 = _x_x_27;
x_15 = _x_x_15;
x_6 = _x_x_6;
x_14 = _x_x_14;
x_23 = _x_x_23;
x_5 = _x_x_5;
}
}
|
the_stack_data/14201541.c | #include<stdio.h>
void ft_ft(int *nbr);
int main(void)
{
int *a;
int b;
a = &b;
ft_ft(a);
printf("%d", *a);
return (0);
}
|
the_stack_data/248579750.c | #include<stdio.h>
int main()
{
long int n,s,sum=0,sum2;
int k,w,i;
scanf("%d%ld%d",&k,&n,&w);
for(i=1; i<=w; i++)
{
sum+=i*k;
}
if(sum>n){
sum2 = sum-n;
printf("%d\n",sum2);
}
else
{
printf("%d\n",0);
}
return 0;
}
|
the_stack_data/137350.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <unistd.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <time.h>
#include <ctype.h>
#define port 4444
int main(int argc, char const *argv[])
{
FILE *fp;
char filename[100], c;
int clientsocket;
struct sockaddr_in server_address;
char message[1024], Reply[200], String[256];
clientsocket = socket(AF_INET, SOCK_STREAM, 0);
//check connection
if(clientsocket < 0){
printf("Socket creation failed.\n");
exit(1);
}
//using the socket server address
//soocket family
server_address.sin_family = AF_INET;
//socket type
server_address.sin_addr.s_addr = inet_addr("127.0.0.1");
//socket port
server_address.sin_port = htons(port);
//Initializing connection to the server
int connection_status = connect(clientsocket, (struct sockaddr *)&server_address,sizeof(server_address));
if(connection_status < 0){
printf("Connection Failed\n");
exit(1);
}
printf("Connected to Server\n");
printf("Enter Command to Execute\n\":check\" to check Progress of busylist\n\":exit\" to Close connection\n");
int number = 0;
int mainly = 0;
//infinite loop for the client so that the client is able to enter input at any momen
while(1){
printf("\n\nClient: ");
gets(message);
int qp = 0;
int count = 0;
char *p = strtok(message, ";");
while(p!=NULL){
send(clientsocket, p, 1024, 0);
p = strtok(NULL, ";");
number++;
}
//if the input by the client is exit, then disconnect from the server
if(strcmp(message, ":exit")==0){
printf("Disconnected from the server\n");
exit(1);
}
if(strcmp(message, ":check")==0){
fp = fopen("/var/www/html/Recess/waiting.txt", "r");
for(c= getc(fp);c!=EOF; c=getc(fp))
if(c=='\n')
count = count + 1;
fclose(fp);
if(count>2){
printf("\n");
for(qp;qp<3;qp++){
recv(clientsocket, Reply, 1024, 0);
printf("Feedback: %s\n", Reply);
}
}
goto A;
}
A:
for(mainly;mainly<number;mainly++){
recv(clientsocket, Reply, 1024, 0);
char marvelo[500];
strcpy(marvelo, Reply);
char none = Reply[0];
if(isdigit(none)){
int mok = atoi(Reply);
printf("\nFeedback: ");
for(int counter = 0;counter<mok;counter++){
recv(clientsocket, Reply, 1024, 0);
printf("%s", Reply);
}
}else{
printf("\nFeedback: %s", marvelo);
}
}
}
return 0;
} |
the_stack_data/100139912.c | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* This file is part of the program and library */
/* SCIP --- Solving Constraint Integer Programs */
/* */
/* Copyright (C) 2002-2019 Konrad-Zuse-Zentrum */
/* fuer Informationstechnik Berlin */
/* */
/* SCIP is distributed under the terms of the ZIB Academic License. */
/* */
/* You should have received a copy of the ZIB Academic License */
/* along with SCIP; see the file COPYING. If not visit scip.zib.de. */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**@file xternal_vrp.c
* @brief main document page of VRP example
* @author Andreas Bley
*/
/*--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
/**@page VRP_MAIN Vehicle Routing
* @version 0.1
* @author Andreas Bley
*
*
* We want to solve the vehicle routing problem (VRP) on a graph \f$G = (V,E)\f$ with \f$V = J \cup {d}\f$, where
* \f$d\f$ is the depot and the distances are given by the length function \f$l_e: E \to R_{\ge 0}\f$.
*
* Consider the MIP formulation
*
* \f[
* \begin{array}[t]{rll}
* \min & \displaystyle \sum_{e \in E} l_e y_e \\
* & & \\
* s.t. & -y_e + \sum_{t \in T_k} a^t_e x_t \leq 0, & \forall e \in E\\
* & \displaystyle \sum_{t \in T_k} a^t_j x_t = 1, & \forall j \in J \\
* & y(\delta(j)) = 2, & \forall j \in J \\
* & y_e \in \{0,1,2\}, & \forall e \in E \\
* & x_t \in [0,1], & \forall t \in T_k
* \end{array}
* \f]
*
* where \f$T_k\f$ is the set of tours visiting at most \f$k\f$ customers with repetitions of customers allowed and
* \f$a^t_e (a^t_j)\f$ counts how often edge e (node j) is traversed in \f$t \in T_k\f$. The model contains two types of
* variables, namely \f$ x \f$ which selects tours fractionally and \f$ y \f$ which indicates which edges of the graph
* are in at least one selected tour. Note that it is possible to use an edge as a forward and backward edge in a tour.
* This is necessary to ensure that a customer \f$ j \f$ with \f$ |\delta(j)| = 1 \f$ can be served.
*
* Since the number of tours can be exponential in the size of the graph, the algorithm starts with some subset \f$
* \bar{T} \subseteq T_k \f$ and adds further tours during the solution process. This way it tries to improve the
* current LP solution.
*
* Let \f$ \lambda_e \f$ and \f$ \gamma_i \f$ be the dual multipliers for the first and seconds constraint of the
* MIP and we define the costs of a tour \f$ T \in T_k \f$ as:
* \f[
* C(T) := \sum_{e \in E(T)} \lambda_e - \sum_{j \in V(T)} \gamma_j
* \f]
*
* The resulting pricing problem \f$ \min_{T \in T_k} C(T) \f$ can be solved with dynamic programming. The algorithm is
* similar to Dijkstra's shortest path algorithm if we shift the the costs \f$ \gamma_j \f$ from the nodes to the edges
* of \f$ G \f$.
*
* Branching decisions on the variables \f$ y \f$ modify the pricing problem only slightly. The branch \f$ y_e = 0\f$
* forbids \f$ e \f$ to be contained in a tour which can be easily realized if we remove \f$ e \f$ from \f$ E \f$. The
* branch \f$ y_e \ge 1 \f$ does not have an impact on the pricing problem.
*
* Further information about the pricing routine and the dynamic program can be found in the documentation of the
* corresponding files.
*
* The pricer pricer_vrp.cpp shows how to perform column generation in SCIP and how to solve the above described pricing
* problem which uses an implementation of a priority queue implemented in pqueue.h. In main_vrp.cpp we read the
* instance, create all necessary data and set up SCIP.
*
* Installation
* ------------
*
* See the @ref INSTALL_APPLICATIONS_EXAMPLES "Install file"
*/
|
the_stack_data/110416.c |
#include <stdio.h>
int main(void) {
//Signed Integer, size depends on the computer system!
//Typically one machine size for a word
int a; //declaration only
int b,c,d; //multiple declarations
int e = 0; //declaration and assignment
int f, g = 30; //valid
int h = 301, i = 30; //valid
/* sizeof of returns the size of the data type */
printf("The size of an int is %d bytes or %d bits.\n",
sizeof(h), sizeof(h) * 8);
return 0; //Returning 0 means everything is OK.
}
|
the_stack_data/103264472.c | int main()
{
char a;
char b = a = 'a';
assert(a=='a');
assert(b=='a');
int i=(long int)&i;
}
|
the_stack_data/377102.c | //
// Created by fengyingcai on 2017/5/3.
//
// 中国剩余定理,同余
// k % 23 = p % 23 , k % 28 = e % 28, k % 33 = i % 33
// k = p (mod 23), k = e (mod 28), k = i (mod 33)
// x = ai (mod mi)
// 若 m(i) 互质,则在 mod M = m1 * m2 ... * mn 上有整数解,为
// x = (a1 * M1 * N1 + ... + an * Mn * Nn)
// Mi = M / mi ,Ni 为 Mi 逆元 (即 Ni * Mi = 1 (mod mi))
// Ni 通过扩展欧几里德公式求解
#include <stdio.h>
// 扩展欧几里德求 a 逆元 x
int egcd(int a, int b, int *x, int *y)
{
int r;
int tmp;
if (b==0) {
*x = 1;
*y = 0;
return a;
}
r = egcd(b, a%b, x, y);
tmp = *x;
*x = *y;
*y = tmp - a/b * (*y);
return *x;
}
// 中国剩余定理
int crl(int p, int e, int i, int d)
{
int next, x, y;
int m[] = {23, 28, 33};
int M = 23 * 28 * 33;
int M1 = M / 23;
int M2 = M / 28;
int M3 = M / 33;
next += (M1*egcd(M1, 23, &x, &y) % M + M) * p;
next += (M2*egcd(M2, 28, &x, &y) % M + M) * e;
next += (M3*egcd(M3, 33, &x, &y) % M + M) * i;
next = (next - d + M) % M;
if (next == 0)
next = M;
return next;
}
// 简单枚举,以 1 为步长
int force(int p, int e, int i, int d)
{
int next;
int step = 1;
next = d+1;
while (1)
{
if ((next-p)%23==0 && (next-e)%28==0 && (next-i)%33==0)
break;
next += step;
}
return next;
}
// 暴力枚举,以 33 为步长
int force2(int p, int e, int i, int d)
{
int next;
int step = 33;
// 求 33 的下个峰点
next = i;
while (next < d)
next += step;
// 以 33 为步长
while (1)
{
if ((next-p)%23==0 && (next-e)%28==0)
break;
next += step;
}
next -= d;
return next;
}
// 暴力枚举,并加速
// 先求 23 与 28 的共同高点 x
// x = 23i + p, x = 28j + e , 则 i = (28j + e - p) / 23 为整数
// 枚举先求最小j
int force3(int p, int e, int i, int d)
{
int next;
int j = 0;
int step = 23 * 28 / 1; // 最大公约数为 1
// 求 j 和 next 初值
while ((28*j + e - p)%23 != 0)
j++;
next = 28*j + e;
while (next < d)
next += step;
while(1)
{
if ((next-i)%33 == 0)
break;
next += step;
}
next = (next - d) % 21252;
if (next==0)
next = 21252;
return next;
}
int main(void)
{
int p, e, i, d;
int next;
int count = 0;
while (1) {
scanf("%d %d %d %d", &p, &e, &i, &d);
if (p==-1 && e==-1 && i==-1 && d==-1)
break;
// 计算 next
next = force3(p, e, i, d);
printf("Case %d: the next triple peak occurs in %d days.\n", ++count, next);
}
}
|
the_stack_data/234519243.c | #include <stdio.h>
int main(int argc, char const *argv[])
{
int i;
int kar[5];
int sum;
for (i=0; i<5; i++){
printf("Prøve %d:\n", i+1);
scanf("%d", &kar[i]);
}
for (i=0; i<5; i++){
sum = sum+kar[i];
}
float g = (float)sum/5;
if (g <= 39){
printf("%.1f%% gir F!\n", g);
} else if (g >= 40 || g <= 49){
printf("%.1f%% gir E\n", g);
} else if (g >= 50 || g <= 59){
printf("%.1f%% gir D\n", g);
} else if (g >= 60 || g <= 79){
printf("%.1f%% gir C\n", g);
} else if (g >= 80 || g <= 89){
printf("%.1f%% gir B\n", g);
} else if (g >= 90 || g <= 100){
printf("%.1f%% gir A!\n", g);
} else {
printf("Juks!\n");
}
return 0;
} |
the_stack_data/21425.c | #include <stdio.h>
int main()
{
int n = 5, x = n*(n+1)/2;
for(int i = 1; i <= n; i++) {
for(int j = n; j >= i; j--) {
printf("%2d ", x--);
}
printf("\n");
}
return 0;
} |
the_stack_data/148577543.c | /* **********************************************************
* Copyright (c) 2003 VMware, Inc. All rights reserved.
* **********************************************************/
/*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of VMware, Inc. 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 VMWARE, INC. 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.
*/
/*
* test of fork
*/
#include <sys/types.h>
#include <unistd.h>
#include <sys/types.h> /* for wait and mmap */
#include <sys/wait.h> /* for wait */
#include <assert.h>
#include <stdio.h>
const int N = 8;
/***************************************************************************/
int fib(int n) {
if (n <= 1) return 1;
return fib(n-1) + fib(n-2);
}
#ifdef DEBUG
# define pf printf
#else
# define pf if(0)printf
#endif
int main(int argc, char** argv)
{
pid_t child1, child2;
int do_vfork = 1; //argc == 1;
int n, sum = 0;
int result;
char *arg[5];
char **env = NULL;
char carg[10], csum[10];
if (find_dynamo_library())
printf("rio\n");
else
printf("native\n");
//printf("%d %s %s %s\n", argc, argv[0], argv[1], argv[2]);
if (argc < 3) { // start calculation
if (2 == argc) // vfork-fib 10
n = atoi(argv[1]);
else
n = N;
printf("parent fib(%d)=%d\n", n, fib(n));
sum = 0;
} else {
assert(argc == 3); // vfork-fib fib 10
n = atoi(argv[2]);
sum = 0;
}
pf("\tfib %d\n", n);
if (n <= 1) { // base case
pf("base case\n");
_exit(1);
}
// now spawn two children
arg[0] = argv[0];
arg[1] = "fib";
arg[3] = NULL;
if (do_vfork) { /* default */
pf("using vfork()\n");
child1 = vfork();
} else {
pf("using fork()\n");
child1 = fork();
}
if (child1 < 0) {
perror("ERROR on fork");
} else if (child1 == 0) {
snprintf(carg, 10, "%d", n-2);
arg[2] = carg;
#if 0
pf("execing %d %s %s=%s %s\n",
3, arg[0], carg, arg[1], arg[2]);
#endif
result = execve(arg[0], arg, env);
if (result < 0)
perror("ERROR in execve");
} else {
pid_t result;
int status;
int children = 2;
if (do_vfork) { /* default */
pf("second child using vfork()\n");
child2 = vfork();
} else {
pf("second child using fork()\n");
child2 = fork();
}
if (child2 < 0) {
perror("ERROR on fork");
} else if (child2 == 0) {
snprintf(carg, 10, "%d", n-1);
arg[2] = carg;
result = execve(arg[0], arg, env);
if (result < 0) perror("ERROR in execve");
}
while(children > 0) {
pf("parent waiting for %d children\n", children);
result = wait(&status);
assert(result == child2 || result == child1);
assert(WIFEXITED(status));
//printf("child %d has exited with status=%d %d\n", result, status, WEXITSTATUS(status));
sum+=WEXITSTATUS(status);
if (children == 2 && result == child1)
pf("first child before second\n");
else
pf("second child before first\n");
children--;
}
#if 0
result = waitpid(child2, &status, 0);
assert(result == child2);
assert(WIFEXITED(status));
pf("child2 has exited with status=%d %d\n", status, WEXITSTATUS(status));
sum+=WEXITSTATUS(status);
pf("parent waiting for child1 %d\n", child1);
result = waitpid(child1, &status, 0);
assert(result == child1);
assert(WIFEXITED(status));
pf("child1 has exited with status=%d %d\n", status, WEXITSTATUS(status));
sum+=WEXITSTATUS(status);
#endif
}
#ifdef DEBUG
printf("\tfib(%d)=%d [%d] %s\n", n, sum, fib(n), sum == fib(n) ? "OK" : "BAD");
#else
if (argc == 1)
printf("\tfib(%d)=%d [%d] %s\n", n, sum, fib(n), sum == fib(n) ? "OK" : "BAD");
#endif
_exit(sum);
}
// TODO it would be nice to have in the tests a measure for nondeterminism
// to also a guarantee that we don't introduce extra synchronization to stifle any parallelism
|
the_stack_data/129194.c | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define MAX 200
int is_prime(int);
int compattarray(int [], int);
int main(int argc, char * argv[]) {
int * vals, dim, i, new_dim;
do{
scanf("%d", &dim);
} while(dim<1 && dim>MAX);
vals = malloc(sizeof(int) * dim);
for(i=0; i<dim; i++)
scanf("%d", (vals+i));
new_dim = compattarray(vals, dim);
for(i=0; i<new_dim; i++)
printf("%d\t", *(vals+i));
printf("\n");
return 0;
}
int is_prime(int n) {
int i, prime, sqrt_n;
if(n<2 || n%2==0)
prime = 0;
else if(n == 2)
prime = 1;
else {
sqrt_n = sqrt(n);
prime = 1;
for(i=3; i<=sqrt(n) && prime; i+=2);
prime = (n%i!=0);
}
return prime;
}
int compattarray(int arr[], int dim) {
int i, j, new_dim;
new_dim = dim;
for(i=0; i<new_dim; i++)
if(!is_prime(arr[i])) {
for(j=i+1; j<new_dim; j++)
arr[j-1] = arr[j];
new_dim--;
i--;
}
return new_dim;
}
|
the_stack_data/190767640.c | /**
* BOJ 14425번 C언어 소스 코드
* 작성자 : 동동매니저 (DDManager)
*
* ※ 실행 결과
* 사용 메모리 : 6,336 KB / 1,572,864 KB
* 소요 시간 : 128 ms / 2,000 ms
*
* Copyright 2020. DDManager all rights reserved.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define TABLE_SIZE 9973
typedef struct Element{
char key[501];
}Element;
typedef struct HashList{
Element item;
struct HashList *link;
}HashList;
HashList *ht[TABLE_SIZE];
int hash_function(char *str){
int len=strlen(str);
int hash=0,g=1;
int i;
for(i=1;i<=len;i++){
hash+=str[len-i]*g;
g*=31;
}
return (unsigned)hash%TABLE_SIZE;
}
void hash_chain_add(Element item){
int hash_value=hash_function(item.key);
HashList *ptr;
HashList *node_before=NULL,*node=ht[hash_value];
for(;node;node_before=node,node=node->link);
ptr=(HashList*)malloc(sizeof(HashList));
ptr->item=item;
ptr->link=NULL;
if(node_before) node_before->link=ptr;
else ht[hash_value]=ptr;
}
int hash_chain_search(Element item){
HashList *node;
int hash_value=hash_function(item.key);
for(node=ht[hash_value];node;node=node->link)
if(strcmp(node->item.key,item.key)==0) return 1;
return 0;
}
int main(void){
int N,M;
Element elem;
int answer=0;
int i;
scanf("%d %d",&N,&M);
for(i=0;i<N;i++){
scanf("%s",elem.key);
hash_chain_add(elem);
}
for(i=0;i<M;i++){
scanf("%s",elem.key);
answer+=hash_chain_search(elem);
}
printf("%d\n",answer);
return 0;
} |
the_stack_data/198582062.c | #include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
struct alarm
{
struct alarm *link;
int seconds;
time_t time; /* seconds from EPOCH */
char message[64];
};
pthread_mutex_t alarm_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t alarm_cond = PTHREAD_COND_INITIALIZER;
struct alarm *alarm_list = NULL;
time_t current_alarm = 0;
/*
* Insert alarm entry on list, in order.
*/
void
alarm_insert (struct alarm *alarm)
{
int status;
struct alarm **last, *next;
/*
* LOCKING PROTOCOL:
*
* This routine requires that the caller have locked the
* alarm_mutex!
*/
last = &alarm_list;
next = *last;
while (next != NULL)
{
if (next->time >= alarm->time)
{
alarm->link = next;
*last = alarm;
break;
}
last = &next->link;
next = next->link;
}
/*
* If we reached the end of the list, insert the new alarm
* there. ("next" is NULL, and "last" points to the link
* field of the last item, or to the list header.)
*/
if (next == NULL)
{
*last = alarm;
alarm->link = NULL;
}
#ifdef DEBUG
printf ("[list: ");
for (next = alarm_list; next != NULL; next = next->link)
printf ("%d(%d)[\"%s\"] ", next->time, next->time - time (NULL),
next->message);
printf ("]\n");
#endif
/*
* Wake the alarm thread if it is not busy (that is, if
* current_alarm is 0, signifying that it's waiting for
* work), or if the new alarm comes before the one on
* which the alarm thread is waiting.
*/
if (current_alarm == 0 || alarm->time < current_alarm)
{
current_alarm = alarm->time;
status = pthread_cond_signal (&alarm_cond);
if (status != 0)
perror ("pthread_cond_signal");
}
}
/*
* The alarm thread's start routine.
*/
void *
alarm_thread (void *arg)
{
struct alarm *alarm;
struct timespec cond_time;
time_t now;
int status, expired;
/*
* Loop forever, processing commands. The alarm thread will
* be disintegrated when the process exits. Lock the mutex
* at the start -- it will be unlocked during condition
* waits, so the main thread can insert alarms.
*/
status = pthread_mutex_lock (&alarm_mutex);
if (status != 0)
perror ("pthread_mutex_lock");
while (1)
{
/*
* If the alarm list is empty, wait until an alarm is
* added. Setting current_alarm to 0 informs the insert
* routine that the thread is not busy.
*/
current_alarm = 0;
while (alarm_list == NULL)
{
status = pthread_cond_wait (&alarm_cond, &alarm_mutex);
if (status != 0)
perror ("pthread_cond_wait");
}
alarm = alarm_list;
alarm_list = alarm->link;
now = time (NULL);
expired = 0;
if (alarm->time > now)
{
#ifdef DEBUG
printf ("[waiting: %d(%d)\"%s\"]\n", alarm->time,
alarm->time - time (NULL), alarm->message);
#endif
cond_time.tv_sec = alarm->time;
cond_time.tv_nsec = 0;
current_alarm = alarm->time;
while (current_alarm == alarm->time)
{
status = pthread_cond_timedwait (
&alarm_cond, &alarm_mutex, &cond_time);
if (status == ETIMEDOUT)
{
expired = 1;
break;
}
if (status != 0)
perror ("pthread_cond_timedwait");
}
if (!expired)
alarm_insert (alarm);
}
else
expired = 1;
if (expired)
{
printf ("(%d) %s\n", alarm->seconds, alarm->message);
free (alarm);
}
}
}
int
main (int argc, char *argv[])
{
int status;
char line[128];
struct alarm *alarm;
pthread_t thread;
status = pthread_create (&thread, NULL, alarm_thread, NULL);
if (status != 0)
perror ("pthread_create");
while (1)
{
printf ("Alarm> ");
if (fgets (line, sizeof (line), stdin) == NULL)
exit (0);
if (strlen (line) <= 1)
continue;
alarm = malloc (sizeof (struct alarm));
if (alarm == NULL)
perror ("malloc");
/*
* Parse input line into seconds (%d) and a message
* (%64[^\n]), consisting of up to 64 characters
* separated from the seconds by whitespace.
*/
if (sscanf (line, "%d %64[^\n]", &alarm->seconds, alarm->message)
< 2)
{
fprintf (stderr, "Bad command\n");
free (alarm);
}
else
{
status = pthread_mutex_lock (&alarm_mutex);
if (status != 0)
perror ("pthread_mutex_lock");
alarm->time = time (NULL) + alarm->seconds;
/*
* Insert the new alarm into the list of alarms,
* sorted by expiration time.
*/
alarm_insert (alarm);
status = pthread_mutex_unlock (&alarm_mutex);
if (status != 0)
perror ("pthread_mutex_unlock");
}
}
}
|
the_stack_data/15761905.c | #include <locale.h>
short CONSOLE_H;
short CONSOLE_W;
#ifdef _WIN32
#include <windows.h>
#include <io.h>
#include <stdio.h>
#include <fcntl.h>
void EnableControlCodes(void) {
DWORD consoleMode;
HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleMode(consoleHandle, &consoleMode);
consoleMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; // colour codes, cursor positioning - https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences
SetConsoleMode(consoleHandle, consoleMode);
}
BOOL unicodeSupported = FALSE;
BOOL CALLBACK checkUnicode(TCHAR* cp){
if(0 == strcmp(cp, "65001"))
unicodeSupported = TRUE;
return TRUE;
}
void FixCodepage(void) {
setlocale(LC_ALL, "");
EnumSystemCodePages(checkUnicode, CP_SUPPORTED);
if(unicodeSupported){
SetConsoleCP(CP_UTF8);
SetConsoleOutputCP(CP_UTF8);
_setmode(_fileno(stdout), _O_U8TEXT);
}
}
short GetConsoleSize(void){
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
// I don't think top and left are ever anything other than 1, but oh well
CONSOLE_H = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
CONSOLE_W = csbi.srWindow.Right - csbi.srWindow.Left + 1;
}
void platform_init(void){
EnableControlCodes();
GetConsoleSize();
FixCodepage();
}
short up_pressed(void){
return GetKeyState(VK_UP) & 0xF000; // GetKeyState returns short; higher order bit determines whether it's pressed
;
}
short w_pressed(void){
return GetKeyState('W') & 0xF000;
}
short s_pressed(void){
return GetKeyState('S') & 0xF000; // GetKeyState returns short; higher order bit determines whether it's pressed
;
}
short down_pressed(void){
return GetKeyState(VK_DOWN) & 0xF000;
}
#elif defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)) // http://web.archive.org/web/20160306052035/http://nadeausoftware.com/articles/2012/01/c_c_tip_how_use_compiler_predefined_macros_detect_operating_system#HowtodetectPOSIXandUNIX
void platform_init(void){}
// TODO
#else // end POSIX
void platform_init(void){
printf("What the fuck sort of OS are you running\nDon't even try this on Android or whatever\n");
exit(1);
}
#endif // end OS detection
|
the_stack_data/151704462.c | // standard h files
#include <stdbool.h>
#include <stdint.h>
#ifndef uint8_t
#define uint8_t unsigned char
#endif
#ifndef uint16_t
#define uint16_t unsigned short
#endif
#ifndef uint32_t
#define uint32_t unsigned int
#endif
#ifndef uint64_t
#define uint64_t unsigned long long
#endif
// structure types:
typedef union{
uint32_t raw32;
struct {
uint32_t field1:1;
uint32_t field2:1;
uint32_t field3:1;
uint32_t field4:1;
uint32_t field5:1;
uint32_t field6:1;
uint32_t field7:1;
uint32_t field8:1;
uint32_t field9:1;
uint32_t field10:1;
uint32_t field11:1;
uint32_t field12:1;
uint32_t field13:1;
uint32_t field14:1;
uint32_t field15:1;
uint32_t field16:1;
uint32_t field17:1;
uint32_t field18:1;
uint32_t field19:1;
uint32_t field20:1;
uint32_t field21:1;
uint32_t field22:1;
uint32_t field23:1;
uint32_t field24:1;
uint32_t field25:1;
uint32_t field26:1;
uint32_t field27:5;
uint32_t field28:1;
};
} str1_t;
typedef union{
uint32_t raw32;
struct {
uint32_t field1:32;
};
} str2_t;
extern str2_t extern_global_var1 ;
typedef union{
uint32_t raw32;
struct {
uint32_t saved_field1:2;
uint32_t field2:1;
};
} str3_t;
extern str3_t extern_global_var2;
struct str4_s {
bool bool_var;
};
typedef union {
struct
{
uint16_t field1 : 2;
uint16_t field2 : 1;
uint16_t field3 : 13;
};
uint16_t raw;
} str4_t;
typedef union
{
struct
{
uint16_t field1 : 4;
uint16_t s_field2 : 1;
uint16_t d_field3 : 2;
uint16_t p_field4 : 1;
uint16_t r_field5 : 3;
uint16_t null_field6 : 1;
uint16_t a_field7 : 1;
uint16_t l_field8 : 1;
uint16_t d_field9 : 1;
uint16_t g_field10 : 1;
};
uint16_t ar_raw;
} str5_t;
typedef union
{
struct
{
uint64_t field1;
str4_t field2;
str5_t field3;
uint32_t field4;
};
struct
{
uint64_t low64;
uint64_t high64;
};
} str6_t;
//function protoypes:
void func1(bool retain_var);
void func2(bool return_var, uint32_t u_var);
void func3(struct str4_s* var1_p);
void func4(void);
void func5(struct str4_s* var1_p);
bool func6(bool bool_var);
void func7(struct str4_s* var1_p);
void func3(struct str4_s* var1_p){
bool bool_var = var1_p->bool_var;
if(func6(bool_var)){
func5(var1_p);
}
}
void func4(){
extern_global_var1.raw32 += 1;
}
bool func6(bool bool_var){
return ((extern_global_var2.field2 !=0) || !bool_var);
}
void func5(struct str4_s* var1_p){
func7(var1_p);
}
void func7(struct str4_s* var1_p){
str6_t var1;
uint32_t var2 = var1.field3.d_field3;
}
int main(void) {
struct str4_s var;
var.bool_var = 1;
__ESBMC_assert(var.bool_var == 1, "Bool_var should be 1");
func3(&var);
return 0;
} |
the_stack_data/600251.c | // RUN: env LIBRARY_PATH=%T/test1 %clang -x c %s -### 2>&1 | FileCheck %s
// CHECK: "-L{{.*}}/test1"
// GCC driver is used as linker on cygming. It should be aware of LIBRARY_PATH.
// XFAIL: win32
// REQUIRES: clang-driver
|
the_stack_data/7951350.c | // Atribuindo valores em vetor usando ponteiros
#include <stdio.h>
int main(void){
int vetor[10], *p;
p = vetor;
for(register int i=0; i<10; i++){
*(p+i) = i;
//vetor[i] = i;
}
return 0;
} |
the_stack_data/1170503.c | //03. Write a program that asks for 3 numbers to the user and determinate the greater one. Take care of side posibilities (equal numbers).
#include <stdio.h>
int main()
{
int number01 = 0;
int number02 = 0;
int number03 = 0;
printf("Enter first number: ");
scanf_s("%i", &number01);
printf("Enter second number: ");
scanf_s("%i", &number02);
printf("Enter the third number: ");
scanf_s("%i", &number03);
if (((number01 == number02) || (number01 == number03) || (number02 == number03)))
{
printf("Two or more numbers are equal. Type 3 different numbers.\n");
}
if ((number01 >= number02) && (number01 >= number03))
{
printf("Number 1 (%i) is the biggest number.\n", number01);
}
if ((number02 >= number01) && (number02 >= number03))
{
printf("Number 2 (%i) is the biggest number.\n", number02);
}
if ((number03 >= number01) && (number03 >= number02))
{
printf("Number 3 (%i) is the biggest number.\n", number03);
}
getchar();
return 0;
} |
the_stack_data/50138617.c | #include<stdio.h>
#include<math.h>
int main(){
int t,n;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
if(n>1){
printf("%.3f\n",((4*n-4)+sqrt(2)*((n-2)*(n-2))));
}
else{
printf("0.000\n");
}
}
return 0;
}
|
the_stack_data/185646.c | struct test {
double asdf[3];
int jkl[2];
char nm[1];
};
int main() {
struct test t = { { 1.5, 2.5, 3.5 }, { 1, 2 }, { 'a' } };
return t.asdf[0] + t.asdf[1] + t.asdf[2] + t.jkl[0] + t.jkl[1] + t.nm[0];
}
|
the_stack_data/11074072.c | #include <stdio.h>
//http://blog.csdn.net/wangpeihuixyz/article/details/40593619
#define align(x, a) _align(x, (typeof(x))(a) - 1)
#define _align(x, mask) (((x) + (mask)) & ~(mask))
#define ROUND_UP(x, align) (((int) (x) + (align - 1)) & ~(align - 1))
#define ROUND_DOWN(x, align) ((int)(x) & ~(align - 1))
#define ALIGNED(x, align) (((int)(x) & (align - 1)) == 0)
int main(int argc, char* argv[])
{
int t, mask;
while (1) {
scanf("%d %d", &t, &mask);
printf("t=%d, mask=%d, result=%d\n", t, mask, align(t, mask));
printf("# t=%d, mask=%d, result=%d\n", t, mask, ROUND_UP(t, mask));
printf("$ t=%d, mask=%d, result=%d\n", t, mask, ROUND_DOWN(t, mask));
printf("%d %d\n", ALIGNED(align(t, mask), mask), ALIGNED(ROUND_UP(t, mask), mask));
}
return 0;
#if 0 //64 bit test
printf("sizeof(char) %d\n", sizeof(char)*8);
printf("sizeof(short) %d\n", sizeof(short)*8);
printf("sizeof(int) %d\n", sizeof(int)*8);
printf("sizeof(long) %d\n", sizeof(long)*8);
printf("sizeof(long long) %d\n", sizeof(long long)*8);
printf("sizeof(void*) %d\n", sizeof(void*)*8);
printf("sizeof(size_t) %d\n", sizeof(size_t)*8);
int i, *p, *q;
struct foo {
int i;
long j;
int x;
} st_foo;
p = &i;
q = (int *) (int)&i;
printf("p %p %lx, q %p %lx\n", p, p, q, q);
printf("sizeof(st_foo) %d %d\n", sizeof(struct foo), sizeof(st_foo));
return 0;
#endif
}
|
the_stack_data/225143370.c | // RUN: %clang_cc1 -triple riscv32 -emit-llvm %s -o - | FileCheck %s
// RUN: %clang_cc1 -triple riscv32 -target-feature +f -target-abi ilp32f -emit-llvm %s -o - \
// RUN: | FileCheck %s
// This file contains test cases that will have the same output for the ilp32
// and ilp32f ABIs.
#include <stddef.h>
#include <stdint.h>
struct tiny {
uint8_t a, b, c, d;
};
struct small {
int32_t a, *b;
};
struct small_aligned {
int64_t a;
};
struct large {
int32_t a, b, c, d;
};
// Scalars passed on the stack should not have signext/zeroext attributes
// (they are anyext).
// CHECK-LABEL: define i32 @f_scalar_stack_1(i32 %a, i64 %b, i32 %c, double %d, fp128 %e, i8 zeroext %f, i8 %g, i8 %h)
int f_scalar_stack_1(int32_t a, int64_t b, int32_t c, double d, long double e,
uint8_t f, int8_t g, uint8_t h) {
return g + h;
}
// Ensure that scalars passed on the stack are still determined correctly in
// the presence of large return values that consume a register due to the need
// to pass a pointer.
// CHECK-LABEL: define void @f_scalar_stack_2(%struct.large* noalias sret align 4 %agg.result, i32 %a, i64 %b, double %c, fp128 %d, i8 zeroext %e, i8 %f, i8 %g)
struct large f_scalar_stack_2(int32_t a, int64_t b, double c, long double d,
uint8_t e, int8_t f, uint8_t g) {
return (struct large){a, e, f, g};
}
// Aggregates and >=XLen scalars passed on the stack should be lowered just as
// they would be if passed via registers.
// CHECK-LABEL: define void @f_scalar_stack_3(double %a, i64 %b, double %c, i64 %d, i32 %e, i64 %f, i32 %g, double %h, fp128 %i)
void f_scalar_stack_3(double a, int64_t b, double c, int64_t d, int e,
int64_t f, int32_t g, double h, long double i) {}
// CHECK-LABEL: define void @f_agg_stack(double %a, i64 %b, double %c, i64 %d, i32 %e.coerce, [2 x i32] %f.coerce, i64 %g.coerce, %struct.large* %h)
void f_agg_stack(double a, int64_t b, double c, int64_t d, struct tiny e,
struct small f, struct small_aligned g, struct large h) {}
|
the_stack_data/15762695.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 'abs_diff_long4long4.cl' */
source_code = read_buffer("abs_diff_long4long4.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, "abs_diff_long4long4", &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_long4 *src_0_host_buffer;
src_0_host_buffer = malloc(num_elem * sizeof(cl_long4));
for (int i = 0; i < num_elem; i++)
src_0_host_buffer[i] = (cl_long4){{2, 2, 2, 2}};
/* Create and init device side src buffer 0 */
cl_mem src_0_device_buffer;
src_0_device_buffer = clCreateBuffer(context, CL_MEM_READ_ONLY, num_elem * sizeof(cl_long4), 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_long4), src_0_host_buffer, 0, NULL, NULL);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clEnqueueWriteBuffer' failed\n");
exit(1);
}
/* Create and init host side src buffer 1 */
cl_long4 *src_1_host_buffer;
src_1_host_buffer = malloc(num_elem * sizeof(cl_long4));
for (int i = 0; i < num_elem; i++)
src_1_host_buffer[i] = (cl_long4){{2, 2, 2, 2}};
/* Create and init device side src buffer 1 */
cl_mem src_1_device_buffer;
src_1_device_buffer = clCreateBuffer(context, CL_MEM_READ_ONLY, num_elem * sizeof(cl_long4), NULL, &ret);
if (ret != CL_SUCCESS)
{
printf("error: could not create source buffer\n");
exit(1);
}
ret = clEnqueueWriteBuffer(command_queue, src_1_device_buffer, CL_TRUE, 0, num_elem * sizeof(cl_long4), src_1_host_buffer, 0, NULL, NULL);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clEnqueueWriteBuffer' failed\n");
exit(1);
}
/* Create host dst buffer */
cl_ulong4 *dst_host_buffer;
dst_host_buffer = malloc(num_elem * sizeof(cl_ulong4));
memset((void *)dst_host_buffer, 1, num_elem * sizeof(cl_ulong4));
/* Create device dst buffer */
cl_mem dst_device_buffer;
dst_device_buffer = clCreateBuffer(context, CL_MEM_WRITE_ONLY, num_elem *sizeof(cl_ulong4), NULL, &ret);
if (ret != CL_SUCCESS)
{
printf("error: could not create dst buffer\n");
exit(1);
}
/* Set kernel arguments */
ret = CL_SUCCESS;
ret |= clSetKernelArg(kernel, 0, sizeof(cl_mem), &src_0_device_buffer);
ret |= clSetKernelArg(kernel, 1, sizeof(cl_mem), &src_1_device_buffer);
ret |= clSetKernelArg(kernel, 2, sizeof(cl_mem), &dst_device_buffer);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clSetKernelArg' failed\n");
exit(1);
}
/* Launch the kernel */
size_t global_work_size = num_elem;
size_t local_work_size = num_elem;
ret = clEnqueueNDRangeKernel(command_queue, kernel, 1, NULL, &global_work_size, &local_work_size, 0, NULL, NULL);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clEnqueueNDRangeKernel' failed\n");
exit(1);
}
/* Wait for it to finish */
clFinish(command_queue);
/* Read results from GPU */
ret = clEnqueueReadBuffer(command_queue, dst_device_buffer, CL_TRUE,0, num_elem * sizeof(cl_ulong4), 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_ulong4));
printf("Result dumped to %s\n", dump_file);
/* Free host dst buffer */
free(dst_host_buffer);
/* Free device dst buffer */
ret = clReleaseMemObject(dst_device_buffer);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clReleaseMemObject' failed\n");
exit(1);
}
/* Free host side src buffer 0 */
free(src_0_host_buffer);
/* Free device side src buffer 0 */
ret = clReleaseMemObject(src_0_device_buffer);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clReleaseMemObject' failed\n");
exit(1);
}
/* Free host side src buffer 1 */
free(src_1_host_buffer);
/* Free device side src buffer 1 */
ret = clReleaseMemObject(src_1_device_buffer);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clReleaseMemObject' failed\n");
exit(1);
}
/* Release kernel */
ret = clReleaseKernel(kernel);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clReleaseKernel' failed\n");
exit(1);
}
/* Release program */
ret = clReleaseProgram(program);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clReleaseProgram' failed\n");
exit(1);
}
/* Release command queue */
ret = clReleaseCommandQueue(command_queue);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clReleaseCommandQueue' failed\n");
exit(1);
}
/* Release context */
ret = clReleaseContext(context);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clReleaseContext' failed\n");
exit(1);
}
return 0;
} |
the_stack_data/998567.c | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define popsize 1000000
#define maxgens 50
#define runs 1
#define hole1 500
#define hole2 500
#define initsize 1000
#define BINS 500
int popdata[popsize], newpopdata[popsize], *pop = popdata, *newpop = newpopdata;
int sizes[maxgens][popsize];
int hist[maxgens][BINS];
int saves = 0;
int maxsize = 0;
/* Select a random individual and return it's length */
int sel()
{
int i;
i = pop[rand()%popsize];
return(i);
}
/* Perform crossover */
int xover( int p1, int p2 )
{
int x1, x2,r;
x1 = rand()&p1;
x2 = rand()&p2;
r = (x1 + (p2-x2));
return r;
}
double mean()
{
int i;
long int m = 0;
for ( i = 0; i< popsize; i ++)
m += pop[i];
return( (double) m / popsize );
}
/* Accumulate the size information for the runs
and remember the biggest size */
void save(int g)
{
int i;
for(i=0;i<popsize;i++) {
sizes[g][i]+=pop[i];
maxsize = pop[i]>maxsize ? pop[i] : maxsize;
}
saves++;
}
/* Calculate the histograms and dump them to the file */
void output()
{
FILE *fp;
int i;
int g;
int b;
int scale;
int bin;
int val;
char fname[1024];
int tmpmax;
printf("Calculating histograms (%d)\n", saves);
scale = 1;
tmpmax = maxsize;
while(tmpmax > BINS) {
tmpmax /=2;
scale *= 2;
}
/* Make the histograms */
for(g=0;g<saves;g++) {
for(i=0;i<popsize;i++) {
val = sizes[g][i];
val /= runs;
bin = val/scale;
/*printf("g=%d, i=%d, val=%d, bin=%d, raw=%d\n", g,i,val,bin, sizes[g][i]);*/
hist[g][bin]++;
}
}
for(g=0;g<saves;g++) {
sprintf(fname, "hist_%d.dat", g);
if((fp = fopen(fname, "w")) == NULL) {
perror("Creating data file");
fp = stdout;
}
for(b=0;b<BINS;b++) {
fprintf(fp, "%d %d\n", b*scale, hist[g][b]);
}
if(fp != stdout) {
fprintf(fp, "\n");
fclose(fp);
}
}
}
void initialise()
{
int i;
pop=popdata;
for ( i = 0; i< popsize; i ++) {
/*pop[i] = 40 + ((i&1)*40);*/ /*two-point initial condition*/
pop[i] = 1+(rand()&31);
/* pop[i] = 1+(i%10);*/
}
saves = 0;
}
int main(int argc, char ** argv)
{
int i, g, r, *tmp;
srand(time(NULL));
for (r = 0; r <runs; r++ )
{
printf("# Run %d\n",r );
initialise();
for (g=0; g < maxgens; g ++)
{
if ( maxgens <= 100 || g % (maxgens / 100) == 0 ) {
save(g);
printf("%d %g\n",g,mean());
}
for ( i = 0; i< popsize; i ++)
newpop[i] = xover(sel(),sel());
tmp = newpop; newpop = pop; pop = tmp;
}
}
output();
return 0;
}
|
the_stack_data/142446.c | #include <stdio.h>
#include <string.h>
// a is dest
// b is source
// a = b
void mystrcpy(char*a, char*b)
{
while( (*(a++) = *(b++)) ){}
}
int main()
{
char a[32];
char b[32];
fgets(b, sizeof(b), stdin);
mystrcpy(a,b);
puts(a);
return 0;
}
|
the_stack_data/104828576.c |
/**
* @file debug_bytes_checksum.c
* @brief as a training module
* @copyright ELECTROLANCE SOLUTIONS
* @license Apache-2.0
* @author Manojkumar <[email protected]>
*/
#include <stdint.h>
#include <stdio.h>
/**
* FUNCTION PROTOTYPES
*/
uint8_t Checksumcrc(uint8_t *aData, uint8_t StartIndex, uint8_t DataLength);
int debug_bytes(uint8_t *data_ptr, size_t size);
void main()
{
uint8_t TxData[5] = {0};
TxData[0] = 0x3E;
TxData[1] = 0x92;
TxData[2] = 0x11;
TxData[3] = 0;
TxData[4] = Checksumcrc(TxData, 0, 4);
debug_bytes(TxData, 5);
}
uint8_t Checksumcrc(uint8_t *aData, uint8_t StartIndex, uint8_t DataLength)
{
uint8_t crc = 0;
uint8_t i = 0;
for (i = StartIndex; i < (StartIndex + DataLength); i++)
{
crc += aData[i];
}
return crc;
}
int debug_bytes(uint8_t *data_ptr, size_t size)
{
if ((data_ptr) && (size > 0))
{
uint8_t i = 0;
for (i = 0; i < 14; i++)
{
/*printf("buf val%d=%#X\r\n", i, data_ptr[i]);*/
printf("Index:\t%d\t\tVal:\t%#X\r\n", i, data_ptr[i]);
}
}
else
{
/*Bad params null ptr or wrong size*/
return -1;
}
return 1;
}
|
the_stack_data/28261905.c |
/**
Copyright (c) 2016 Jason Ertel, Codesim LLC
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <endian.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
unsigned short read16(FILE* f, unsigned char offset) {
fseek(f, offset, SEEK_SET);
unsigned short s = 0;
fread(&s, sizeof(unsigned short), 1, f);
return htobe16(s);
}
unsigned char read8(FILE* f, unsigned char offset) {
fseek(f, offset, SEEK_SET);
unsigned char c = 0;
fread(&c, sizeof(unsigned char), 1, f);
return c;
}
unsigned char read1(FILE* f, unsigned char offset, unsigned char bit) {
fseek(f, offset, SEEK_SET);
unsigned char c = 0;
fread(&c, sizeof(unsigned char), 1, f);
return (c & (1 << bit)) > 0 ? 1 : 0;
}
void write8(FILE* f, unsigned char offset, const unsigned char value) {
fseek(f, offset, SEEK_SET);
unsigned char c = 0;
fwrite(&value, sizeof(unsigned char), 1, f);
}
void write1(FILE* f, unsigned char offset, unsigned char bit, const unsigned char value) {
unsigned char c = read8(f, offset);
fseek(f, offset, SEEK_SET);
if (value > 0) {
c |= (1 << bit);
} else {
c &= ~(1 << bit);
}
fwrite(&c, sizeof(unsigned char), 1, f);
}
FILE* initEc() {
system("modprobe ec_sys write_support=1");
return fopen("/sys/kernel/debug/ec/ec0/io", "r+");
}
void closeEc(FILE* ec) {
fclose(ec);
}
void fail(const char* msg) {
printf("ERROR: %s\n", msg);
exit(1);
}
int main(int argc, char** args) {
FILE* ec = initEc();
if (!ec) fail("Unable to initialize embedded controller; did you forget to use sudo?");
if (argc == 3) {
char* dotIdx = strchr(args[1], '.');
if (dotIdx != NULL) {
*dotIdx = '\0';
dotIdx++;
unsigned char offset = (unsigned char)strtol(args[1], NULL, 0);
unsigned char bit = (unsigned char)atoi(dotIdx);
unsigned char value = (unsigned char)strtol(args[2], NULL, 0);
write1(ec, offset, bit, value);
} else {
unsigned char offset = (unsigned char)strtol(args[1], NULL, 0);
unsigned char value = (unsigned char)strtol(args[2], NULL, 0);
write8(ec, offset, value);
}
} else {
// Setting the following bits causing the EC to activate (or at least activate fan controls)
write8(ec, 0x01, 0xA3);
printf("Usage: sudo %s [<hex-offset[.bit]> <hex-value>]\n", args[0]);
printf(" Ex: sudo %s 0x01.6 0x07\n\n", args[0]);
printf("Current Embedded Controller Values:\n");
printf(" USB Charge During Sleep [0x01.5]: %d\n", read1(ec, 0x01, 5));
printf(" USB Charge During Hibernate [0x07.2]: %d\n", read1(ec, 0x07, 2));
printf(" Camera Enabled [0x01.6]: %d\n", read1(ec, 0x01, 6));
printf(" Bluetooth Enabled [0x01.7]: %d\n", read1(ec, 0x01, 7));
printf(" WiFi Enabled [0x02.6]: %d\n", read1(ec, 0x02, 6));
printf(" Touchpad Enabled [0x03.5]: %d\n", read1(ec, 0x03, 5));
printf(" Ambient Light [0x66]: %d%%\n", read8(ec, 0x66));
printf(" Screen Enabled [0x09.3]: %d\n", read1(ec, 0x09, 3));
printf(" Keyboard Backlight Mode [0xD7]: %d\n", read8(ec, 0xD7));
printf(" CPU Temp [0x60]: %d C\n", read8(ec, 0x60));
printf(" GPU Temp [0x61]: %d C\n", read8(ec, 0x61));
printf(" MLB Temp [0x62]: %d C\n", read8(ec, 0x62));
printf(" Fan0 Speed [0xFC]: %d RPM\n", read16(ec, 0xFC));
printf(" Fan1 Speed [0xFE]: %d RPM\n", read16(ec, 0xFE));
printf(" Fan Control Enabled [0x13.3]: %d\n", read1(ec, 0x13, 3));
printf(" Fan Quiet Mode Enabled [0x08.6]: %d\n", read1(ec, 0x08, 6));
printf(" Fan Gaming Mode Enabled [0x12.4]: %d\n", read1(ec, 0x12, 4));
printf(" Fan Custom Mode Enabled [0x13.0]: %d\n", read1(ec, 0x13, 0));
printf(" Fan0 Custom Speed Setting [0xB0]: %d%%\n", (int)round(read8(ec, 0xB0) / 2.55));
printf(" Fan1 Custom Speed Setting [0xB1]: %d%%\n", (int)round(read8(ec, 0xB1) / 2.55));
printf(" Current Speed Setting [0x64]: %d\n", read8(ec, 0x64));
}
closeEc(ec);
exit(0);
}
|
the_stack_data/54333.c | // PARAM: --sets solver td3 --enable ana.int.interval --enable exp.partition-arrays.enabled --set ana.activated "['base','threadid','threadflag','expRelation','mallocWrapper']"
int global_array[50];
int main(void) {
some_func();
int x = global_array[5];
assert(x == 0); //UNKNOWN
assert(x == 42); //UNKNOWN
}
void some_func(void) {
global_array[0] = 5;
for(int i=1; i < 50; i++) {
global_array[i] = 42;
}
int x = global_array[0];
assert(x == 42); //FAIL
}
|
the_stack_data/653189.c | // Program to reverse the digits of a number
#include <stdio.h>
int main ()
{
int number, right_digit;
printf ("Enter your number to reverse: ");
scanf ("%i", &number);
do {
right_digit = number % 10;
printf ("%i", right_digit);
number = number / 10;
}
while (number != 0);
printf ("\n");
return 0;
}
/* Output
Enter your number to reverse: 10
01
*/
|
the_stack_data/218892661.c | #include <stdio.h>
int main(void)
{
int cont, somma, voto;
float media;
cont = 0;
somma = 0;
do
{
scanf("%d", &voto);
cont = cont + 1;
somma = somma + voto;
} while(voto != 0);
if(cont == 1)
{
printf("Sequenza vuota\n");;
}
else
{
media = (float)somma / (cont - 1);
printf("Media: %.2f\n", media);
}
return 0;
}
|
the_stack_data/73475.c | #include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <semaphore.h>
#include <zconf.h>
#include <stdbool.h>
#define RED "\x1B[31m"
#define GRN "\x1B[32m"
#define BLU "\x1B[34m"
#define RESET "\x1B[0m"
int work_counter = 300;
int buffer_1[10];
int buffer_size_1 = 0;
int buffer_2[10];
int buffer_size_2 = 0;
sem_t mutex_1;
sem_t full_1;
sem_t empty_1;
sem_t mutex_2;
sem_t full_2;
sem_t empty_2;
sem_t queue_type1_buff_1;
sem_t queue_type1_buff_2;
sem_t queue_type2;
sem_t action_token;
sem_t notify_queue;
void *produce(void *id);
void *consume(void *id);
void *consume_from_two_buffers(void *id);
void *check_queue();
void random_sleep();
int draw_buffer();
void init_semaphores();
bool is_type_two_queued(int queue_type2_sem_value);
bool can_take_from_buff_1_queue(int queue_type1_buf1_sem_value);
bool can_take_from_buff_2_queue(int queue_type1_buf2_sem_value);
void move_buffer_1();
void move_buffer_2();
int main() {
pthread_t producer_1, producer_2, producer_3, consumer, consumer_2, two_consumer, two_consumer_2, queue;
int one = 1, two = 2, three = 3;
srand(time(NULL));
init_semaphores();
printf("\n\n\n");
pthread_create(&queue, NULL, check_queue, NULL);
pthread_create(&producer_1, NULL, produce, (void *) &one);
pthread_create(&producer_2, NULL, produce, (void *) &two);
pthread_create(&producer_3, NULL, produce, (void *) &three);
pthread_create(&consumer, NULL, consume, (void *) &one);
pthread_create(&consumer_2, NULL, consume, (void *) &two);
pthread_create(&two_consumer, NULL, consume_from_two_buffers, (void *) &one);
pthread_create(&two_consumer_2, NULL, consume_from_two_buffers, (void *) &two);
pthread_exit(NULL);
}
void init_semaphores() {
sem_init(&mutex_1, 0, 1);// sem_mutex = 1 at the beginning
sem_init(&mutex_2, 0, 1);
sem_init(&full_1, 0, 10);// sem_full = 10 at the beginning
sem_init(&full_2, 0, 10);
sem_init(&empty_1, 0, 0);// sem_empty = 0 at the beginning
sem_init(&empty_2, 0, 0);
sem_init(&queue_type1_buff_1, 0, 0);// nothing in queues at start, sem = 0 - cannot take from queue
sem_init(&queue_type1_buff_2, 0, 0);
sem_init(&queue_type2, 0, 0);
sem_init(¬ify_queue, 0, 0);
sem_init(&action_token, 0, 1);
}
// ===================================== QUEUE =====================================
void *check_queue() {
int queue_type1_buf1_sem_value, queue_type1_buf2_sem_value, queue_type2_sem_value;
while (work_counter > 0) {
sem_wait(¬ify_queue);
sem_wait(&mutex_1);
sem_wait(&mutex_2);
sem_getvalue(&queue_type1_buff_1, &queue_type1_buf1_sem_value);
sem_getvalue(&queue_type1_buff_2, &queue_type1_buf2_sem_value);
sem_getvalue(&queue_type2, &queue_type2_sem_value);
// printf("___ queues: type 2: "RED"%d"RESET", type_1__1: "RED"%d"RESET", type_1__2: "RED"%d"RESET" "
// "buffers: buff_1: "RED"%d"RESET", buff_2: "RED"%d"RESET"\n",
// queue_type2_sem_value, queue_type1_buf1_sem_value, queue_type1_buf2_sem_value, buffer_size_1,
// buffer_size_2);
if (is_type_two_queued(queue_type2_sem_value)) {
buffer_size_2--;
buffer_size_1--;
printf("*"RED"consumer TYPE 2 FROM QUEUE consumed: %d and %d "RESET" from BUFF 1,2; buff_size: %d and %d \n",
buffer_1[0],
buffer_2[0], buffer_size_1, buffer_size_2);
move_buffer_1();
move_buffer_2();
sem_post(&full_1);
sem_post(&full_2);
sem_wait(&queue_type2);
}
if (!is_type_two_queued(queue_type2_sem_value) && can_take_from_buff_1_queue(queue_type1_buf1_sem_value)) {
buffer_size_1--;
printf("-"RED"consumer FROM QUEUE consumed: %d "RESET" from "GRN"BUFF 1 "RESET", buff_size: %d \n",
buffer_1[0], buffer_size_1);
move_buffer_1();
sem_post(&full_1);
sem_wait(&queue_type1_buff_1);
}
if (!is_type_two_queued(queue_type2_sem_value) && can_take_from_buff_2_queue(queue_type1_buf2_sem_value)) {
buffer_size_2--;
printf("-"RED"consumer FROM QUEUE consumed: %d "RESET" from "BLU"BUFF 2 "RESET", buff_size: %d \n",
buffer_2[0], buffer_size_2);
move_buffer_2();
sem_post(&full_2);
sem_wait(&queue_type1_buff_2);
}
sem_post(&mutex_1);
sem_post(&mutex_2);
sem_post(&action_token);
}
pthread_exit(NULL);
}
bool is_type_two_queued(int queue_type2_sem_value) {
return queue_type2_sem_value > 0 && buffer_size_1 > 0 && buffer_size_2 > 0;
}
bool can_take_from_buff_1_queue(int queue_type1_buf1_sem_value) {
return queue_type1_buf1_sem_value > 0 && buffer_size_1 > 0;
}
bool can_take_from_buff_2_queue(int queue_type1_buf2_sem_value) {
return queue_type1_buf2_sem_value > 0 && buffer_size_2 > 0;
}
// ===================================== PRODUCER ======================================
void *produce(void *id) {
int ID = *((int *) id);
while (work_counter > 0) {
if (draw_buffer() == 1) {
sem_wait(&full_1);
sem_wait(&action_token);
sem_wait(&mutex_1);
buffer_1[buffer_size_1] = rand() % 10;
printf("+producer: %d produced: %d for "GRN"BUFF 1 "RESET", buff_size: %d \n", ID,
buffer_1[buffer_size_1], buffer_size_1);
buffer_size_1++;
sem_post(&empty_1);
sem_post(&mutex_1);
} else {
sem_wait(&full_2);
sem_wait(&action_token);
sem_wait(&mutex_2);
buffer_2[buffer_size_2] = rand() % 10;
printf("+producer: %d produced: %d for "BLU"BUFF 2 "RESET", buff_size: %d \n", ID,
buffer_2[buffer_size_2], buffer_size_2);
buffer_size_2++;
sem_post(&empty_2);
sem_post(&mutex_2);
}
sem_post(¬ify_queue);
work_counter--;
random_sleep();
}
pthread_exit(NULL);
}
// ======================================== CONSUMER ===============================================================
void *consume(void *id) {
int ID = *((int *) id);
while (work_counter > 0) {
sem_wait(&action_token);
if (draw_buffer() == 1) {
sem_wait(&mutex_1);
if (buffer_size_1 == 0) {
sem_post(&queue_type1_buff_1);
printf("-"RED"consumer: %d ADDED TO QUEUE "RESET" of "GRN"BUFF 1 "RESET" \n", ID);
} else {
buffer_size_1--;
printf("-"RED"consumer: %d consumed: %d "RESET" from "GRN"BUFF 1 "RESET", buff_size: %d \n", ID,
buffer_1[0], buffer_size_1);
move_buffer_1();
sem_post(&full_1);
}
sem_post(&mutex_1);
} else {
sem_wait(&mutex_2);
if (buffer_size_2 == 0) {
sem_post(&queue_type1_buff_2);
printf("-"RED"consumer: %d ADDED TO QUEUE "RESET" of "BLU"BUFF 2 "RESET" \n", ID);
} else {
buffer_size_2--;
printf("-"RED"consumer: %d consumed: %d "RESET" from "BLU"BUFF 2 "RESET", buff_size: %d \n", ID,
buffer_2[0], buffer_size_2);
move_buffer_2();
sem_post(&full_2);
}
sem_post(&mutex_2);
}
sem_post(¬ify_queue);
work_counter--;
random_sleep();
}
pthread_exit(NULL);
}
void move_buffer_2() {
int i;
if (buffer_size_2 > 0) {
for (i = 0; i < buffer_size_2; i++) {
buffer_2[i] = buffer_2[i + 1];
}
}
}
void move_buffer_1() {
int i;
if (buffer_size_1 > 0) {
for (i = 0; i < buffer_size_1; i++) {
buffer_1[i] = buffer_1[i + 1];
}
}
}
void *consume_from_two_buffers(void *id) {
int ID = *((int *) id);
while (work_counter > 0) {
sem_wait(&action_token);
sem_wait(&mutex_1);
sem_wait(&mutex_2);
if (buffer_size_1 > 0 && buffer_size_2 > 0) {
buffer_size_1--;
buffer_size_2--;
printf("-"RED"consumer_type_2, id=%d consumed: %d,%d"RESET" from BUFF 1 & 2, buff_size1: %d, buff_size2: %d \n",
ID, buffer_1[0], buffer_2[0], buffer_size_1, buffer_size_2);
move_buffer_1();
move_buffer_2();
sem_post(&full_1);
sem_post(&full_2);
}
if (buffer_size_1 == 0 || buffer_size_2 == 0) {
sem_post(&queue_type2);
printf("-"RED"consumer_type_2, id=%d ADDED TO QUEUE "RESET" \n", ID);
}
sem_post(&mutex_1);
sem_post(&mutex_2);
sem_post(¬ify_queue);
work_counter--;
random_sleep();
sleep(2);
}
pthread_exit(NULL);
}
//=======================================================================================
int draw_buffer() {
return rand() % 2 + 1;
}
void random_sleep() {
if (rand() % 2 == 1) {
sleep(1);
}
}
|
the_stack_data/156394339.c | // RUN: rm -f %t
// RUN: %clang -fsyntax-only %s -Wblahblah --serialize-diagnostics %t > /dev/null 2>&1 || true
// RUN: c-index-test -read-diagnostics %t 2>&1 | FileCheck %s
// This test case tests that we can handle frontend diagnostics.
// CHECK: warning: unknown warning option '-Wblahblah'
// CHECK: Number of diagnostics: 1
|
the_stack_data/694389.c | #include<stdio.h>
main()
{
unsigned int i;
for(i=10;i>=0;i--)
printf("%d",i--);
}
|
the_stack_data/93133.c | /* shc.c */
/**
* This software contains an ad hoc version of the 'Alleged RC4' algorithm,
* which was anonymously posted on sci.crypt news by cypherpunks on Sep 1994.
*
* My implementation is a complete rewrite of the one found in
* an unknown-copyright (283 characters) version picked up from:
* From: [email protected] (John L. Allen)
* Newsgroups: comp.lang.c
* Subject: Shrink this C code for fame and fun
* Date: 21 May 1996 10:49:37 -0400
* And it is licensed also under GPL.
*/
static const char my_name[] = "shc";
static const char version[] = "Version 3.8.9";
static const char subject[] = "Generic Script Compiler";
static const char cpright[] = "Copyright (c) 1994-2012";
static const struct { const char * f, * s, * e; }
author = { "Francisco", "Rosales", "<[email protected]>" };
static const char * copying[] = {
"Copying:",
"",
" This program is free software; you can redistribute it and/or modify",
" it under the terms of the GNU General Public License as published by",
" the Free Software Foundation; either version 2 of the License, or",
" (at your option) any later version.",
"",
" This program is distributed in the hope that it will be useful,",
" but WITHOUT ANY WARRANTY; without even the implied warranty of",
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the",
" GNU General Public License for more details.",
"",
" You should have received a copy of the GNU General Public License",
" along with this program; if not, write to the Free Software",
" Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.",
"",
" Report problems and questions to:",
"",
0};
static const char * abstract[] = {
"Abstract:",
"",
" This tool generates a stripped binary executable version",
" of the script specified at command line.",
"",
" Binary version will be saved with a .x extension.",
"",
" You can specify expiration date [-e] too, after which binary will",
" refuse to be executed, displaying \"[-m]\" instead.",
"",
" You can compile whatever interpreted script, but valid [-i], [-x]",
" and [-l] options must be given.",
"",
0};
static const char usage[] =
"Usage: shc [-e date] [-m addr] [-i iopt] [-x cmnd] [-l lopt] [-rvDTCAh] -f script";
static const char * help[] = {
"",
" -e %s Expiration date in dd/mm/yyyy format [none]",
" -m %s Message to display upon expiration [\"Please contact your provider\"]",
" -f %s File name of the script to compile",
" -i %s Inline option for the shell interpreter i.e: -e",
" -x %s eXec command, as a printf format i.e: exec('%s',@ARGV);",
" -l %s Last shell option i.e: --",
" -r Relax security. Make a redistributable binary",
" -v Verbose compilation",
" -D Switch ON debug exec calls [OFF]",
" -T Allow binary to be traceable [no]",
" -C Display license and exit",
" -A Display abstract and exit",
" -h Display help and exit",
"",
" Environment variables used:",
" Name Default Usage",
" CC cc C compiler command",
" CFLAGS <none> C compiler flags",
"",
" Please consult the shc(1) man page.",
"",
0};
#include <sys/types.h>
#include <sys/stat.h>
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#define SIZE 4096
static char * file;
static char date[21];
static char * mail = "Please contact your provider";
static char rlax[1];
static char * shll;
static char * inlo;
static char * xecc;
static char * lsto;
static char * opts;
static char * text;
static int verbose;
static const char DEBUGEXEC_line[] =
"#define DEBUGEXEC %d /* Define as 1 to debug execvp calls */\n";
static int DEBUGEXEC_flag;
static const char TRACEABLE_line[] =
"#define TRACEABLE %d /* Define as 1 to enable ptrace the executable */\n";
static int TRACEABLE_flag;
static const char * RTC[] = {
"",
"/* rtc.c */",
"",
"#include <sys/stat.h>",
"#include <sys/types.h>",
"",
"#include <errno.h>",
"#include <stdio.h>",
"#include <stdlib.h>",
"#include <string.h>",
"#include <time.h>",
"#include <unistd.h>",
"",
"/* 'Alleged RC4' */",
"",
"static unsigned char stte[256], indx, jndx, kndx;",
"",
"/*",
" * Reset arc4 stte. ",
" */",
"void stte_0(void)",
"{",
" indx = jndx = kndx = 0;",
" do {",
" stte[indx] = indx;",
" } while (++indx);",
"}",
"",
"/*",
" * Set key. Can be used more than once. ",
" */",
"void key(void * str, int len)",
"{",
" unsigned char tmp, * ptr = (unsigned char *)str;",
" while (len > 0) {",
" do {",
" tmp = stte[indx];",
" kndx += tmp;",
" kndx += ptr[(int)indx % len];",
" stte[indx] = stte[kndx];",
" stte[kndx] = tmp;",
" } while (++indx);",
" ptr += 256;",
" len -= 256;",
" }",
"}",
"",
"/*",
" * Crypt data. ",
" */",
"void arc4(void * str, int len)",
"{",
" unsigned char tmp, * ptr = (unsigned char *)str;",
" while (len > 0) {",
" indx++;",
" tmp = stte[indx];",
" jndx += tmp;",
" stte[indx] = stte[jndx];",
" stte[jndx] = tmp;",
" tmp += stte[indx];",
" *ptr ^= stte[tmp];",
" ptr++;",
" len--;",
" }",
"}",
"",
"/* End of ARC4 */",
"",
"/*",
" * Key with file invariants. ",
" */",
"int key_with_file(char * file)",
"{",
" struct stat statf[1];",
" struct stat control[1];",
"",
" if (stat(file, statf) < 0)",
" return -1;",
"",
" /* Turn on stable fields */",
" memset(control, 0, sizeof(control));",
" control->st_ino = statf->st_ino;",
" control->st_dev = statf->st_dev;",
" control->st_rdev = statf->st_rdev;",
" control->st_uid = statf->st_uid;",
" control->st_gid = statf->st_gid;",
" control->st_size = statf->st_size;",
" control->st_mtime = statf->st_mtime;",
" control->st_ctime = statf->st_ctime;",
" key(control, sizeof(control));",
" return 0;",
"}",
"",
"#if DEBUGEXEC",
"void debugexec(char * sh11, int argc, char ** argv)",
"{",
" int i;",
" fprintf(stderr, \"shll=%s\\n\", sh11 ? sh11 : \"<null>\");",
" fprintf(stderr, \"argc=%d\\n\", argc);",
" if (!argv) {",
" fprintf(stderr, \"argv=<null>\\n\");",
" } else { ",
" for (i = 0; i <= argc ; i++)",
" fprintf(stderr, \"argv[%d]=%.60s\\n\", i, argv[i] ? argv[i] : \"<null>\");",
" }",
"}",
"#endif /* DEBUGEXEC */",
"",
"void rmarg(char ** argv, char * arg)",
"{",
" for (; argv && *argv && *argv != arg; argv++);",
" for (; argv && *argv; argv++)",
" *argv = argv[1];",
"}",
"",
"int chkenv(int argc)",
"{",
" char buff[512];",
" unsigned long mask, m;",
" int l, a, c;",
" char * string;",
" extern char ** environ;",
"",
" mask = (unsigned long)&chkenv;",
" mask ^= (unsigned long)getpid() * ~mask;",
" sprintf(buff, \"x%lx\", mask);",
" string = getenv(buff);",
"#if DEBUGEXEC",
" fprintf(stderr, \"getenv(%s)=%s\\n\", buff, string ? string : \"<null>\");",
"#endif",
" l = strlen(buff);",
" if (!string) {",
" /* 1st */",
" sprintf(&buff[l], \"=%lu %d\", mask, argc);",
" putenv(strdup(buff));",
" return 0;",
" }",
" c = sscanf(string, \"%lu %d%c\", &m, &a, buff);",
" if (c == 2 && m == mask) {",
" /* 3rd */",
" rmarg(environ, &string[-l - 1]);",
" return 1 + (argc - a);",
" }",
" return -1;",
"}",
"",
"#if !TRACEABLE",
"",
"#define _LINUX_SOURCE_COMPAT",
"#include <sys/ptrace.h>",
"#include <sys/types.h>",
"#include <sys/wait.h>",
"#include <fcntl.h>",
"#include <signal.h>",
"#include <stdio.h>",
"#include <unistd.h>",
"",
"#if !defined(PTRACE_ATTACH) && defined(PT_ATTACH)",
"# define PTRACE_ATTACH PT_ATTACH",
"#endif",
"void untraceable(char * argv0)",
"{",
" char proc[80];",
" int pid, mine;",
"",
" switch(pid = fork()) {",
" case 0:",
" pid = getppid();",
" /* For problematic SunOS ptrace */",
"#if defined(__FreeBSD__)",
" sprintf(proc, \"/proc/%d/mem\", (int)pid);",
"#else",
" sprintf(proc, \"/proc/%d/as\", (int)pid);",
"#endif",
" close(0);",
" mine = !open(proc, O_RDWR|O_EXCL);",
" if (!mine && errno != EBUSY)",
" mine = !ptrace(PTRACE_ATTACH, pid, 0, 0);",
" if (mine) {",
" kill(pid, SIGCONT);",
" } else {",
/*" fprintf(stderr, \"%s is being traced!\\n\", argv0);",*/
" perror(argv0);",
" kill(pid, SIGKILL);",
" }",
" _exit(mine);",
" case -1:",
" break;",
" default:",
" if (pid == waitpid(pid, 0, 0))",
" return;",
" }",
" perror(argv0);",
" _exit(1);",
"}",
"#endif /* !TRACEABLE */",
"",
"char * xsh(int argc, char ** argv)",
"{",
" char * scrpt;",
" int ret, i, j;",
" char ** varg;",
" char * me = getenv(\"_\");",
" if (me == NULL) { me = argv[0]; }",
"",
" stte_0();",
" key(pswd, pswd_z);",
" arc4(msg1, msg1_z);",
" arc4(date, date_z);",
" if (date[0] && (atoll(date)<time(NULL)))",
" return msg1;",
" arc4(shll, shll_z);",
" arc4(inlo, inlo_z);",
" arc4(xecc, xecc_z);",
" arc4(lsto, lsto_z);",
" arc4(tst1, tst1_z);",
" key(tst1, tst1_z);",
" arc4(chk1, chk1_z);",
" if ((chk1_z != tst1_z) || memcmp(tst1, chk1, tst1_z))",
" return tst1;",
" ret = chkenv(argc);",
" arc4(msg2, msg2_z);",
" if (ret < 0)",
" return msg2;",
" varg = (char **)calloc(argc + 10, sizeof(char *));",
" if (!varg)",
" return 0;",
" if (ret) {",
" arc4(rlax, rlax_z);",
" if (!rlax[0] && key_with_file(shll))",
" return shll;",
" arc4(opts, opts_z);",
" arc4(text, text_z);",
" arc4(tst2, tst2_z);",
" key(tst2, tst2_z);",
" arc4(chk2, chk2_z);",
" if ((chk2_z != tst2_z) || memcmp(tst2, chk2, tst2_z))",
" return tst2;",
" /* Prepend hide_z spaces to script text to hide it. */",
" scrpt = malloc(hide_z + text_z);",
" if (!scrpt)",
" return 0;",
" memset(scrpt, (int) ' ', hide_z);",
" memcpy(&scrpt[hide_z], text, text_z);",
" } else { /* Reexecute */",
" if (*xecc) {",
" scrpt = malloc(512);",
" if (!scrpt)",
" return 0;",
" sprintf(scrpt, xecc, me);",
" } else {",
" scrpt = me;",
" }",
" }",
" j = 0;",
" varg[j++] = argv[0]; /* My own name at execution */",
" if (ret && *opts)",
" varg[j++] = opts; /* Options on 1st line of code */",
" if (*inlo)",
" varg[j++] = inlo; /* Option introducing inline code */",
" varg[j++] = scrpt; /* The script itself */",
" if (*lsto)",
" varg[j++] = lsto; /* Option meaning last option */",
" i = (ret > 1) ? ret : 0; /* Args numbering correction */",
" while (i < argc)",
" varg[j++] = argv[i++]; /* Main run-time arguments */",
" varg[j] = 0; /* NULL terminated array */",
"#if DEBUGEXEC",
" debugexec(shll, j, varg);",
"#endif",
" execvp(shll, varg);",
" return shll;",
"}",
"",
"int main(int argc, char ** argv)",
"{",
"#if DEBUGEXEC",
" debugexec(\"main\", argc, argv);",
"#endif",
"#if !TRACEABLE",
" untraceable(argv[0]);",
"#endif",
" argv[1] = xsh(argc, argv);",
" fprintf(stderr, \"%s%s%s: %s\\n\", argv[0],",
" errno ? \": \" : \"\",",
" errno ? strerror(errno) : \"\",",
" argv[1] ? argv[1] : \"<null>\"",
" );",
" return 1;",
"}",
0};
static int parse_an_arg(int argc, char * argv[])
{
extern char * optarg;
const char * opts = "e:m:f:i:x:l:rvDTCAh";
struct tm tmp[1];
time_t expdate;
int cnt, l;
char ctrl;
switch (getopt(argc, argv, opts)) {
case 'e':
memset(tmp, 0, sizeof(tmp));
cnt = sscanf(optarg, "%2d/%2d/%4d%c",
&tmp->tm_mday, &tmp->tm_mon, &tmp->tm_year, &ctrl);
if (cnt == 3) {
tmp->tm_mon--;
tmp->tm_year -= 1900;
expdate = mktime(tmp);
}
if (cnt != 3 || expdate <= 0) {
fprintf(stderr, "%s parse(-e %s): Not a valid value\n",
my_name, optarg);
return -1;
}
sprintf(date, "%lld", (long long)expdate);
if (verbose) fprintf(stderr, "%s -e %s", my_name, ctime(&expdate));
expdate = atoll(date);
if (verbose) fprintf(stderr, "%s -e %s", my_name, ctime(&expdate));
break;
case 'm':
mail = optarg;
break;
case 'f':
if (file) {
fprintf(stderr, "%s parse(-f): Specified more than once\n",
my_name);
return -1;
}
file = optarg;
break;
case 'i':
inlo = optarg;
break;
case 'x':
xecc = optarg;
break;
case 'l':
lsto = optarg;
break;
case 'r':
rlax[0]++;
break;
case 'v':
verbose++;
break;
case 'D':
DEBUGEXEC_flag = 1;
break;
case 'T':
TRACEABLE_flag = 1;
break;
case 'C':
fprintf(stderr, "%s %s, %s\n", my_name, version, subject);
fprintf(stderr, "%s %s %s %s %s\n", my_name, cpright, author.f, author.s, author.e);
fprintf(stderr, "%s ", my_name);
for (l = 0; copying[l]; l++)
fprintf(stderr, "%s\n", copying[l]);
fprintf(stderr, " %s %s %s\n\n", author.f, author.s, author.e);
exit(0);
break;
case 'A':
fprintf(stderr, "%s %s, %s\n", my_name, version, subject);
fprintf(stderr, "%s %s %s %s %s\n", my_name, cpright, author.f, author.s, author.e);
fprintf(stderr, "%s ", my_name);
for (l = 0; abstract[l]; l++)
fprintf(stderr, "%s\n", abstract[l]);
exit(0);
break;
case 'h':
fprintf(stderr, "%s %s, %s\n", my_name, version, subject);
fprintf(stderr, "%s %s %s %s %s\n", my_name, cpright, author.f, author.s, author.e);
fprintf(stderr, "%s %s\n", my_name, usage);
for (l = 0; help[l]; l++)
fprintf(stderr, "%s\n", help[l]);
exit(0);
break;
case -1:
if (!file) {
fprintf(stderr, "%s parse(-f): No source file specified\n", my_name);
file = "";
return -1;
}
return 0;
case ':':
fprintf(stderr, "%s parse: Missing parameter\n", my_name);
return -1;
case '?':
fprintf(stderr, "%s parse: Unknown option\n", my_name);
return -1;
default:
fprintf(stderr, "%s parse: Unknown return\n", my_name);
return -1;
}
return 1;
}
static void parse_args(int argc, char * argv[])
{
int err = 0;
int ret;
#if 0
my_name = strrchr(argv[0], '/');
if (my_name)
my_name++;
else
my_name = argv[0];
#endif
do {
ret = parse_an_arg(argc, argv);
if (ret == -1)
err++;
} while (ret);
if (err) {
fprintf(stderr, "\n%s %s\n\n", my_name, usage);
exit(1);
}
}
/* 'Alleged RC4' */
static unsigned char stte[256], indx, jndx, kndx;
/*
* Reset arc4 stte.
*/
void stte_0(void)
{
indx = jndx = kndx = 0;
do {
stte[indx] = indx;
} while (++indx);
}
/*
* Set key. Can be used more than once.
*/
void key(void * str, int len)
{
unsigned char tmp, * ptr = (unsigned char *)str;
while (len > 0) {
do {
tmp = stte[indx];
kndx += tmp;
kndx += ptr[(int)indx % len];
stte[indx] = stte[kndx];
stte[kndx] = tmp;
} while (++indx);
ptr += 256;
len -= 256;
}
}
/*
* Crypt data.
*/
void arc4(void * str, int len)
{
unsigned char tmp, * ptr = (unsigned char *)str;
while (len > 0) {
indx++;
tmp = stte[indx];
jndx += tmp;
stte[indx] = stte[jndx];
stte[jndx] = tmp;
tmp += stte[indx];
*ptr ^= stte[tmp];
ptr++;
len--;
}
}
/* End of ARC4 */
/*
* Key with file invariants.
*/
int key_with_file(char * file)
{
struct stat statf[1];
struct stat control[1];
if (stat(file, statf) < 0)
return -1;
/* Turn on stable fields */
memset(control, 0, sizeof(control));
control->st_ino = statf->st_ino;
control->st_dev = statf->st_dev;
control->st_rdev = statf->st_rdev;
control->st_uid = statf->st_uid;
control->st_gid = statf->st_gid;
control->st_size = statf->st_size;
control->st_mtime = statf->st_mtime;
control->st_ctime = statf->st_ctime;
key(control, sizeof(control));
return 0;
}
/*
* NVI stands for Shells that complaint "Not Valid Identifier" on
* environment variables with characters as "=|#:*?$ ".
*/
struct {
char * shll;
char * inlo;
char * lsto;
char * xecc;
} shellsDB[] = {
{ "perl", "-e", "--", "exec('%s',@ARGV);" },
{ "rc", "-c", "", "builtin exec %s $*" },
{ "sh", "-c", "", "exec '%s' \"$@\"" }, /* IRIX_nvi */
{ "bash", "-c", "", "exec '%s' \"$@\"" },
{ "bsh", "-c", "", "exec '%s' \"$@\"" }, /* AIX_nvi */
{ "Rsh", "-c", "", "exec '%s' \"$@\"" }, /* AIX_nvi */
{ "ksh", "-c", "", "exec '%s' \"$@\"" }, /* OK on Solaris, AIX and Linux (THX <[email protected]>) */
{ "tsh", "-c", "--", "exec '%s' \"$@\"" }, /* AIX */
{ "ash", "-c", "--", "exec '%s' \"$@\"" }, /* Linux */
{ "csh", "-c", "-b", "exec '%s' $argv" }, /* AIX: No file for $0 */
{ "tcsh", "-c", "-b", "exec '%s' $argv" },
{ NULL, NULL, NULL, NULL },
};
int eval_shell(char * text)
{
int i;
char * ptr;
ptr = strchr(text, (int)'\n');
if (!ptr)
i = strlen(text);
else
i = ptr - text;
ptr = malloc(i + 1);
shll = malloc(i + 1);
opts = malloc(i + 1);
if (!ptr || !shll || !opts)
return -1;
strncpy(ptr, text, i);
ptr[i] = '\0';
*opts = '\0';
i = sscanf(ptr, " #!%s%s %c", shll, opts, opts);
if (i < 1 || i > 2) {
fprintf(stderr, "%s: invalid first line in script: %s\n", my_name, ptr);
return -1;
}
free(ptr);
shll = realloc(shll, strlen(shll) + 1);
ptr = strrchr(shll, (int)'/');
if (*ptr == '/')
ptr++;
if (verbose) fprintf(stderr, "%s shll=%s\n", my_name, ptr);
for(i=0; shellsDB[i].shll; i++) {
if(!strcmp(ptr, shellsDB[i].shll)) {
if (!inlo)
inlo = strdup(shellsDB[i].inlo);
if (!xecc)
xecc = strdup(shellsDB[i].xecc);
if (!lsto)
lsto = strdup(shellsDB[i].lsto);
}
}
if (!inlo || !xecc || !lsto) {
fprintf(stderr, "%s Unknown shell (%s): specify [-i][-x][-l]\n", my_name, ptr);
return -1;
}
if (verbose) fprintf(stderr, "%s [-i]=%s\n", my_name, inlo);
if (verbose) fprintf(stderr, "%s [-x]=%s\n", my_name, xecc);
if (verbose) fprintf(stderr, "%s [-l]=%s\n", my_name, lsto);
opts = realloc(opts, strlen(opts) + 1);
if (*opts && !strcmp(opts, lsto)) {
fprintf(stderr, "%s opts=%s : Is equal to [-l]. Removing opts\n", my_name, opts);
*opts = '\0';
} else if (!strcmp(opts, "-")) {
fprintf(stderr, "%s opts=%s : No real one. Removing opts\n", my_name, opts);
*opts = '\0';
}
if (verbose) fprintf(stderr, "%s opts=%s\n", my_name, opts);
return 0;
}
char * read_script(char * file)
{
FILE * i;
char * text;
int cnt, l;
text = malloc(SIZE);
if (!text)
return NULL;
i = fopen(file, "r");
if (!i)
return NULL;
for (l = 0;;) {
text = realloc(text, l + SIZE);
if (!text)
return NULL;
cnt = fread(&text[l], 1, SIZE, i);
if (!cnt)
break;
l += cnt;
}
fclose(i);
text = realloc(text, l + 1);
if (!text)
return NULL;
text[l] = '\0';
/* Check current System ARG_MAX limit. */
if (l > 0.80 * (cnt = sysconf(_SC_ARG_MAX))) {
fprintf(stderr, "%s: WARNING!!\n"
" Scripts of length near to (or higher than) the current System limit on\n"
" \"maximum size of arguments to EXEC\", could comprise its binary execution.\n"
" In the current System the call sysconf(_SC_ARG_MAX) returns %d bytes\n"
" and your script \"%s\" is %d bytes length.\n",
my_name, cnt, file, l);
}
return text;
}
unsigned rand_mod(unsigned mod)
{
/* Without skew */
unsigned rnd, top = RAND_MAX;
top -= top % mod;
while (top <= (rnd = rand()))
continue;
/* Using high-order bits. */
rnd = 1.0*mod*rnd/(1.0+top);
return rnd;
}
char rand_chr(void)
{
return (char)rand_mod(1<<(sizeof(char)<<3));
}
int noise(char * ptr, unsigned min, unsigned xtra, int str)
{
if (xtra) xtra = rand_mod(xtra);
xtra += min;
for (min = 0; min < xtra; min++, ptr++)
do
*ptr = rand_chr();
while (str && !isalnum((int)*ptr));
if (str) *ptr = '\0';
return xtra;
}
static int offset;
void prnt_bytes(FILE * o, char * ptr, int m, int l, int n)
{
int i;
l += m;
n += l;
for (i = 0; i < n; i++) {
if ((i & 0xf) == 0)
fprintf(o, "\n\t\"");
fprintf(o, "\\%03o", (unsigned char)((i>=m) && (i<l) ? ptr[i-m] : rand_chr()));
if ((i & 0xf) == 0xf)
fprintf(o, "\"");
}
if ((i & 0xf) != 0)
fprintf(o, "\"");
offset += n;
}
void prnt_array(FILE * o, void * ptr, char * name, int l, char * cast)
{
int m = rand_mod(1+l/4); /* Random amount of random pre padding (offset) */
int n = rand_mod(1+l/4); /* Random amount of random post padding (tail) */
int a = (offset+m)%l;
if (cast && a) m += l - a; /* Type alignement. */
fprintf(o, "\n");
fprintf(o, "#define %s_z %d", name, l);
fprintf(o, "\n");
fprintf(o, "#define %s (%s(&data[%d]))", name, cast?cast:"", offset+m);
prnt_bytes(o, ptr, m, l, n);
}
void dump_array(FILE * o, void * ptr, char * name, int l, char * cast)
{
arc4(ptr, l);
prnt_array(o, ptr, name, l, cast);
}
int write_C(char * file, char * argv[])
{
char pswd[256];
int pswd_z = sizeof(pswd);
char* msg1 = strdup("has expired!\n");
int msg1_z = strlen(msg1) + 1;
int date_z = strlen(date) + 1;
char* kwsh = strdup(shll);
int shll_z = strlen(shll) + 1;
int inlo_z = strlen(inlo) + 1;
int xecc_z = strlen(xecc) + 1;
int lsto_z = strlen(lsto) + 1;
char* tst1 = strdup("location has changed!");
int tst1_z = strlen(tst1) + 1;
char* chk1 = strdup(tst1);
int chk1_z = tst1_z;
char* msg2 = strdup("abnormal behavior!");
int msg2_z = strlen(msg2) + 1;
int rlax_z = sizeof(rlax);
int opts_z = strlen(opts) + 1;
int text_z = strlen(text) + 1;
char* tst2 = strdup("shell has changed!");
int tst2_z = strlen(tst2) + 1;
char* chk2 = strdup(tst2);
int chk2_z = tst2_z;
char* name = strdup(file);
FILE * o;
int indx;
int numd = 0;
int done = 0;
/* Encrypt */
srand((unsigned)time(NULL)^(unsigned)getpid());
pswd_z = noise(pswd, pswd_z, 0, 0); numd++;
stte_0();
key(pswd, pswd_z);
msg1_z += strlen(mail);
msg1 = strcat(realloc(msg1, msg1_z), mail);
arc4(msg1, msg1_z); numd++;
arc4(date, date_z); numd++;
arc4(shll, shll_z); numd++;
arc4(inlo, inlo_z); numd++;
arc4(xecc, xecc_z); numd++;
arc4(lsto, lsto_z); numd++;
arc4(tst1, tst1_z); numd++;
key(chk1, chk1_z);
arc4(chk1, chk1_z); numd++;
arc4(msg2, msg2_z); numd++;
indx = !rlax[0];
arc4(rlax, rlax_z); numd++;
if (indx && key_with_file(kwsh)) {
fprintf(stderr, "%s: invalid file name: %s", my_name, kwsh);
perror("");
exit(1);
}
arc4(opts, opts_z); numd++;
arc4(text, text_z); numd++;
arc4(tst2, tst2_z); numd++;
key(chk2, chk2_z);
arc4(chk2, chk2_z); numd++;
/* Output */
name = strcat(realloc(name, strlen(name)+5), ".x.c");
o = fopen(name, "w");
if (!o) {
fprintf(stderr, "%s: creating output file: %s", my_name, name);
perror("");
exit(1);
}
fprintf(o, "#if 0\n");
fprintf(o, "\t%s %s, %s\n", my_name, version, subject);
fprintf(o, "\t%s %s %s %s\n\n\t", cpright, author.f, author.s, author.e);
for (indx = 0; argv[indx]; indx++)
fprintf(o, "%s ", argv[indx]);
fprintf(o, "\n#endif\n\n");
fprintf(o, "static char data [] = ");
do {
done = 0;
indx = rand_mod(15);
do {
switch (indx) {
case 0: if (pswd_z>=0) {prnt_array(o, pswd, "pswd", pswd_z, 0); pswd_z=done=-1; break;}
case 1: if (msg1_z>=0) {prnt_array(o, msg1, "msg1", msg1_z, 0); msg1_z=done=-1; break;}
case 2: if (date_z>=0) {prnt_array(o, date, "date", date_z, 0); date_z=done=-1; break;}
case 3: if (shll_z>=0) {prnt_array(o, shll, "shll", shll_z, 0); shll_z=done=-1; break;}
case 4: if (inlo_z>=0) {prnt_array(o, inlo, "inlo", inlo_z, 0); inlo_z=done=-1; break;}
case 5: if (xecc_z>=0) {prnt_array(o, xecc, "xecc", xecc_z, 0); xecc_z=done=-1; break;}
case 6: if (lsto_z>=0) {prnt_array(o, lsto, "lsto", lsto_z, 0); lsto_z=done=-1; break;}
case 7: if (tst1_z>=0) {prnt_array(o, tst1, "tst1", tst1_z, 0); tst1_z=done=-1; break;}
case 8: if (chk1_z>=0) {prnt_array(o, chk1, "chk1", chk1_z, 0); chk1_z=done=-1; break;}
case 9: if (msg2_z>=0) {prnt_array(o, msg2, "msg2", msg2_z, 0); msg2_z=done=-1; break;}
case 10: if (rlax_z>=0) {prnt_array(o, rlax, "rlax", rlax_z, 0); rlax_z=done=-1; break;}
case 11: if (opts_z>=0) {prnt_array(o, opts, "opts", opts_z, 0); opts_z=done=-1; break;}
case 12: if (text_z>=0) {prnt_array(o, text, "text", text_z, 0); text_z=done=-1; break;}
case 13: if (tst2_z>=0) {prnt_array(o, tst2, "tst2", tst2_z, 0); tst2_z=done=-1; break;}
case 14: if (chk2_z>=0) {prnt_array(o, chk2, "chk2", chk2_z, 0); chk2_z=done=-1; break;}
}
indx = 0;
} while (!done);
} while (numd+=done);
fprintf(o, "/* End of data[] */;\n");
fprintf(o, "#define %s_z %d\n", "hide", 1<<12);
fprintf(o, DEBUGEXEC_line, DEBUGEXEC_flag);
fprintf(o, TRACEABLE_line, TRACEABLE_flag);
for (indx = 0; RTC[indx]; indx++)
fprintf(o, "%s\n", RTC[indx]);
fflush(o);
fclose(o);
return 0;
}
int make(void)
{
char * cc, * cflags;
char cmd[SIZE];
cc = getenv("CC");
if (!cc)
cc = "cc";
cflags = getenv("CFLAGS");
if (!cflags)
cflags = "";
sprintf(cmd, "%s %s %s.x.c -o %s.x", cc, cflags, file, file);
if (verbose) fprintf(stderr, "%s: %s\n", my_name, cmd);
if (system(cmd))
return -1;
sprintf(cmd, "strip %s.x", file);
if (verbose) fprintf(stderr, "%s: %s\n", my_name, cmd);
if (system(cmd))
fprintf(stderr, "%s: never mind\n", my_name);
sprintf(cmd, "chmod go-r %s.x", file);
if (verbose) fprintf(stderr, "%s: %s\n", my_name, cmd);
if (system(cmd))
fprintf(stderr, "%s: remove read permission\n", my_name);
return 0;
}
void do_all(int argc, char * argv[])
{
parse_args(argc, argv);
text = read_script(file);
if (!text)
return;
if (eval_shell(text))
return;
if (write_C(file, argv))
return;
if (make())
return;
exit(0);
}
int main(int argc, char * argv[])
{
putenv("LANG=");
do_all(argc, argv);
/* Return on error */
perror(argv[0]);
exit(1);
return 1;
}
|
the_stack_data/1105215.c | #include<stdio.h>
main (){
//Question 1
int x,y;
printf("Enter 2 numbers: ");
scanf("%d",&x);
scanf("%d",&y);
if(x==y){
printf("X and Y are equal.");
}
else {
printf("X and Y are not equal.");
}
//Question 2
}
|
the_stack_data/100139859.c | const unsigned int megaShoot[32][32] = {
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 1, 2, 2, 2, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},//here
{0, 1, 2, 2, 2, 3, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},// here
{0, 1, 2, 2, 2, 2, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 1, 2, 2, 2, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
};
//0 = background
//1= black
//2=Beige
//3=white
|
the_stack_data/638510.c | #include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
int d;
if (argc < 2)
{
return 10;
}
d = open(argv[1], O_RDONLY);
if (d == -1)
{
perror("Error while opening a file");
exit(1);
}
printf("Descriptor number %d\n", d);
sleep(60); // check now under /proc/<proc num>/fd
close(d);
printf("Descriptor number %d\n", d);
sleep(30); // check now under /proc/<proc num>/fd
return 0;
}
|
the_stack_data/1148242.c | /***
* This code is a part of EvoApproxLib library (ehw.fit.vutbr.cz/approxlib) distributed under The MIT License.
* When used, please cite the following article(s): V. Mrazek, L. Sekanina, Z. Vasicek "Libraries of Approximate Circuits: Automated Design and Application in CNN Accelerators" IEEE Journal on Emerging and Selected Topics in Circuits and Systems, Vol 10, No 4, 2020
* This file contains a circuit from a sub-set of pareto optimal circuits with respect to the pwr and mae parameters
***/
// MAE% = 3.46 %
// MAE = 71
// WCE% = 14.50 %
// WCE = 297
// WCRE% = 125.00 %
// EP% = 86.62 %
// MRE% = 37.23 %
// MSE = 8553
// PDK45_PWR = 0.011 mW
// PDK45_AREA = 44.1 um2
// PDK45_DELAY = 0.29 ns
#include <stdint.h>
#include <stdlib.h>
uint64_t mul8x3u_00D(const uint64_t A,const uint64_t B)
{
uint64_t dout_24, dout_26, dout_32, dout_34, dout_63, dout_64, dout_66, dout_67, dout_68, dout_72, dout_81, dout_82, dout_83, dout_97, dout_98, dout_111;
uint64_t O;
dout_24=((A >> 6)&1)&((B >> 2)&1);
dout_26=((A >> 7)&1)&((B >> 1)&1);
dout_32=((A >> 5)&1)&((B >> 2)&1);
dout_34=((A >> 7)&1)&((B >> 2)&1);
dout_63=((B >> 1)&1)&((A >> 6)&1);
dout_64=((B >> 0)&1)&((A >> 7)&1);
dout_66=dout_63|dout_64;
dout_67=dout_26&dout_24;
dout_68=dout_26^dout_24;
dout_72=dout_68&((B >> 0)&1);
dout_81=dout_68^dout_66;
dout_82=dout_68&dout_66;
dout_83=dout_34^dout_67;
dout_97=dout_83^dout_82;
dout_98=dout_34&dout_72;
dout_111=dout_67|dout_98;
O = 0;
O |= (dout_111&1) << 0;
O |= (0&1) << 1;
O |= (0&1) << 2;
O |= (0&1) << 3;
O |= (dout_32&1) << 4;
O |= (dout_81&1) << 5;
O |= (dout_34&1) << 6;
O |= (dout_32&1) << 7;
O |= (dout_81&1) << 8;
O |= (dout_97&1) << 9;
O |= (dout_111&1) << 10;
return O;
}
|
the_stack_data/103264539.c | #include <netdb.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#define MYPORT 2220
#define BUF_LEN 1000
#define IP "127.0.0.1"
int main(){
int sock, len;
struct sockaddr_in serv;
socklen_t addlen = sizeof(serv);
char buf[BUF_LEN];
sock = socket(PF_INET, SOCK_STREAM, 0);
serv.sin_family = AF_INET;
serv.sin_port = htons(MYPORT);
inet_aton( "127.0.0.1",&serv.sin_addr);
if(connect(sock, (struct sockaddr *) &serv, addlen) != 0 ){
printf("connection with the server failed...\n");
exit(0);
}
while(1){
printf("Enviar mensagem: ");
scanf("%s", buf);
//fgets(buf,BUF_LEN, stdin);
len=send(sock, buf, strlen(buf)+1, 0);
if(!strcmp("exit", buf)){
printf("Closed");
break;
}
}
close(sock);
return 1;
} |
the_stack_data/71926.c | /* gcc.dg/tree-ssa/loadpre23.c used to ICE with Graphite. */
struct {
int a;
int large[100];
} x;
int foo(int argc)
{
int b;
int c;
int i;
int d, e;
for (i = 0; i < argc; i++)
{
e = x.a;
x.a = 9;
}
return d + e;
}
|
the_stack_data/14200782.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_check_clues.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: robitett <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/12/01 00:33:05 by robitett #+# #+# */
/* Updated: 2019/12/01 19:31:28 by dnascime ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
int from_down(int *matrix, int *clues, int col, int size)
{
int i;
int count;
i = 3;
count = 1;
while (i > 0)
{
if (*(matrix + (col * size) + i) < *(matrix + (col * size) + i - 1))
count++;
i--;
}
if (count == *(clues + (2 * size) + col))
return (1);
else
return (0);
}
int from_left(int *matrix, int *clues, int row, int size)
{
int i;
int count;
i = 0;
count = 1;
while (i < 3)
{
if (*(matrix + (row * size) + i) < *(matrix + (row * size) + i + 1))
count++;
i++;
}
if (count == *(clues + (2 * size) + row))
return (1);
else
return (0);
}
int from_right(int *matrix, int *clues, int row, int size)
{
int i;
int count;
i = 3;
count = 1;
while (i > 0)
{
if (*(matrix + (row * size) + i) < *(matrix + (row * size) + i - 1))
count++;
i--;
}
if (count == *(clues + (3 * size) + row))
return (1);
else
return (0);
}
int check_previous_rowcol(int *matrix, int size, int cursor)
{
int cur_row;
int cur_col;
int cur_number;
int i;
cur_col = cursor % size;
cur_row = cursor / size;
cur_number = *(matrix + cursor);
i = 0;
while (i < cur_row)
{
if (*(matrix + (i * size) + cur_col) == cur_number)
return (1);
i++;
}
i = 0;
while (i < cur_col)
{
if (*(matrix + (cur_row * size) + i) == cur_number)
return (1);
i++;
}
return (0);
}
int check_end_of_row(int *matrix, int *clues, int size, int cursor)
{
int row;
int col;
col = cursor % size;
row = cursor / size;
if ((cursor + 1) % (size) == 0)
{
if (from_right(matrix, clues, row, size) == 0)
return (1);
if (from_left(matrix, clues, row, size) == 0)
return (1);
}
return (0);
}
|
the_stack_data/1066571.c | /*
* libc/stdio/sprintf.c
* ANSI-compliant C standard i/o library.
* sprintf()
* ANSI 4.9.6.5.
* Formatted print into given string.
*/
#include <stdio.h>
#include <stdarg.h>
int
sprintf(s, format) char *s; const char *format;
{
va_list args;
va_start(args, format);
return vsprintf(s, format, args);
}
/* end of libc/stdio/sprintf.c */
|
the_stack_data/36074216.c | #include <stdlib.h>
int main() {
system("echo This is from system\n");
}
|
the_stack_data/98575461.c | #include <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#define BUFLEN 512
#define PORT 8888
void err(char *str)
{
perror(str);
exit(1);
}
int main(void)
{
struct sockaddr_in my_addr, cli_addr;
int sockfd, r;
socklen_t slen=sizeof(cli_addr);
char buf[BUFLEN];
fd_set rfds,_rfds;
if ((sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1)
err("socket");
else
printf("Server : Socket() successful\n");
bzero(&my_addr, sizeof(my_addr));
my_addr.sin_family = AF_INET;
my_addr.sin_port = htons(PORT);
my_addr.sin_addr.s_addr = htonl(INADDR_ANY);
if (bind(sockfd, (struct sockaddr* ) &my_addr, sizeof(my_addr))==-1)
err("bind");
else
printf("Server : bind() successful\n");
FD_ZERO(&rfds); FD_ZERO(&_rfds); FD_SET(sockfd, &rfds);
while(1)
{
memcpy( &_rfds, &rfds, sizeof(fd_set));
select( sockfd+1, &_rfds, NULL,NULL,NULL);
if (FD_ISSET(sockfd, &_rfds)) {
if (recvfrom(sockfd, buf, BUFLEN, 0, (struct sockaddr*)&cli_addr, &slen)==-1)
err("recvfrom()");
printf("Received packet from %s:%d\nData: %s\n\n",
inet_ntoa(cli_addr.sin_addr), ntohs(cli_addr.sin_port), buf);
} else printf("FALLTHROUGH IN select() with %d\n\n", r);
}
close(sockfd);
return 0;
}
|
the_stack_data/28263456.c | #include <stdio.h>
#include <stdlib.h>
struct Queue
{
int size;
int front;
int rear;
int *Q;
};
void create(struct Queue *q,int size)
{
q->size=size;
q->front=q->rear=0;
q->Q=(int *)malloc(q->size*sizeof(int));
}
void enqueue(struct Queue *q,int x)
{
if((q->rear+1)%q->size==q->front)
printf("Queue is Full");
else
{
q->rear=(q->rear+1)%q->size;
q->Q[q->rear]=x;
}
}
int dequeue(struct Queue *q)
{
int x=-1;
if(q->front==q->rear)
printf("Queue is Empty\n");
else
{
q->front=(q->front+1)%q->size;
x=q->Q[q->front];
}
return x;
}
void Display(struct Queue q)
{
int i=q.front+1;
do
{
printf("%d ",q.Q[i]);
i=(i+1)%q.size;
}while(i!=(q.rear+1)%q.size);
printf("\n");
}
int main()
{
struct Queue q;
create(&q,5);
enqueue(&q,10);
enqueue(&q,20);
enqueue(&q,30);
enqueue(&q,40);
enqueue(&q,50);
enqueue(&q,60);
Display(q);
printf("%d ",dequeue(&q));
return 0;
} |
the_stack_data/247017515.c | /**
******************************************************************************
* @file stm32l4xx_ll_rcc.c
* @author MCD Application Team
* @brief RCC LL module driver.
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2017 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
#if defined(USE_FULL_LL_DRIVER)
/* Includes ------------------------------------------------------------------*/
#include "stm32l4xx_ll_rcc.h"
#ifdef USE_FULL_ASSERT
#include "stm32_assert.h"
#else
#define assert_param(expr) ((void)0U)
#endif
/** @addtogroup STM32L4xx_LL_Driver
* @{
*/
#if defined(RCC)
/** @addtogroup RCC_LL
* @{
*/
/* Private types -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private constants ---------------------------------------------------------*/
/* Private macros ------------------------------------------------------------*/
/** @addtogroup RCC_LL_Private_Macros
* @{
*/
#if defined(RCC_CCIPR_USART3SEL)
#define IS_LL_RCC_USART_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_USART1_CLKSOURCE) \
|| ((__VALUE__) == LL_RCC_USART2_CLKSOURCE) \
|| ((__VALUE__) == LL_RCC_USART3_CLKSOURCE))
#else
#define IS_LL_RCC_USART_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_USART1_CLKSOURCE) \
|| ((__VALUE__) == LL_RCC_USART2_CLKSOURCE))
#endif /* RCC_CCIPR_USART3SEL */
#if defined(RCC_CCIPR_UART4SEL) && defined(RCC_CCIPR_UART5SEL)
#define IS_LL_RCC_UART_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_UART4_CLKSOURCE) \
|| ((__VALUE__) == LL_RCC_UART5_CLKSOURCE))
#elif defined(RCC_CCIPR_UART4SEL)
#define IS_LL_RCC_UART_CLKSOURCE(__VALUE__) ((__VALUE__) == LL_RCC_UART4_CLKSOURCE)
#elif defined(RCC_CCIPR_UART5SEL)
#define IS_LL_RCC_UART_CLKSOURCE(__VALUE__) ((__VALUE__) == LL_RCC_UART5_CLKSOURCE)
#endif /* RCC_CCIPR_UART4SEL && RCC_CCIPR_UART5SEL*/
#define IS_LL_RCC_LPUART_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_LPUART1_CLKSOURCE))
#if defined(RCC_CCIPR_I2C2SEL) && defined(RCC_CCIPR_I2C3SEL) && defined(RCC_CCIPR2_I2C4SEL)
#define IS_LL_RCC_I2C_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_I2C1_CLKSOURCE) \
|| ((__VALUE__) == LL_RCC_I2C2_CLKSOURCE) \
|| ((__VALUE__) == LL_RCC_I2C3_CLKSOURCE) \
|| ((__VALUE__) == LL_RCC_I2C4_CLKSOURCE))
#elif defined(RCC_CCIPR_I2C2SEL) && defined(RCC_CCIPR_I2C3SEL)
#define IS_LL_RCC_I2C_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_I2C1_CLKSOURCE) \
|| ((__VALUE__) == LL_RCC_I2C2_CLKSOURCE) \
|| ((__VALUE__) == LL_RCC_I2C3_CLKSOURCE))
#elif !defined(RCC_CCIPR_I2C2SEL) && 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_I2C2SEL && RCC_CCIPR_I2C3SEL && RCC_CCIPR2_I2C4SEL */
#define IS_LL_RCC_LPTIM_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_LPTIM1_CLKSOURCE) \
|| ((__VALUE__) == LL_RCC_LPTIM2_CLKSOURCE))
#if defined(RCC_CCIPR_SAI2SEL) || defined(RCC_CCIPR2_SAI2SEL)
#define IS_LL_RCC_SAI_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_SAI1_CLKSOURCE) \
|| ((__VALUE__) == LL_RCC_SAI2_CLKSOURCE))
#elif defined(RCC_CCIPR_SAI1SEL) || defined(RCC_CCIPR2_SAI1SEL)
#define IS_LL_RCC_SAI_CLKSOURCE(__VALUE__) ((__VALUE__) == LL_RCC_SAI1_CLKSOURCE)
#endif /* RCC_CCIPR_SAI2SEL RCC_CCIPR2_SAI2SEL ||*/
#if defined(SDMMC1)
#if defined(RCC_CCIPR2_SDMMCSEL)
#define IS_LL_RCC_SDMMC_KERNELCLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_SDMMC1_KERNELCLKSOURCE))
#endif /* RCC_CCIPR2_SDMMCSEL */
#define IS_LL_RCC_SDMMC_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_SDMMC1_CLKSOURCE))
#endif /* SDMMC1 */
#define IS_LL_RCC_RNG_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_RNG_CLKSOURCE))
#if defined(USB_OTG_FS) || defined(USB)
#define IS_LL_RCC_USB_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_USB_CLKSOURCE))
#endif /* USB_OTG_FS || USB */
#define IS_LL_RCC_ADC_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_ADC_CLKSOURCE))
#if defined(SWPMI1)
#define IS_LL_RCC_SWPMI_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_SWPMI1_CLKSOURCE))
#endif /* SWPMI1 */
#if defined(DFSDM1_Channel0)
#define IS_LL_RCC_DFSDM_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_DFSDM1_CLKSOURCE))
#if defined(RCC_CCIPR2_DFSDM1SEL)
#define IS_LL_RCC_DFSDM_AUDIO_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_DFSDM1_AUDIO_CLKSOURCE))
#endif /* RCC_CCIPR2_DFSDM1SEL */
#endif /* DFSDM1_Channel0 */
#if defined(DSI)
#define IS_LL_RCC_DSI_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_DSI_CLKSOURCE))
#endif /* DSI */
#if defined(LTDC)
#define IS_LL_RCC_LTDC_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_LTDC_CLKSOURCE))
#endif /* LTDC */
#if defined(OCTOSPI1)
#define IS_LL_RCC_OCTOSPI_CLKSOURCE(__VALUE__) (((__VALUE__) == LL_RCC_OCTOSPI_CLKSOURCE))
#endif /* OCTOSPI */
/**
* @}
*/
/* 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);
uint32_t RCC_PLL_GetFreqDomain_SAI(void);
uint32_t RCC_PLL_GetFreqDomain_48M(void);
#if defined(RCC_PLLSAI1_SUPPORT)
uint32_t RCC_PLLSAI1_GetFreqDomain_SAI(void);
uint32_t RCC_PLLSAI1_GetFreqDomain_48M(void);
uint32_t RCC_PLLSAI1_GetFreqDomain_ADC(void);
#endif /* RCC_PLLSAI1_SUPPORT */
#if defined(RCC_PLLSAI2_SUPPORT)
uint32_t RCC_PLLSAI2_GetFreqDomain_SAI(void);
#if defined(LTDC)
uint32_t RCC_PLLSAI2_GetFreqDomain_LTDC(void);
#else
uint32_t RCC_PLLSAI2_GetFreqDomain_ADC(void);
#endif /* LTDC */
#if defined(DSI)
uint32_t RCC_PLLSAI2_GetFreqDomain_DSI(void);
#endif /* DSI */
#endif /*RCC_PLLSAI2_SUPPORT*/
/**
* @}
*/
/* 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, PLL, PLLSAI1 and PLLSAI2 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)
{
__IO uint32_t vl_mask;
/* Set MSION bit */
LL_RCC_MSI_Enable();
/* Insure MSIRDY bit is set before writing default MSIRANGE value */
while (LL_RCC_MSI_IsReady() == 0U)
{
}
/* Set MSIRANGE default value */
LL_RCC_MSI_SetRange(LL_RCC_MSIRANGE_6);
/* Set MSITRIM bits to the reset value*/
LL_RCC_MSI_SetCalibTrimming(0);
/* Set HSITRIM bits to the reset value*/
#if defined(RCC_ICSCR_HSITRIM_6)
LL_RCC_HSI_SetCalibTrimming(0x40U);
#else
LL_RCC_HSI_SetCalibTrimming(0x10U);
#endif /* RCC_ICSCR_HSITRIM_6 */
/* Reset CFGR register */
LL_RCC_WriteReg(CFGR, 0x00000000U);
/* Read CR register */
vl_mask = LL_RCC_ReadReg(CR);
/* Reset HSION, HSIKERON, HSIASFS, HSEON, PLLON bits */
CLEAR_BIT(vl_mask,
(RCC_CR_HSION | RCC_CR_HSIASFS | RCC_CR_HSIKERON | RCC_CR_HSEON | RCC_CR_PLLON));
#if defined(RCC_PLLSAI1_SUPPORT)
/* Reset PLLSAI1ON bit */
CLEAR_BIT(vl_mask, RCC_CR_PLLSAI1ON);
#endif /*RCC_PLLSAI1_SUPPORT*/
#if defined(RCC_PLLSAI2_SUPPORT)
/* Reset PLLSAI2ON bit */
CLEAR_BIT(vl_mask, RCC_CR_PLLSAI2ON);
#endif /*RCC_PLLSAI2_SUPPORT*/
/* Write new value in CR register */
LL_RCC_WriteReg(CR, vl_mask);
#if defined(RCC_PLLSAI2_SUPPORT)
/* Wait for PLLRDY, PLLSAI1RDY and PLLSAI2RDY bits to be reset */
while(READ_BIT(RCC->CR, RCC_CR_PLLRDY | RCC_CR_PLLSAI1RDY | RCC_CR_PLLSAI2RDY) != 0U)
{
}
#elif defined(RCC_PLLSAI1_SUPPORT)
/* Wait for PLLRDY and PLLSAI1RDY to be reset */
while(READ_BIT(RCC->CR, RCC_CR_PLLRDY | RCC_CR_PLLSAI1RDY) != 0U)
{
}
#else
/* Wait for PLLRDY bit to be reset */
while(READ_BIT(RCC->CR, RCC_CR_PLLRDY) != 0U)
{
}
#endif
/* Reset PLLCFGR register */
LL_RCC_WriteReg(PLLCFGR, 16U << RCC_PLLCFGR_PLLN_Pos);
#if defined(RCC_PLLSAI1_SUPPORT)
/* Reset PLLSAI1CFGR register */
LL_RCC_WriteReg(PLLSAI1CFGR, 16U << RCC_PLLSAI1CFGR_PLLSAI1N_Pos);
#endif /*RCC_PLLSAI1_SUPPORT*/
#if defined(RCC_PLLSAI2_SUPPORT)
/* Reset PLLSAI2CFGR register */
LL_RCC_WriteReg(PLLSAI2CFGR, 16U << RCC_PLLSAI2CFGR_PLLSAI2N_Pos);
#endif /*RCC_PLLSAI2_SUPPORT*/
/* Reset HSEBYP bit */
LL_RCC_HSE_DisableBypass();
/* Disable all interrupts */
LL_RCC_WriteReg(CIER, 0x00000000U);
/* Clear all interrupt flags */
vl_mask = RCC_CICR_LSIRDYC | RCC_CICR_LSERDYC | RCC_CICR_MSIRDYC | RCC_CICR_HSIRDYC | RCC_CICR_HSERDYC | RCC_CICR_PLLRDYC | \
RCC_CICR_CSSC | RCC_CICR_LSECSSC;
#if defined(RCC_HSI48_SUPPORT)
vl_mask |= RCC_CICR_HSI48RDYC;
#endif
#if defined(RCC_PLLSAI1_SUPPORT)
vl_mask |= RCC_CICR_PLLSAI1RDYC;
#endif
#if defined(RCC_PLLSAI2_SUPPORT)
vl_mask |= RCC_CICR_PLLSAI2RDYC;
#endif
LL_RCC_WriteReg(CICR, vl_mask);
/* Clear reset flags */
LL_RCC_ClearResetFlags();
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_VALUE(*)
* @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 HSE_VALUE(***)
* or HSI_VALUE(**) or MSI_VALUE(*) multiplied/divided by the PLL factors.
* @note (*) MSI_VALUE is a constant defined in this file (default value
* 4 MHz) but the real value may vary depending on the variations
* in voltage and temperature.
* @note (**) HSI_VALUE is a constant defined in this file (default value
* 16 MHz) but the real value may vary depending on the variations
* in voltage and temperature.
* @note (***) HSE_VALUE is a constant defined in this file (default value
* 8 MHz), 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
* @arg @ref LL_RCC_USART3_CLKSOURCE (*)
*
* (*) value not defined in all devices.
* @retval USART clock frequency (in Hz)
* - @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 (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() != 0U)
{
usart_frequency = HSI_VALUE;
}
break;
case LL_RCC_USART1_CLKSOURCE_LSE: /* USART1 Clock is LSE Osc. */
if (LL_RCC_LSE_IsReady() != 0U)
{
usart_frequency = LSE_VALUE;
}
break;
case LL_RCC_USART1_CLKSOURCE_PCLK2: /* USART1 Clock is PCLK2 */
usart_frequency = RCC_GetPCLK2ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
break;
default:
break;
}
}
else 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() != 0U)
{
usart_frequency = HSI_VALUE;
}
break;
case LL_RCC_USART2_CLKSOURCE_LSE: /* USART2 Clock is LSE Osc. */
if (LL_RCC_LSE_IsReady() != 0U)
{
usart_frequency = LSE_VALUE;
}
break;
case LL_RCC_USART2_CLKSOURCE_PCLK1: /* USART2 Clock is PCLK1 */
usart_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
break;
default:
break;
}
}
else
{
#if defined(RCC_CCIPR_USART3SEL)
if (USARTxSource == LL_RCC_USART3_CLKSOURCE)
{
/* USART3CLK clock frequency */
switch (LL_RCC_GetUSARTClockSource(USARTxSource))
{
case LL_RCC_USART3_CLKSOURCE_SYSCLK: /* USART3 Clock is System Clock */
usart_frequency = RCC_GetSystemClockFreq();
break;
case LL_RCC_USART3_CLKSOURCE_HSI: /* USART3 Clock is HSI Osc. */
if (LL_RCC_HSI_IsReady() != 0U)
{
usart_frequency = HSI_VALUE;
}
break;
case LL_RCC_USART3_CLKSOURCE_LSE: /* USART3 Clock is LSE Osc. */
if (LL_RCC_LSE_IsReady() != 0U)
{
usart_frequency = LSE_VALUE;
}
break;
case LL_RCC_USART3_CLKSOURCE_PCLK1: /* USART3 Clock is PCLK1 */
usart_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
break;
default:
break;
}
}
#endif /* RCC_CCIPR_USART3SEL */
}
return usart_frequency;
}
#if defined(RCC_CCIPR_UART4SEL) || defined(RCC_CCIPR_UART5SEL)
/**
* @brief Return UARTx clock frequency
* @param UARTxSource This parameter can be one of the following values:
* @arg @ref LL_RCC_UART4_CLKSOURCE
* @arg @ref LL_RCC_UART5_CLKSOURCE
* @retval UART clock frequency (in Hz)
* - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (HSI or LSE) is not ready
*/
uint32_t LL_RCC_GetUARTClockFreq(uint32_t UARTxSource)
{
uint32_t uart_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
/* Check parameter */
assert_param(IS_LL_RCC_UART_CLKSOURCE(UARTxSource));
#if defined(RCC_CCIPR_UART4SEL)
if (UARTxSource == LL_RCC_UART4_CLKSOURCE)
{
/* UART4CLK clock frequency */
switch (LL_RCC_GetUARTClockSource(UARTxSource))
{
case LL_RCC_UART4_CLKSOURCE_SYSCLK: /* UART4 Clock is System Clock */
uart_frequency = RCC_GetSystemClockFreq();
break;
case LL_RCC_UART4_CLKSOURCE_HSI: /* UART4 Clock is HSI Osc. */
if (LL_RCC_HSI_IsReady() != 0U)
{
uart_frequency = HSI_VALUE;
}
break;
case LL_RCC_UART4_CLKSOURCE_LSE: /* UART4 Clock is LSE Osc. */
if (LL_RCC_LSE_IsReady() != 0U)
{
uart_frequency = LSE_VALUE;
}
break;
case LL_RCC_UART4_CLKSOURCE_PCLK1: /* UART4 Clock is PCLK1 */
uart_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
break;
default:
break;
}
}
#endif /* RCC_CCIPR_UART4SEL */
#if defined(RCC_CCIPR_UART5SEL)
if (UARTxSource == LL_RCC_UART5_CLKSOURCE)
{
/* UART5CLK clock frequency */
switch (LL_RCC_GetUARTClockSource(UARTxSource))
{
case LL_RCC_UART5_CLKSOURCE_SYSCLK: /* UART5 Clock is System Clock */
uart_frequency = RCC_GetSystemClockFreq();
break;
case LL_RCC_UART5_CLKSOURCE_HSI: /* UART5 Clock is HSI Osc. */
if (LL_RCC_HSI_IsReady() != 0U)
{
uart_frequency = HSI_VALUE;
}
break;
case LL_RCC_UART5_CLKSOURCE_LSE: /* UART5 Clock is LSE Osc. */
if (LL_RCC_LSE_IsReady() != 0U)
{
uart_frequency = LSE_VALUE;
}
break;
case LL_RCC_UART5_CLKSOURCE_PCLK1: /* UART5 Clock is PCLK1 */
uart_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
break;
default:
break;
}
}
#endif /* RCC_CCIPR_UART5SEL */
return uart_frequency;
}
#endif /* RCC_CCIPR_UART4SEL || RCC_CCIPR_UART5SEL */
/**
* @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_I2C2_CLKSOURCE (*)
* @arg @ref LL_RCC_I2C3_CLKSOURCE
* @arg @ref LL_RCC_I2C4_CLKSOURCE (*)
*
* (*) value not defined in all devices.
* @retval I2C clock frequency (in Hz)
* - @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));
if (I2CxSource == LL_RCC_I2C1_CLKSOURCE)
{
/* I2C1 CLK clock frequency */
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() != 0U)
{
i2c_frequency = HSI_VALUE;
}
break;
case LL_RCC_I2C1_CLKSOURCE_PCLK1: /* I2C1 Clock is PCLK1 */
i2c_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
break;
default:
break;
}
}
#if defined(RCC_CCIPR_I2C2SEL)
else if (I2CxSource == LL_RCC_I2C2_CLKSOURCE)
{
/* I2C2 CLK clock frequency */
switch (LL_RCC_GetI2CClockSource(I2CxSource))
{
case LL_RCC_I2C2_CLKSOURCE_SYSCLK: /* I2C2 Clock is System Clock */
i2c_frequency = RCC_GetSystemClockFreq();
break;
case LL_RCC_I2C2_CLKSOURCE_HSI: /* I2C2 Clock is HSI Osc. */
if (LL_RCC_HSI_IsReady() != 0U)
{
i2c_frequency = HSI_VALUE;
}
break;
case LL_RCC_I2C2_CLKSOURCE_PCLK1: /* I2C2 Clock is PCLK1 */
i2c_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
break;
default:
break;
}
}
#endif /*RCC_CCIPR_I2C2SEL*/
else
{
if (I2CxSource == LL_RCC_I2C3_CLKSOURCE)
{
/* I2C3 CLK clock frequency */
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() != 0U)
{
i2c_frequency = HSI_VALUE;
}
break;
case LL_RCC_I2C3_CLKSOURCE_PCLK1: /* I2C3 Clock is PCLK1 */
i2c_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
break;
default:
break;
}
}
#if defined(RCC_CCIPR2_I2C4SEL)
else
{
if (I2CxSource == LL_RCC_I2C4_CLKSOURCE)
{
/* I2C4 CLK clock frequency */
switch (LL_RCC_GetI2CClockSource(I2CxSource))
{
case LL_RCC_I2C4_CLKSOURCE_SYSCLK: /* I2C4 Clock is System Clock */
i2c_frequency = RCC_GetSystemClockFreq();
break;
case LL_RCC_I2C4_CLKSOURCE_HSI: /* I2C4 Clock is HSI Osc. */
if (LL_RCC_HSI_IsReady() != 0U)
{
i2c_frequency = HSI_VALUE;
}
break;
case LL_RCC_I2C4_CLKSOURCE_PCLK1: /* I2C4 Clock is PCLK1 */
i2c_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
break;
default:
break;
}
}
}
#endif /*RCC_CCIPR2_I2C4SEL*/
}
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)
* - @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() != 0U)
{
lpuart_frequency = HSI_VALUE;
}
break;
case LL_RCC_LPUART1_CLKSOURCE_LSE: /* LPUART1 Clock is LSE Osc. */
if (LL_RCC_LSE_IsReady() != 0U)
{
lpuart_frequency = LSE_VALUE;
}
break;
case LL_RCC_LPUART1_CLKSOURCE_PCLK1: /* LPUART1 Clock is PCLK1 */
lpuart_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
break;
default:
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
* @arg @ref LL_RCC_LPTIM2_CLKSOURCE
* @retval LPTIM clock frequency (in Hz)
* - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (HSI, LSI 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() != 0U)
{
#if defined(RCC_CSR_LSIPREDIV)
if (LL_RCC_LSI_GetPrediv() == LL_RCC_LSI_PREDIV_128)
{
lptim_frequency = LSI_VALUE / 128U;
}
else
#endif /* RCC_CSR_LSIPREDIV */
{
lptim_frequency = LSI_VALUE;
}
}
break;
case LL_RCC_LPTIM1_CLKSOURCE_HSI: /* LPTIM1 Clock is HSI Osc. */
if (LL_RCC_HSI_IsReady() != 0U)
{
lptim_frequency = HSI_VALUE;
}
break;
case LL_RCC_LPTIM1_CLKSOURCE_LSE: /* LPTIM1 Clock is LSE Osc. */
if (LL_RCC_LSE_IsReady() != 0U)
{
lptim_frequency = LSE_VALUE;
}
break;
case LL_RCC_LPTIM1_CLKSOURCE_PCLK1: /* LPTIM1 Clock is PCLK1 */
lptim_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
break;
default:
break;
}
}
else
{
if (LPTIMxSource == LL_RCC_LPTIM2_CLKSOURCE)
{
/* LPTIM2CLK clock frequency */
switch (LL_RCC_GetLPTIMClockSource(LPTIMxSource))
{
case LL_RCC_LPTIM2_CLKSOURCE_LSI: /* LPTIM2 Clock is LSI Osc. */
if (LL_RCC_LSI_IsReady() != 0U)
{
#if defined(RCC_CSR_LSIPREDIV)
if (LL_RCC_LSI_GetPrediv() == LL_RCC_LSI_PREDIV_128)
{
lptim_frequency = LSI_VALUE / 128U;
}
else
#endif /* RCC_CSR_LSIPREDIV */
{
lptim_frequency = LSI_VALUE;
}
}
break;
case LL_RCC_LPTIM2_CLKSOURCE_HSI: /* LPTIM2 Clock is HSI Osc. */
if (LL_RCC_HSI_IsReady() != 0U)
{
lptim_frequency = HSI_VALUE;
}
break;
case LL_RCC_LPTIM2_CLKSOURCE_LSE: /* LPTIM2 Clock is LSE Osc. */
if (LL_RCC_LSE_IsReady() != 0U)
{
lptim_frequency = LSE_VALUE;
}
break;
case LL_RCC_LPTIM2_CLKSOURCE_PCLK1: /* LPTIM2 Clock is PCLK1 */
lptim_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
break;
default:
break;
}
}
}
return lptim_frequency;
}
#if defined(RCC_CCIPR_SAI1SEL) || defined(RCC_CCIPR_SAI2SEL) || defined(RCC_CCIPR2_SAI1SEL) || defined(RCC_CCIPR2_SAI2SEL)
/**
* @brief Return SAIx clock frequency
* @param SAIxSource This parameter can be one of the following values:
* @arg @ref LL_RCC_SAI1_CLKSOURCE
* @arg @ref LL_RCC_SAI2_CLKSOURCE (*)
*
* (*) value not defined in all devices.
* @retval SAI clock frequency (in Hz)
* - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that PLL is not ready
*/
uint32_t LL_RCC_GetSAIClockFreq(uint32_t SAIxSource)
{
uint32_t sai_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
/* Check parameter */
assert_param(IS_LL_RCC_SAI_CLKSOURCE(SAIxSource));
if (SAIxSource == LL_RCC_SAI1_CLKSOURCE)
{
/* SAI1CLK clock frequency */
switch (LL_RCC_GetSAIClockSource(SAIxSource))
{
case LL_RCC_SAI1_CLKSOURCE_PLLSAI1: /* PLLSAI1 clock used as SAI1 clock source */
if (LL_RCC_PLLSAI1_IsReady() != 0U)
{
sai_frequency = RCC_PLLSAI1_GetFreqDomain_SAI();
}
break;
#if defined(RCC_PLLSAI2_SUPPORT)
case LL_RCC_SAI1_CLKSOURCE_PLLSAI2: /* PLLSAI2 clock used as SAI1 clock source */
if (LL_RCC_PLLSAI2_IsReady() != 0U)
{
sai_frequency = RCC_PLLSAI2_GetFreqDomain_SAI();
}
break;
#endif /* RCC_PLLSAI2_SUPPORT */
case LL_RCC_SAI1_CLKSOURCE_PLL: /* PLL clock used as SAI1 clock source */
if (LL_RCC_PLL_IsReady() != 0U)
{
sai_frequency = RCC_PLL_GetFreqDomain_SAI();
}
break;
case LL_RCC_SAI1_CLKSOURCE_PIN: /* External input clock used as SAI1 clock source */
sai_frequency = EXTERNAL_SAI1_CLOCK_VALUE;
break;
default:
break;
}
}
else
{
#if defined(RCC_CCIPR_SAI2SEL) || defined(RCC_CCIPR2_SAI2SEL)
if (SAIxSource == LL_RCC_SAI2_CLKSOURCE)
{
/* SAI2CLK clock frequency */
switch (LL_RCC_GetSAIClockSource(SAIxSource))
{
case LL_RCC_SAI2_CLKSOURCE_PLLSAI1: /* PLLSAI1 clock used as SAI2 clock source */
if (LL_RCC_PLLSAI1_IsReady() != 0U)
{
sai_frequency = RCC_PLLSAI1_GetFreqDomain_SAI();
}
break;
#if defined(RCC_PLLSAI2_SUPPORT)
case LL_RCC_SAI2_CLKSOURCE_PLLSAI2: /* PLLSAI2 clock used as SAI2 clock source */
if (LL_RCC_PLLSAI2_IsReady() != 0U)
{
sai_frequency = RCC_PLLSAI2_GetFreqDomain_SAI();
}
break;
#endif /* RCC_PLLSAI2_SUPPORT */
case LL_RCC_SAI2_CLKSOURCE_PLL: /* PLL clock used as SAI2 clock source */
if (LL_RCC_PLL_IsReady() != 0U)
{
sai_frequency = RCC_PLL_GetFreqDomain_SAI();
}
break;
case LL_RCC_SAI2_CLKSOURCE_PIN: /* External input clock used as SAI2 clock source */
sai_frequency = EXTERNAL_SAI2_CLOCK_VALUE;
break;
default:
break;
}
}
#endif /* RCC_CCIPR_SAI2SEL || RCC_CCIPR2_SAI2SEL */
}
return sai_frequency;
}
#endif /* RCC_CCIPR_SAI1SEL || RCC_CCIPR_SAI2SEL || RCC_CCIPR2_SAI1SEL || RCC_CCIPR2_SAI2SEL*/
#if defined(SDMMC1)
#if defined(RCC_CCIPR2_SDMMCSEL)
/**
* @brief Return SDMMCx kernel clock frequency
* @param SDMMCxSource This parameter can be one of the following values:
* @arg @ref LL_RCC_SDMMC1_KERNELCLKSOURCE
* @retval SDMMC clock frequency (in Hz)
* - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (MSI) or PLL is not ready
* - @ref LL_RCC_PERIPH_FREQUENCY_NA indicates that no clock source selected
*/
uint32_t LL_RCC_GetSDMMCKernelClockFreq(uint32_t SDMMCxSource)
{
uint32_t sdmmc_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
/* Check parameter */
assert_param(IS_LL_RCC_SDMMC_KERNELCLKSOURCE(SDMMCxSource));
/* SDMMC1CLK kernel clock frequency */
switch (LL_RCC_GetSDMMCKernelClockSource(SDMMCxSource))
{
case LL_RCC_SDMMC1_KERNELCLKSOURCE_48CLK: /* 48MHz clock from internal multiplexor used as SDMMC1 clock source */
sdmmc_frequency = LL_RCC_GetSDMMCClockFreq(LL_RCC_SDMMC1_CLKSOURCE);
break;
case LL_RCC_SDMMC1_KERNELCLKSOURCE_PLLP: /* PLL "P" output (PLLSAI3CLK) clock used as SDMMC1 clock source */
if (LL_RCC_PLL_IsReady() != 0U)
{
sdmmc_frequency = RCC_PLL_GetFreqDomain_SAI();
}
break;
default:
sdmmc_frequency = LL_RCC_PERIPH_FREQUENCY_NA;
break;
}
return sdmmc_frequency;
}
#endif
/**
* @brief Return SDMMCx clock frequency
* @param SDMMCxSource This parameter can be one of the following values:
* @arg @ref LL_RCC_SDMMC1_CLKSOURCE
* @retval SDMMC clock frequency (in Hz)
* - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (MSI) or PLL is not ready
* - @ref LL_RCC_PERIPH_FREQUENCY_NA indicates that no clock source selected
*/
uint32_t LL_RCC_GetSDMMCClockFreq(uint32_t SDMMCxSource)
{
uint32_t sdmmc_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
/* Check parameter */
assert_param(IS_LL_RCC_SDMMC_CLKSOURCE(SDMMCxSource));
/* SDMMC1CLK clock frequency */
switch (LL_RCC_GetSDMMCClockSource(SDMMCxSource))
{
#if defined(LL_RCC_SDMMC1_CLKSOURCE_PLLSAI1)
case LL_RCC_SDMMC1_CLKSOURCE_PLLSAI1: /* PLLSAI1 clock used as SDMMC1 clock source */
if (LL_RCC_PLLSAI1_IsReady() != 0U)
{
sdmmc_frequency = RCC_PLLSAI1_GetFreqDomain_48M();
}
break;
#endif
case LL_RCC_SDMMC1_CLKSOURCE_PLL: /* PLL clock used as SDMMC1 clock source */
if (LL_RCC_PLL_IsReady() != 0U)
{
sdmmc_frequency = RCC_PLL_GetFreqDomain_48M();
}
break;
#if defined(LL_RCC_SDMMC1_CLKSOURCE_MSI)
case LL_RCC_SDMMC1_CLKSOURCE_MSI: /* MSI clock used as SDMMC1 clock source */
if (LL_RCC_MSI_IsReady() != 0U)
{
sdmmc_frequency = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(),
((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ?
LL_RCC_MSI_GetRange() :
LL_RCC_MSI_GetRangeAfterStandby()));
}
break;
#endif
#if defined(RCC_HSI48_SUPPORT)
case LL_RCC_SDMMC1_CLKSOURCE_HSI48: /* HSI48 used as SDMMC1 clock source */
if (LL_RCC_HSI48_IsReady() != 0U)
{
sdmmc_frequency = HSI48_VALUE;
}
break;
#else
case LL_RCC_SDMMC1_CLKSOURCE_NONE: /* No clock used as SDMMC1 clock source */
#endif
default:
sdmmc_frequency = LL_RCC_PERIPH_FREQUENCY_NA;
break;
}
return sdmmc_frequency;
}
#endif /* SDMMC1 */
/**
* @brief Return RNGx clock frequency
* @param RNGxSource This parameter can be one of the following values:
* @arg @ref LL_RCC_RNG_CLKSOURCE
* @retval RNG clock frequency (in Hz)
* - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (MSI) or PLL is not ready
* - @ref LL_RCC_PERIPH_FREQUENCY_NA indicates that no clock source selected
*/
uint32_t LL_RCC_GetRNGClockFreq(uint32_t RNGxSource)
{
uint32_t rng_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
/* Check parameter */
assert_param(IS_LL_RCC_RNG_CLKSOURCE(RNGxSource));
/* RNGCLK clock frequency */
switch (LL_RCC_GetRNGClockSource(RNGxSource))
{
#if defined(RCC_PLLSAI1_SUPPORT)
case LL_RCC_RNG_CLKSOURCE_PLLSAI1: /* PLLSAI1 clock used as RNG clock source */
if (LL_RCC_PLLSAI1_IsReady() != 0U)
{
rng_frequency = RCC_PLLSAI1_GetFreqDomain_48M();
}
break;
#endif /* RCC_PLLSAI1_SUPPORT */
case LL_RCC_RNG_CLKSOURCE_PLL: /* PLL clock used as RNG clock source */
if (LL_RCC_PLL_IsReady() != 0U)
{
rng_frequency = RCC_PLL_GetFreqDomain_48M();
}
break;
case LL_RCC_RNG_CLKSOURCE_MSI: /* MSI clock used as RNG clock source */
if (LL_RCC_MSI_IsReady() != 0U)
{
rng_frequency = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(),
((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ?
LL_RCC_MSI_GetRange() :
LL_RCC_MSI_GetRangeAfterStandby()));
}
break;
#if defined(RCC_HSI48_SUPPORT)
case LL_RCC_RNG_CLKSOURCE_HSI48: /* HSI48 used as RNG clock source */
if (LL_RCC_HSI48_IsReady() != 0U)
{
rng_frequency = HSI48_VALUE;
}
break;
#else
case LL_RCC_RNG_CLKSOURCE_NONE: /* No clock used as RNG clock source */
#endif
default:
rng_frequency = LL_RCC_PERIPH_FREQUENCY_NA;
break;
}
return rng_frequency;
}
#if defined(USB_OTG_FS)||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)
* - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (MSI) or PLL is not ready
* - @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))
{
#if defined(RCC_PLLSAI1_SUPPORT)
case LL_RCC_USB_CLKSOURCE_PLLSAI1: /* PLLSAI1 clock used as USB clock source */
if (LL_RCC_PLLSAI1_IsReady() != 0U)
{
usb_frequency = RCC_PLLSAI1_GetFreqDomain_48M();
}
break;
#endif /* RCC_PLLSAI1_SUPPORT */
case LL_RCC_USB_CLKSOURCE_PLL: /* PLL clock used as USB clock source */
if (LL_RCC_PLL_IsReady() != 0U)
{
usb_frequency = RCC_PLL_GetFreqDomain_48M();
}
break;
case LL_RCC_USB_CLKSOURCE_MSI: /* MSI clock used as USB clock source */
if (LL_RCC_MSI_IsReady() != 0U)
{
usb_frequency = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(),
((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ?
LL_RCC_MSI_GetRange() :
LL_RCC_MSI_GetRangeAfterStandby()));
}
break;
#if defined(RCC_HSI48_SUPPORT)
case LL_RCC_USB_CLKSOURCE_HSI48: /* HSI48 used as USB clock source */
if (LL_RCC_HSI48_IsReady() != 0U)
{
usb_frequency = HSI48_VALUE;
}
break;
#else
case LL_RCC_USB_CLKSOURCE_NONE: /* No clock used as USB clock source */
#endif
default:
usb_frequency = LL_RCC_PERIPH_FREQUENCY_NA;
break;
}
return usb_frequency;
}
#endif /* USB_OTG_FS || USB */
/**
* @brief Return ADCx clock frequency
* @param ADCxSource This parameter can be one of the following values:
* @arg @ref LL_RCC_ADC_CLKSOURCE
* @retval ADC clock frequency (in Hz)
* - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (MSI) or PLL is not ready
* - @ref LL_RCC_PERIPH_FREQUENCY_NA indicates that no clock source selected
*/
uint32_t LL_RCC_GetADCClockFreq(uint32_t ADCxSource)
{
uint32_t adc_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
/* Check parameter */
assert_param(IS_LL_RCC_ADC_CLKSOURCE(ADCxSource));
/* ADCCLK clock frequency */
switch (LL_RCC_GetADCClockSource(ADCxSource))
{
#if defined(RCC_PLLSAI1_SUPPORT)
case LL_RCC_ADC_CLKSOURCE_PLLSAI1: /* PLLSAI1 clock used as ADC clock source */
if (LL_RCC_PLLSAI1_IsReady() != 0U)
{
adc_frequency = RCC_PLLSAI1_GetFreqDomain_ADC();
}
break;
#endif /* RCC_PLLSAI1_SUPPORT */
#if defined(RCC_PLLSAI2_SUPPORT) && defined(LL_RCC_ADC_CLKSOURCE_PLLSAI2)
case LL_RCC_ADC_CLKSOURCE_PLLSAI2: /* PLLSAI2 clock used as ADC clock source */
if (LL_RCC_PLLSAI2_IsReady() != 0U)
{
adc_frequency = RCC_PLLSAI2_GetFreqDomain_ADC();
}
break;
#endif /* RCC_PLLSAI2_SUPPORT && LL_RCC_ADC_CLKSOURCE_PLLSAI2 */
case LL_RCC_ADC_CLKSOURCE_SYSCLK: /* SYSCLK clock used as ADC clock source */
adc_frequency = RCC_GetSystemClockFreq();
break;
case LL_RCC_ADC_CLKSOURCE_NONE: /* No clock used as ADC clock source */
default:
adc_frequency = LL_RCC_PERIPH_FREQUENCY_NA;
break;
}
return adc_frequency;
}
#if defined(SWPMI1)
/**
* @brief Return SWPMIx clock frequency
* @param SWPMIxSource This parameter can be one of the following values:
* @arg @ref LL_RCC_SWPMI1_CLKSOURCE
* @retval SWPMI clock frequency (in Hz)
* - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator (HSI) is not ready
*/
uint32_t LL_RCC_GetSWPMIClockFreq(uint32_t SWPMIxSource)
{
uint32_t swpmi_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
/* Check parameter */
assert_param(IS_LL_RCC_SWPMI_CLKSOURCE(SWPMIxSource));
/* SWPMI1CLK clock frequency */
switch (LL_RCC_GetSWPMIClockSource(SWPMIxSource))
{
case LL_RCC_SWPMI1_CLKSOURCE_HSI: /* SWPMI1 Clock is HSI Osc. */
if (LL_RCC_HSI_IsReady())
{
swpmi_frequency = HSI_VALUE;
}
break;
case LL_RCC_SWPMI1_CLKSOURCE_PCLK1: /* SWPMI1 Clock is PCLK1 */
swpmi_frequency = RCC_GetPCLK1ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
break;
default:
break;
}
return swpmi_frequency;
}
#endif /* SWPMI1 */
#if defined(DFSDM1_Channel0)
/**
* @brief Return DFSDMx clock frequency
* @param DFSDMxSource This parameter can be one of the following values:
* @arg @ref LL_RCC_DFSDM1_CLKSOURCE
* @retval DFSDM clock frequency (in Hz)
*/
uint32_t LL_RCC_GetDFSDMClockFreq(uint32_t DFSDMxSource)
{
uint32_t dfsdm_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
/* Check parameter */
assert_param(IS_LL_RCC_DFSDM_CLKSOURCE(DFSDMxSource));
/* DFSDM1CLK clock frequency */
switch (LL_RCC_GetDFSDMClockSource(DFSDMxSource))
{
case LL_RCC_DFSDM1_CLKSOURCE_SYSCLK: /* DFSDM1 Clock is SYSCLK */
dfsdm_frequency = RCC_GetSystemClockFreq();
break;
case LL_RCC_DFSDM1_CLKSOURCE_PCLK2: /* DFSDM1 Clock is PCLK2 */
dfsdm_frequency = RCC_GetPCLK2ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
break;
default:
break;
}
return dfsdm_frequency;
}
#if defined(RCC_CCIPR2_DFSDM1SEL)
/**
* @brief Return DFSDMx Audio clock frequency
* @param DFSDMxSource This parameter can be one of the following values:
* @arg @ref LL_RCC_DFSDM1_AUDIO_CLKSOURCE
* @retval DFSDM clock frequency (in Hz)
* - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator is not ready
*/
uint32_t LL_RCC_GetDFSDMAudioClockFreq(uint32_t DFSDMxSource)
{
uint32_t dfsdm_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
/* Check parameter */
assert_param(IS_LL_RCC_DFSDM_AUDIO_CLKSOURCE(DFSDMxSource));
/* DFSDM1CLK clock frequency */
switch (LL_RCC_GetDFSDMAudioClockSource(DFSDMxSource))
{
case LL_RCC_DFSDM1_AUDIO_CLKSOURCE_SAI1: /* SAI1 clock used as DFSDM1 audio clock */
dfsdm_frequency = LL_RCC_GetSAIClockFreq(LL_RCC_SAI1_CLKSOURCE);
break;
case LL_RCC_DFSDM1_AUDIO_CLKSOURCE_MSI: /* MSI clock used as DFSDM1 audio clock */
if (LL_RCC_MSI_IsReady() != 0U)
{
dfsdm_frequency = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(),
((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ?
LL_RCC_MSI_GetRange() :
LL_RCC_MSI_GetRangeAfterStandby()));
}
break;
case LL_RCC_DFSDM1_AUDIO_CLKSOURCE_HSI: /* HSI clock used as DFSDM1 audio clock */
default:
if (LL_RCC_HSI_IsReady() != 0U)
{
dfsdm_frequency = HSI_VALUE;
}
break;
}
return dfsdm_frequency;
}
#endif /* RCC_CCIPR2_DFSDM1SEL */
#endif /* DFSDM1_Channel0 */
#if defined(DSI)
/**
* @brief Return DSI clock frequency
* @param DSIxSource This parameter can be one of the following values:
* @arg @ref LL_RCC_DSI_CLKSOURCE
* @retval DSI clock frequency (in Hz)
* - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator is not ready
* - @ref LL_RCC_PERIPH_FREQUENCY_NA indicates that external clock is used
*/
uint32_t LL_RCC_GetDSIClockFreq(uint32_t DSIxSource)
{
uint32_t dsi_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
/* Check parameter */
assert_param(IS_LL_RCC_DSI_CLKSOURCE(DSIxSource));
/* DSICLK clock frequency */
switch (LL_RCC_GetDSIClockSource(DSIxSource))
{
case LL_RCC_DSI_CLKSOURCE_PLL: /* DSI Clock is PLLSAI2 Osc. */
if (LL_RCC_PLLSAI2_IsReady() != 0U)
{
dsi_frequency = RCC_PLLSAI2_GetFreqDomain_DSI();
}
break;
case LL_RCC_DSI_CLKSOURCE_PHY: /* DSI Clock is DSI physical clock. */
default:
dsi_frequency = LL_RCC_PERIPH_FREQUENCY_NA;
break;
}
return dsi_frequency;
}
#endif /* DSI */
#if defined(LTDC)
/**
* @brief Return LTDC clock frequency
* @param LTDCxSource This parameter can be one of the following values:
* @arg @ref LL_RCC_LTDC_CLKSOURCE
* @retval LTDC clock frequency (in Hz)
* - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator PLLSAI is not ready
*/
uint32_t LL_RCC_GetLTDCClockFreq(uint32_t LTDCxSource)
{
uint32_t ltdc_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
/* Check parameter */
assert_param(IS_LL_RCC_LTDC_CLKSOURCE(LTDCxSource));
if (LL_RCC_PLLSAI2_IsReady() != 0U)
{
ltdc_frequency = RCC_PLLSAI2_GetFreqDomain_LTDC();
}
return ltdc_frequency;
}
#endif /* LTDC */
#if defined(OCTOSPI1)
/**
* @brief Return OCTOSPI clock frequency
* @param OCTOSPIxSource This parameter can be one of the following values:
* @arg @ref LL_RCC_OCTOSPI_CLKSOURCE
* @retval OCTOSPI clock frequency (in Hz)
* - @ref LL_RCC_PERIPH_FREQUENCY_NO indicates that oscillator PLLSAI is not ready
*/
uint32_t LL_RCC_GetOCTOSPIClockFreq(uint32_t OCTOSPIxSource)
{
uint32_t octospi_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
/* Check parameter */
assert_param(IS_LL_RCC_OCTOSPI_CLKSOURCE(OCTOSPIxSource));
/* OCTOSPI clock frequency */
switch (LL_RCC_GetOCTOSPIClockSource(OCTOSPIxSource))
{
case LL_RCC_OCTOSPI_CLKSOURCE_SYSCLK: /* OCTOSPI clock is SYSCLK */
octospi_frequency = RCC_GetSystemClockFreq();
break;
case LL_RCC_OCTOSPI_CLKSOURCE_MSI: /* MSI clock used as OCTOSPI clock */
if (LL_RCC_MSI_IsReady() != 0U)
{
octospi_frequency = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(),
((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ?
LL_RCC_MSI_GetRange() :
LL_RCC_MSI_GetRangeAfterStandby()));
}
break;
case LL_RCC_OCTOSPI_CLKSOURCE_PLL: /* PLL clock used as OCTOSPI source */
if (LL_RCC_PLL_IsReady() != 0U)
{
octospi_frequency = RCC_PLL_GetFreqDomain_48M();
}
break;
default:
octospi_frequency = LL_RCC_PERIPH_FREQUENCY_NO;
break;
}
return octospi_frequency;
}
#endif /* OCTOSPI1 */
/**
* @}
*/
/**
* @}
*/
/** @addtogroup RCC_LL_Private_Functions
* @{
*/
/**
* @brief Return SYSTEM clock frequency
* @retval SYSTEM clock frequency (in Hz)
*/
uint32_t RCC_GetSystemClockFreq(void)
{
uint32_t frequency;
/* 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_IsEnabledRangeSelect(),
((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ?
LL_RCC_MSI_GetRange() :
LL_RCC_MSI_GetRangeAfterStandby()));
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_IsEnabledRangeSelect(),
((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ?
LL_RCC_MSI_GetRange() :
LL_RCC_MSI_GetRangeAfterStandby()));
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, pllsource;
/* PLL_VCO = (HSE_VALUE or HSI_VALUE or MSI_VALUE/ PLLM) * PLLN
SYSCLK = PLL_VCO / PLLR
*/
pllsource = LL_RCC_PLL_GetMainSource();
switch (pllsource)
{
case LL_RCC_PLLSOURCE_MSI: /* MSI used as PLL clock source */
pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(),
((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ?
LL_RCC_MSI_GetRange() :
LL_RCC_MSI_GetRangeAfterStandby()));
break;
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 = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(),
((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ?
LL_RCC_MSI_GetRange() :
LL_RCC_MSI_GetRangeAfterStandby()));
break;
}
return __LL_RCC_CALC_PLLCLK_FREQ(pllinputfreq, LL_RCC_PLL_GetDivider(),
LL_RCC_PLL_GetN(), LL_RCC_PLL_GetR());
}
#if defined(SAI1)
/**
* @brief Return PLL clock frequency used for SAI domain
* @retval PLL clock frequency (in Hz)
*/
uint32_t RCC_PLL_GetFreqDomain_SAI(void)
{
uint32_t pllinputfreq, pllsource;
/* PLL_VCO = (HSE_VALUE or HSI_VALUE or MSI_VALUE / PLLM) * PLLN
SAI Domain clock = PLL_VCO / PLLP
*/
pllsource = LL_RCC_PLL_GetMainSource();
switch (pllsource)
{
case LL_RCC_PLLSOURCE_MSI: /* MSI used as PLL clock source */
pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(),
((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ?
LL_RCC_MSI_GetRange() :
LL_RCC_MSI_GetRangeAfterStandby()));
break;
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 = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(),
((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ?
LL_RCC_MSI_GetRange() :
LL_RCC_MSI_GetRangeAfterStandby()));
break;
}
return __LL_RCC_CALC_PLLCLK_SAI_FREQ(pllinputfreq, LL_RCC_PLL_GetDivider(),
LL_RCC_PLL_GetN(), LL_RCC_PLL_GetP());
}
#endif /* SAI1 */
/**
* @brief Return PLL clock frequency used for 48 MHz domain
* @retval PLL clock frequency (in Hz)
*/
uint32_t RCC_PLL_GetFreqDomain_48M(void)
{
uint32_t pllinputfreq, pllsource;
/* PLL_VCO = (HSE_VALUE or HSI_VALUE or MSI_VALUE/ PLLM) * PLLN
48M Domain clock = PLL_VCO / PLLQ
*/
pllsource = LL_RCC_PLL_GetMainSource();
switch (pllsource)
{
case LL_RCC_PLLSOURCE_MSI: /* MSI used as PLL clock source */
pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(),
((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ?
LL_RCC_MSI_GetRange() :
LL_RCC_MSI_GetRangeAfterStandby()));
break;
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 = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(),
((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ?
LL_RCC_MSI_GetRange() :
LL_RCC_MSI_GetRangeAfterStandby()));
break;
}
return __LL_RCC_CALC_PLLCLK_48M_FREQ(pllinputfreq, LL_RCC_PLL_GetDivider(),
LL_RCC_PLL_GetN(), LL_RCC_PLL_GetQ());
}
#if defined(DSI)
/**
* @brief Return PLL clock frequency used for DSI clock
* @retval PLL clock frequency (in Hz)
*/
uint32_t RCC_PLLSAI2_GetFreqDomain_DSI(void)
{
uint32_t pllinputfreq, pllsource;
/* PLLSAI2_VCO = (HSE_VALUE or HSI_VALUE or MSI_VALUE/ PLLSAI2M) * PLLSAI2N */
/* DSICLK = PLLSAI2_VCO / PLLSAI2R */
pllsource = LL_RCC_PLL_GetMainSource();
switch (pllsource)
{
case LL_RCC_PLLSOURCE_MSI: /* MSI used as PLLSAI2 clock source */
pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(),
((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ?
LL_RCC_MSI_GetRange() :
LL_RCC_MSI_GetRangeAfterStandby()));
break;
case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLLSAI2 clock source */
pllinputfreq = HSI_VALUE;
break;
case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLLSAI2 clock source */
pllinputfreq = HSE_VALUE;
break;
default:
pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(),
((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ?
LL_RCC_MSI_GetRange() :
LL_RCC_MSI_GetRangeAfterStandby()));
break;
}
return __LL_RCC_CALC_PLLSAI2_DSI_FREQ(pllinputfreq, LL_RCC_PLLSAI2_GetDivider(),
LL_RCC_PLLSAI2_GetN(), LL_RCC_PLLSAI2_GetR());
}
#endif /* DSI */
#if defined(RCC_PLLSAI1_SUPPORT)
/**
* @brief Return PLLSAI1 clock frequency used for SAI domain
* @retval PLLSAI1 clock frequency (in Hz)
*/
uint32_t RCC_PLLSAI1_GetFreqDomain_SAI(void)
{
uint32_t pllinputfreq, pllsource;
#if defined(RCC_PLLSAI2M_DIV_1_16_SUPPORT)
/* PLLSAI1_VCO = (HSE_VALUE or HSI_VALUE or MSI_VALUE/ PLLSAI1M) * PLLSAI1N */
#else
/* PLLSAI1_VCO = (HSE_VALUE or HSI_VALUE or MSI_VALUE/ PLLM) * PLLSAI1N */
#endif
/* SAI Domain clock = PLLSAI1_VCO / PLLSAI1P */
pllsource = LL_RCC_PLL_GetMainSource();
switch (pllsource)
{
case LL_RCC_PLLSOURCE_MSI: /* MSI used as PLLSAI1 clock source */
pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(),
((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ?
LL_RCC_MSI_GetRange() :
LL_RCC_MSI_GetRangeAfterStandby()));
break;
case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLLSAI1 clock source */
pllinputfreq = HSI_VALUE;
break;
case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLLSAI1 clock source */
pllinputfreq = HSE_VALUE;
break;
default:
pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(),
((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ?
LL_RCC_MSI_GetRange() :
LL_RCC_MSI_GetRangeAfterStandby()));
break;
}
return __LL_RCC_CALC_PLLSAI1_SAI_FREQ(pllinputfreq, LL_RCC_PLL_GetDivider(),
LL_RCC_PLLSAI1_GetN(), LL_RCC_PLLSAI1_GetP());
}
/**
* @brief Return PLLSAI1 clock frequency used for 48Mhz domain
* @retval PLLSAI1 clock frequency (in Hz)
*/
uint32_t RCC_PLLSAI1_GetFreqDomain_48M(void)
{
uint32_t pllinputfreq, pllsource;
#if defined(RCC_PLLSAI2M_DIV_1_16_SUPPORT)
/* PLLSAI1_VCO = (HSE_VALUE or HSI_VALUE or MSI_VALUE/ PLLSAI1M) * PLLSAI1N */
#else
/* PLLSAI1_VCO = (HSE_VALUE or HSI_VALUE or MSI_VALUE/ PLLM) * PLLSAI1N */
#endif
/* 48M Domain clock = PLLSAI1_VCO / PLLSAI1Q */
pllsource = LL_RCC_PLL_GetMainSource();
switch (pllsource)
{
case LL_RCC_PLLSOURCE_MSI: /* MSI used as PLLSAI1 clock source */
pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(),
((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ?
LL_RCC_MSI_GetRange() :
LL_RCC_MSI_GetRangeAfterStandby()));
break;
case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLLSAI1 clock source */
pllinputfreq = HSI_VALUE;
break;
case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLLSAI1 clock source */
pllinputfreq = HSE_VALUE;
break;
default:
pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(),
((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ?
LL_RCC_MSI_GetRange() :
LL_RCC_MSI_GetRangeAfterStandby()));
break;
}
return __LL_RCC_CALC_PLLSAI1_48M_FREQ(pllinputfreq, LL_RCC_PLL_GetDivider(),
LL_RCC_PLLSAI1_GetN(), LL_RCC_PLLSAI1_GetQ());
}
/**
* @brief Return PLLSAI1 clock frequency used for ADC domain
* @retval PLLSAI1 clock frequency (in Hz)
*/
uint32_t RCC_PLLSAI1_GetFreqDomain_ADC(void)
{
uint32_t pllinputfreq, pllsource;
#if defined(RCC_PLLSAI2M_DIV_1_16_SUPPORT)
/* PLLSAI1_VCO = (HSE_VALUE or HSI_VALUE or MSI_VALUE/ PLLSAI1M) * PLLSAI1N */
#else
/* PLLSAI1_VCO = (HSE_VALUE or HSI_VALUE or MSI_VALUE/ PLLM) * PLLSAI1N */
#endif
/* 48M Domain clock = PLLSAI1_VCO / PLLSAI1R */
pllsource = LL_RCC_PLL_GetMainSource();
switch (pllsource)
{
case LL_RCC_PLLSOURCE_MSI: /* MSI used as PLLSAI1 clock source */
pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(),
((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ?
LL_RCC_MSI_GetRange() :
LL_RCC_MSI_GetRangeAfterStandby()));
break;
case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLLSAI1 clock source */
pllinputfreq = HSI_VALUE;
break;
case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLLSAI1 clock source */
pllinputfreq = HSE_VALUE;
break;
default:
pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(),
((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ?
LL_RCC_MSI_GetRange() :
LL_RCC_MSI_GetRangeAfterStandby()));
break;
}
return __LL_RCC_CALC_PLLSAI1_ADC_FREQ(pllinputfreq, LL_RCC_PLL_GetDivider(),
LL_RCC_PLLSAI1_GetN(), LL_RCC_PLLSAI1_GetR());
}
#endif /* RCC_PLLSAI1_SUPPORT */
#if defined(RCC_PLLSAI2_SUPPORT)
/**
* @brief Return PLLSAI2 clock frequency used for SAI domain
* @retval PLLSAI2 clock frequency (in Hz)
*/
uint32_t RCC_PLLSAI2_GetFreqDomain_SAI(void)
{
uint32_t pllinputfreq, pllsource;
#if defined(RCC_PLLSAI2M_DIV_1_16_SUPPORT)
/* PLLSAI2_VCO = (HSE_VALUE or HSI_VALUE or MSI_VALUE/ PLLSAI2M) * PLLSAI2N */
#else
/* PLLSAI2_VCO = (HSE_VALUE or HSI_VALUE or MSI_VALUE/ PLLM) * PLLSAI2N */
#endif
/* SAI Domain clock = PLLSAI2_VCO / PLLSAI2P */
pllsource = LL_RCC_PLL_GetMainSource();
switch (pllsource)
{
case LL_RCC_PLLSOURCE_MSI: /* MSI used as PLLSAI2 clock source */
pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(),
((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ?
LL_RCC_MSI_GetRange() :
LL_RCC_MSI_GetRangeAfterStandby()));
break;
case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLLSAI2 clock source */
pllinputfreq = HSI_VALUE;
break;
case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLLSAI2 clock source */
pllinputfreq = HSE_VALUE;
break;
default:
pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(),
((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ?
LL_RCC_MSI_GetRange() :
LL_RCC_MSI_GetRangeAfterStandby()));
break;
}
#if defined(RCC_PLLSAI2M_DIV_1_16_SUPPORT)
return __LL_RCC_CALC_PLLSAI2_SAI_FREQ(pllinputfreq, LL_RCC_PLLSAI2_GetDivider(),
LL_RCC_PLLSAI2_GetN(), LL_RCC_PLLSAI2_GetP());
#else
return __LL_RCC_CALC_PLLSAI2_SAI_FREQ(pllinputfreq, LL_RCC_PLL_GetDivider(),
LL_RCC_PLLSAI2_GetN(), LL_RCC_PLLSAI2_GetP());
#endif
}
#if defined(LTDC)
/**
* @brief Return PLLSAI2 clock frequency used for LTDC domain
* @retval PLLSAI2 clock frequency (in Hz)
*/
uint32_t RCC_PLLSAI2_GetFreqDomain_LTDC(void)
{
uint32_t pllinputfreq, pllsource;
/* PLLSAI2_VCO = (HSE_VALUE or HSI_VALUE or MSI_VALUE/ PLLSAI2M) * PLLSAI2N */
/* LTDC Domain clock = (PLLSAI2_VCO / PLLSAI2R) / PLLSAI2DIVR */
pllsource = LL_RCC_PLL_GetMainSource();
switch (pllsource)
{
case LL_RCC_PLLSOURCE_MSI: /* MSI used as PLLSAI2 clock source */
pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(),
((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ?
LL_RCC_MSI_GetRange() :
LL_RCC_MSI_GetRangeAfterStandby()));
break;
case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLLSAI2 clock source */
pllinputfreq = HSI_VALUE;
break;
case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLLSAI2 clock source */
pllinputfreq = HSE_VALUE;
break;
default:
pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(),
((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ?
LL_RCC_MSI_GetRange() :
LL_RCC_MSI_GetRangeAfterStandby()));
break;
}
return __LL_RCC_CALC_PLLSAI2_LTDC_FREQ(pllinputfreq, LL_RCC_PLLSAI2_GetDivider(),
LL_RCC_PLLSAI2_GetN(), LL_RCC_PLLSAI2_GetR(), LL_RCC_PLLSAI2_GetDIVR());
}
#else
/**
* @brief Return PLLSAI2 clock frequency used for ADC domain
* @retval PLLSAI2 clock frequency (in Hz)
*/
uint32_t RCC_PLLSAI2_GetFreqDomain_ADC(void)
{
uint32_t pllinputfreq = 0U, pllsource = 0U;
/* PLLSAI2_VCO = (HSE_VALUE or HSI_VALUE or MSI_VALUE/ PLLM) * PLLSAI2N */
/* 48M Domain clock = PLLSAI2_VCO / PLLSAI2R */
pllsource = LL_RCC_PLL_GetMainSource();
switch (pllsource)
{
case LL_RCC_PLLSOURCE_MSI: /* MSI used as PLLSAI2 clock source */
pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(),
((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ?
LL_RCC_MSI_GetRange() :
LL_RCC_MSI_GetRangeAfterStandby()));
break;
case LL_RCC_PLLSOURCE_HSI: /* HSI used as PLLSAI2 clock source */
pllinputfreq = HSI_VALUE;
break;
case LL_RCC_PLLSOURCE_HSE: /* HSE used as PLLSAI2 clock source */
pllinputfreq = HSE_VALUE;
break;
default:
pllinputfreq = __LL_RCC_CALC_MSI_FREQ(LL_RCC_MSI_IsEnabledRangeSelect(),
((LL_RCC_MSI_IsEnabledRangeSelect() != 0U) ?
LL_RCC_MSI_GetRange() :
LL_RCC_MSI_GetRangeAfterStandby()));
break;
}
return __LL_RCC_CALC_PLLSAI2_ADC_FREQ(pllinputfreq, LL_RCC_PLL_GetDivider(),
LL_RCC_PLLSAI2_GetN(), LL_RCC_PLLSAI2_GetR());
}
#endif /* LTDC */
#endif /*RCC_PLLSAI2_SUPPORT*/
/**
* @}
*/
/**
* @}
*/
#endif /* defined(RCC) */
/**
* @}
*/
#endif /* USE_FULL_LL_DRIVER */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
the_stack_data/136193.c | /*-------------------------------------------------------------------------
*
* open.c
* Win32 open() replacement
*
*
* Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
*
* src/port/open.c
*
*-------------------------------------------------------------------------
*/
#ifdef WIN32
#ifndef FRONTEND
#include "postgres.h"
#else
#include "postgres_fe.h"
#endif
#include <fcntl.h>
#include <assert.h>
static int
openFlagsToCreateFileFlags(int openFlags)
{// #lizard forgives
switch (openFlags & (O_CREAT | O_TRUNC | O_EXCL))
{
/* O_EXCL is meaningless without O_CREAT */
case 0:
case O_EXCL:
return OPEN_EXISTING;
case O_CREAT:
return OPEN_ALWAYS;
/* O_EXCL is meaningless without O_CREAT */
case O_TRUNC:
case O_TRUNC | O_EXCL:
return TRUNCATE_EXISTING;
case O_CREAT | O_TRUNC:
return CREATE_ALWAYS;
/* O_TRUNC is meaningless with O_CREAT */
case O_CREAT | O_EXCL:
case O_CREAT | O_TRUNC | O_EXCL:
return CREATE_NEW;
}
/* will never get here */
return 0;
}
/*
* - file attribute setting, based on fileMode?
*/
int
pgwin32_open(const char *fileName, int fileFlags,...)
{// #lizard forgives
int fd;
HANDLE h = INVALID_HANDLE_VALUE;
SECURITY_ATTRIBUTES sa;
int loops = 0;
/* Check that we can handle the request */
assert((fileFlags & ((O_RDONLY | O_WRONLY | O_RDWR) | O_APPEND |
(O_RANDOM | O_SEQUENTIAL | O_TEMPORARY) |
_O_SHORT_LIVED | O_DSYNC | O_DIRECT |
(O_CREAT | O_TRUNC | O_EXCL) | (O_TEXT | O_BINARY))) == fileFlags);
sa.nLength = sizeof(sa);
sa.bInheritHandle = TRUE;
sa.lpSecurityDescriptor = NULL;
while ((h = CreateFile(fileName,
/* cannot use O_RDONLY, as it == 0 */
(fileFlags & O_RDWR) ? (GENERIC_WRITE | GENERIC_READ) :
((fileFlags & O_WRONLY) ? GENERIC_WRITE : GENERIC_READ),
/* These flags allow concurrent rename/unlink */
(FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE),
&sa,
openFlagsToCreateFileFlags(fileFlags),
FILE_ATTRIBUTE_NORMAL |
((fileFlags & O_RANDOM) ? FILE_FLAG_RANDOM_ACCESS : 0) |
((fileFlags & O_SEQUENTIAL) ? FILE_FLAG_SEQUENTIAL_SCAN : 0) |
((fileFlags & _O_SHORT_LIVED) ? FILE_ATTRIBUTE_TEMPORARY : 0) |
((fileFlags & O_TEMPORARY) ? FILE_FLAG_DELETE_ON_CLOSE : 0) |
((fileFlags & O_DIRECT) ? FILE_FLAG_NO_BUFFERING : 0) |
((fileFlags & O_DSYNC) ? FILE_FLAG_WRITE_THROUGH : 0),
NULL)) == INVALID_HANDLE_VALUE)
{
/*
* Sharing violation or locking error can indicate antivirus, backup
* or similar software that's locking the file. Try again for 30
* seconds before giving up.
*/
DWORD err = GetLastError();
if (err == ERROR_SHARING_VIOLATION ||
err == ERROR_LOCK_VIOLATION)
{
pg_usleep(100000);
loops++;
#ifndef FRONTEND
if (loops == 50)
ereport(LOG,
(errmsg("could not open file \"%s\": %s", fileName,
(err == ERROR_SHARING_VIOLATION) ? _("sharing violation") : _("lock violation")),
errdetail("Continuing to retry for 30 seconds."),
errhint("You might have antivirus, backup, or similar software interfering with the database system.")));
#endif
if (loops < 300)
continue;
}
_dosmaperr(err);
return -1;
}
/* _open_osfhandle will, on error, set errno accordingly */
if ((fd = _open_osfhandle((intptr_t) h, fileFlags & O_APPEND)) < 0)
CloseHandle(h); /* will not affect errno */
else if (fileFlags & (O_TEXT | O_BINARY) &&
_setmode(fd, fileFlags & (O_TEXT | O_BINARY)) < 0)
{
_close(fd);
return -1;
}
return fd;
}
FILE *
pgwin32_fopen(const char *fileName, const char *mode)
{// #lizard forgives
int openmode = 0;
int fd;
if (strstr(mode, "r+"))
openmode |= O_RDWR;
else if (strchr(mode, 'r'))
openmode |= O_RDONLY;
if (strstr(mode, "w+"))
openmode |= O_RDWR | O_CREAT | O_TRUNC;
else if (strchr(mode, 'w'))
openmode |= O_WRONLY | O_CREAT | O_TRUNC;
if (strchr(mode, 'a'))
openmode |= O_WRONLY | O_CREAT | O_APPEND;
if (strchr(mode, 'b'))
openmode |= O_BINARY;
if (strchr(mode, 't'))
openmode |= O_TEXT;
fd = pgwin32_open(fileName, openmode);
if (fd == -1)
return NULL;
return _fdopen(fd, mode);
}
#endif
|
the_stack_data/19364.c | /*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#ifdef _WIN64
#define EXPORT __declspec(dllexport)
#else
#define EXPORT
#endif
EXPORT void foo(void (*cb)(void)) {
cb();
}
|
the_stack_data/215766897.c | char c_null = '\0';
char c_zero = '0';
int main () { return 0; }
|
the_stack_data/985978.c | #include <time.h>
#include <stdio.h>
int main(void)
{
time_t t;
t = time(0);
printf("%s", ctime(&t));
return 0;
}
|
the_stack_data/150144280.c | /*
报纸页数
X星球日报和我们地球的城市早报是一样的,
都是一些单独的纸张叠在一起而已。每张纸印有4版。
比如,某张报纸包含的4页是:5,6,11,12,
可以确定它应该是最上边的第2张报纸。
我们在太空中捡到了一张X星球的报纸,4个页码分别是:
1125,1126,1727,1728
请你计算这份报纸一共多少页(也就是最大页码,并不是用了几张纸哦)?
请填写表示总页数的数字。
注意:你提交的应该是一个整数,不要填写任何多余的内容或说明性文字。
2852
*/
#include <stdio.h>
int main() {
int left = 1126, right = 1727;
while (left < right) {
left += 2;
right -= 2;
}
left -= 2; //////////////////////////////////
right += 2; //////////////////////////////////
printf("%d %d %d\n", left, right, left * 2);
return 0;
} |
the_stack_data/212644287.c | /*
* Copyright 2004-2016 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <openssl/sha.h>
#include <openssl/evp.h>
#include <openssl/crypto.h>
static const unsigned char app_c1[SHA512_DIGEST_LENGTH] = {
0xdd, 0xaf, 0x35, 0xa1, 0x93, 0x61, 0x7a, 0xba,
0xcc, 0x41, 0x73, 0x49, 0xae, 0x20, 0x41, 0x31,
0x12, 0xe6, 0xfa, 0x4e, 0x89, 0xa9, 0x7e, 0xa2,
0x0a, 0x9e, 0xee, 0xe6, 0x4b, 0x55, 0xd3, 0x9a,
0x21, 0x92, 0x99, 0x2a, 0x27, 0x4f, 0xc1, 0xa8,
0x36, 0xba, 0x3c, 0x23, 0xa3, 0xfe, 0xeb, 0xbd,
0x45, 0x4d, 0x44, 0x23, 0x64, 0x3c, 0xe8, 0x0e,
0x2a, 0x9a, 0xc9, 0x4f, 0xa5, 0x4c, 0xa4, 0x9f
};
static const unsigned char app_c2[SHA512_DIGEST_LENGTH] = {
0x8e, 0x95, 0x9b, 0x75, 0xda, 0xe3, 0x13, 0xda,
0x8c, 0xf4, 0xf7, 0x28, 0x14, 0xfc, 0x14, 0x3f,
0x8f, 0x77, 0x79, 0xc6, 0xeb, 0x9f, 0x7f, 0xa1,
0x72, 0x99, 0xae, 0xad, 0xb6, 0x88, 0x90, 0x18,
0x50, 0x1d, 0x28, 0x9e, 0x49, 0x00, 0xf7, 0xe4,
0x33, 0x1b, 0x99, 0xde, 0xc4, 0xb5, 0x43, 0x3a,
0xc7, 0xd3, 0x29, 0xee, 0xb6, 0xdd, 0x26, 0x54,
0x5e, 0x96, 0xe5, 0x5b, 0x87, 0x4b, 0xe9, 0x09
};
static const unsigned char app_c3[SHA512_DIGEST_LENGTH] = {
0xe7, 0x18, 0x48, 0x3d, 0x0c, 0xe7, 0x69, 0x64,
0x4e, 0x2e, 0x42, 0xc7, 0xbc, 0x15, 0xb4, 0x63,
0x8e, 0x1f, 0x98, 0xb1, 0x3b, 0x20, 0x44, 0x28,
0x56, 0x32, 0xa8, 0x03, 0xaf, 0xa9, 0x73, 0xeb,
0xde, 0x0f, 0xf2, 0x44, 0x87, 0x7e, 0xa6, 0x0a,
0x4c, 0xb0, 0x43, 0x2c, 0xe5, 0x77, 0xc3, 0x1b,
0xeb, 0x00, 0x9c, 0x5c, 0x2c, 0x49, 0xaa, 0x2e,
0x4e, 0xad, 0xb2, 0x17, 0xad, 0x8c, 0xc0, 0x9b
};
static const unsigned char app_d1[SHA384_DIGEST_LENGTH] = {
0xcb, 0x00, 0x75, 0x3f, 0x45, 0xa3, 0x5e, 0x8b,
0xb5, 0xa0, 0x3d, 0x69, 0x9a, 0xc6, 0x50, 0x07,
0x27, 0x2c, 0x32, 0xab, 0x0e, 0xde, 0xd1, 0x63,
0x1a, 0x8b, 0x60, 0x5a, 0x43, 0xff, 0x5b, 0xed,
0x80, 0x86, 0x07, 0x2b, 0xa1, 0xe7, 0xcc, 0x23,
0x58, 0xba, 0xec, 0xa1, 0x34, 0xc8, 0x25, 0xa7
};
static const unsigned char app_d2[SHA384_DIGEST_LENGTH] = {
0x09, 0x33, 0x0c, 0x33, 0xf7, 0x11, 0x47, 0xe8,
0x3d, 0x19, 0x2f, 0xc7, 0x82, 0xcd, 0x1b, 0x47,
0x53, 0x11, 0x1b, 0x17, 0x3b, 0x3b, 0x05, 0xd2,
0x2f, 0xa0, 0x80, 0x86, 0xe3, 0xb0, 0xf7, 0x12,
0xfc, 0xc7, 0xc7, 0x1a, 0x55, 0x7e, 0x2d, 0xb9,
0x66, 0xc3, 0xe9, 0xfa, 0x91, 0x74, 0x60, 0x39
};
static const unsigned char app_d3[SHA384_DIGEST_LENGTH] = {
0x9d, 0x0e, 0x18, 0x09, 0x71, 0x64, 0x74, 0xcb,
0x08, 0x6e, 0x83, 0x4e, 0x31, 0x0a, 0x4a, 0x1c,
0xed, 0x14, 0x9e, 0x9c, 0x00, 0xf2, 0x48, 0x52,
0x79, 0x72, 0xce, 0xc5, 0x70, 0x4c, 0x2a, 0x5b,
0x07, 0xb8, 0xb3, 0xdc, 0x38, 0xec, 0xc4, 0xeb,
0xae, 0x97, 0xdd, 0xd8, 0x7f, 0x3d, 0x89, 0x85
};
int main(int argc, char **argv)
{
unsigned char md[SHA512_DIGEST_LENGTH];
int i;
EVP_MD_CTX *evp;
fprintf(stdout, "Testing SHA-512 ");
if (!EVP_Digest("abc", 3, md, NULL, EVP_sha512(), NULL))
goto err;
if (memcmp(md, app_c1, sizeof(app_c1))) {
fflush(stdout);
fprintf(stderr, "\nTEST 1 of 3 failed.\n");
return 1;
} else
fprintf(stdout, ".");
fflush(stdout);
if (!EVP_Digest("abcdefgh" "bcdefghi" "cdefghij" "defghijk"
"efghijkl" "fghijklm" "ghijklmn" "hijklmno"
"ijklmnop" "jklmnopq" "klmnopqr" "lmnopqrs"
"mnopqrst" "nopqrstu", 112, md, NULL, EVP_sha512(), NULL))
goto err;
if (memcmp(md, app_c2, sizeof(app_c2))) {
fflush(stdout);
fprintf(stderr, "\nTEST 2 of 3 failed.\n");
return 1;
} else
fprintf(stdout, ".");
fflush(stdout);
evp = EVP_MD_CTX_new();
if (evp == NULL) {
fflush(stdout);
fprintf(stderr, "\nTEST 3 of 3 failed. (malloc failure)\n");
return 1;
}
if (!EVP_DigestInit_ex(evp, EVP_sha512(), NULL))
goto err;
for (i = 0; i < 1000000; i += 288) {
if (!EVP_DigestUpdate(evp, "aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa",
(1000000 - i) < 288 ? 1000000 - i : 288))
goto err;
}
if (!EVP_DigestFinal_ex(evp, md, NULL))
goto err;
EVP_MD_CTX_reset(evp);
if (memcmp(md, app_c3, sizeof(app_c3))) {
fflush(stdout);
fprintf(stderr, "\nTEST 3 of 3 failed.\n");
return 1;
} else
fprintf(stdout, ".");
fflush(stdout);
fprintf(stdout, " passed.\n");
fflush(stdout);
fprintf(stdout, "Testing SHA-384 ");
if (!EVP_Digest("abc", 3, md, NULL, EVP_sha384(), NULL))
goto err;
if (memcmp(md, app_d1, sizeof(app_d1))) {
fflush(stdout);
fprintf(stderr, "\nTEST 1 of 3 failed.\n");
return 1;
} else
fprintf(stdout, ".");
fflush(stdout);
if (!EVP_Digest("abcdefgh" "bcdefghi" "cdefghij" "defghijk"
"efghijkl" "fghijklm" "ghijklmn" "hijklmno"
"ijklmnop" "jklmnopq" "klmnopqr" "lmnopqrs"
"mnopqrst" "nopqrstu", 112, md, NULL, EVP_sha384(), NULL))
goto err;
if (memcmp(md, app_d2, sizeof(app_d2))) {
fflush(stdout);
fprintf(stderr, "\nTEST 2 of 3 failed.\n");
return 1;
} else
fprintf(stdout, ".");
fflush(stdout);
if (!EVP_DigestInit_ex(evp, EVP_sha384(), NULL))
goto err;
for (i = 0; i < 1000000; i += 64) {
if (!EVP_DigestUpdate(evp, "aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa",
(1000000 - i) < 64 ? 1000000 - i : 64))
goto err;
}
if (!EVP_DigestFinal_ex(evp, md, NULL))
goto err;
EVP_MD_CTX_free(evp);
if (memcmp(md, app_d3, sizeof(app_d3))) {
fflush(stdout);
fprintf(stderr, "\nTEST 3 of 3 failed.\n");
return 1;
} else
fprintf(stdout, ".");
fflush(stdout);
fprintf(stdout, " passed.\n");
fflush(stdout);
return 0;
err:
fflush(stdout);
fprintf(stderr, "\nFatal EVP error!\n");
return 1;
}
|
the_stack_data/148576780.c | /* { dg-do compile } */
/* { dg-options -Wtraditional-conversion } */
int
test_s (signed int x)
{
return __builtin_abs (x) /* { dg-bogus "as unsigned due to prototype" } */
+ __builtin_clz (x) /* { dg-warning "as unsigned due to prototype" } */
+ __builtin_ctz (x) /* { dg-warning "as unsigned due to prototype" } */
+ __builtin_clrsb (x) /* { dg-bogus "as unsigned due to prototype" } */
+ __builtin_ffs (x) /* { dg-bogus "as unsigned due to prototype" } */
+ __builtin_parity (x) /* { dg-warning "as unsigned due to prototype" } */
+ __builtin_popcount (x); /* { dg-warning "as unsigned due to prototype" } */
}
int
test_u (unsigned int x)
{
return __builtin_abs (x) /* { dg-warning "as signed due to prototype" } */
+ __builtin_clz (x) /* { dg-bogus "as signed due to prototype" } */
+ __builtin_ctz (x) /* { dg-bogus "as signed due to prototype" } */
+ __builtin_clrsb (x) /* { dg-warning "as signed due to prototype" } */
+ __builtin_ffs (x) /* { dg-warning "as signed due to prototype" } */
+ __builtin_parity (x) /* { dg-bogus "as signed due to prototype" } */
+ __builtin_popcount (x); /* { dg-bogus "as signed due to prototype" } */
}
int
test_sl (signed long x)
{
return __builtin_labs (x) /* { dg-bogus "as unsigned due to prototype" } */
+ __builtin_clzl (x) /* { dg-warning "as unsigned due to prototype" } */
+ __builtin_ctzl (x) /* { dg-warning "as unsigned due to prototype" } */
+ __builtin_clrsbl (x) /* { dg-bogus "as unsigned due to prototype" } */
+ __builtin_ffsl (x) /* { dg-bogus "as unsigned due to prototype" } */
+ __builtin_parityl (x) /* { dg-warning "as unsigned due to prototype" } */
+ __builtin_popcountl (x); /* { dg-warning "as unsigned due to prototype" } */
}
int
test_ul (unsigned long x)
{
return __builtin_labs (x) /* { dg-warning "as signed due to prototype" } */
+ __builtin_clzl (x) /* { dg-bogus "as signed due to prototype" } */
+ __builtin_ctzl (x) /* { dg-bogus "as signed due to prototype" } */
+ __builtin_clrsbl (x) /* { dg-warning "as signed due to prototype" } */
+ __builtin_ffsl (x) /* { dg-warning "as signed due to prototype" } */
+ __builtin_parityl (x) /* { dg-bogus "as signed due to prototype" } */
+ __builtin_popcountl (x); /* { dg-bogus "as signed due to prototype" } */
}
int
test_sll (signed long long x)
{
return __builtin_llabs (x) /* { dg-bogus "as unsigned due to prototype" } */
+ __builtin_clzll (x) /* { dg-warning "as unsigned due to prototype" } */
+ __builtin_ctzll (x) /* { dg-warning "as unsigned due to prototype" } */
+ __builtin_clrsbll (x) /* { dg-bogus "as unsigned due to prototype" } */
+ __builtin_ffsll (x) /* { dg-bogus "as unsigned due to prototype" } */
+ __builtin_parityll (x) /* { dg-warning "as unsigned due to prototype" } */
+ __builtin_popcountll (x); /* { dg-warning "as unsigned due to prototype" } */
}
int
test_ull (unsigned long long x)
{
return __builtin_llabs (x) /* { dg-warning "as signed due to prototype" } */
+ __builtin_clzll (x) /* { dg-bogus "as signed due to prototype" } */
+ __builtin_ctzll (x) /* { dg-bogus "as signed due to prototype" } */
+ __builtin_clrsbll (x) /* { dg-warning "as signed due to prototype" } */
+ __builtin_ffsll (x) /* { dg-warning "as signed due to prototype" } */
+ __builtin_parityll (x) /* { dg-bogus "as signed due to prototype" } */
+ __builtin_popcountll (x); /* { dg-bogus "as signed due to prototype" } */
}
|
the_stack_data/151704529.c | // PARAM: --set solver td3 --enable ana.int.interval --disable ana.int.def_exc --set ana.activated "['base','threadid','threadflag','mallocWrapper']" --set ana.base.privatization none
// This is a pattern we saw in some examples for SVCOMP, where instead of the assert(0) there was a call to verifier error.
// Because of the demand-driven nature of our solvers, we never looked at the code inside fail since there is no edge from the loop to the endpoint of f.
// However, the assert(0) (verifier error) is still reachable from main.
void f(void) {
fail:
assert(0); //FAIL
goto fail;
}
int main(void) {
int top;
if(top) {
f();
}
}
|
the_stack_data/1191286.c | #include <stdio.h>
#include <math.h>
#include <string.h>
int main()
{
int n = 0, i, k=1;
(void)scanf("%d", &n);
int mas[n];
memset(mas, 0, sizeof mas);
for(i =1; i<=n;i++)
{
(void)scanf("%d", &mas[i]);
}
for(i=1; i<=n; i++)
{
k=k*(mas[i]-i);
}
printf("%d", k );
return 0;
}
|
the_stack_data/128357.c | /*
* p521 -- code/ecf/rfork.c
*
* 下面的代码包含了一个暴露竞争的简便技巧
*
* 像 procmask2.c 那样的竞争难以发现,因为它们依赖于内核相关的调度决策。在一次
* fork() 调用之后,有些内核调度子进程先运行,而有些内核调度父进程先运行。如果你
* 要在后一种系统上运行 procmask1.c 的代码,它绝不会失败,无论你测试多少遍。但是
* 一旦在前一种系统上运行这段代码,那么竞争就会暴露出来,代码会失败。
*
* 下面的代码是一个 fork() 的包装函数,它随机地决定父进程和子进程执行的顺序。父进
* 程和子进程扔一枚硬币来决定谁会休眠,因而给另一个进程被调度的机会。
*
* 如果我们运行这个代码多次,那么我们就有极高的概率会测试到父子进程执行的两种顺序,
* 无论这个特定内核的调度策略是什么样子的。
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/types.h>
/* Sleep for a random period between [0, MAX_SLEEP] us. */
#define MAX_SLEEP 100000
/* Macro that maps val into the range [0, RAND_MAX] */
#define CONVERT(val) (((double)val)/(double)RAND_MAX)
pid_t Fork(void) {
static struct timeval time;
unsigned bool, secs;
pid_t pid;
/* Generate a different seed each time the function is called */
gettimeofday(&time, NULL);
srand(time.tv_usec);
/* Determine whether to sleep in parent of child and for how long */
bool = (unsigned) (CONVERT(rand()) + 0.5);
secs = (unsigned) (CONVERT(rand()) * MAX_SLEEP);
/* Call the real fork function */
if ((pid = fork()) < 0)
return pid;
/* Randomly decide to sleep in the parent or the child */
if (pid == 0) { /* Child */
if (bool) {
usleep(secs);
}
} else { /* Parent */
if (!bool) {
usleep(secs);
}
}
/* Return the PID like a normal fork call */
return pid;
}
|
the_stack_data/1170448.c | #if defined _Static_assert
# error Should not be defined, but valid to ask for it
#endif
#include <assert.h>
/* NOT actually on OpenBSD! (This is a bug) */
#ifdef __OpenBSD__
#define static_assert _Static_assert
#endif
_Static_assert('a' < 'b', "Alphabet error");
int foo(char a) {
_Static_assert(sizeof(a) == 1, "Hello");
return 0;
}
int main(void) {
return foo(42);
}
static_assert(1, "");
|
the_stack_data/246636.c | #include <stdio.h>
#define LOWER 0
#define UPPER 300
#define STEP 20
/* Print Fahrenheit-Celsius Table */
main(){
int fahr;
for (fahr = LOWER; fahr <= UPPER; fahr += STEP)
printf("%3d\t%6.1f\n", fahr, (5.0/9.0) * (fahr-32));
} |
the_stack_data/234518080.c | /*numPass=0, numTotal=5
Verdict:WRONG_ANSWER, Visibility:1, Input:"2", ExpOutput:"2*
*1
", Output:"5432*543*1"
Verdict:WRONG_ANSWER, Visibility:1, Input:"4", ExpOutput:"432*
43*1
4*21
*321
", Output:"5432*543*154*125*123"
Verdict:WRONG_ANSWER, Visibility:1, Input:"5", ExpOutput:"5432*
543*1
54*21
5*321
*4321
", Output:"5432*543*154*125*123*1234"
Verdict:WRONG_ANSWER, Visibility:0, Input:"1", ExpOutput:"*
", Output:"5432*"
Verdict:WRONG_ANSWER, Visibility:0, Input:"10", ExpOutput:"1098765432*
109876543*1
10987654*21
1098765*321
109876*4321
10987*54321
1098*654321
109*7654321
10*87654321
*987654321
", Output:"5432*543*154*125*123*1234*12345*123456*1234567*12345678*123456789"
*/
#include<stdio.h>
int main(){
int N,i,j,k;
scanf("%d",&N);
for(i=1;i<=N;i++)
{
for(j=5;j>i;j--){
printf("%d",j);
}
printf("*");
for(k=1;k<i;k++){
printf("%d",k);
}
}
//Enter your code here
return 0;
} |
the_stack_data/7950193.c | #include<stdio.h>
int main(int argc, char const *argv[])
{
/* code */
printf("hello world\n");
return 0;
} |
the_stack_data/140915.c | #include <stdio.h>
#include <stdlib.h>
#define SIZE 5
int count = 0;
struct node
{
int data;
struct node *addr;
};
typedef struct node *NODE;
NODE getnode()
{
return (NODE)malloc(sizeof(struct node));
}
NODE push(NODE start, int x)
{
if (count >= SIZE)
{
printf("Stack OverFlow \n");
return start;
exit(0);
}
NODE temp, cur;
temp = getnode();
temp->data = x;
temp->addr = NULL;
if (start == NULL)
{
return temp;
}
cur = start;
while (cur->addr != NULL)
{
cur = cur->addr;
}
cur->addr = temp;
count++;
return temp;
}
NODE pop(NODE start)
{
if (count == 0)
{
printf("Stack UnderFlow\n");
exit(1);
return start;
}
NODE cur, prev;
if (start == NULL)
{
printf("Empty List\n");
return NULL;
}
prev = NULL;
cur = start;
while (cur->addr != NULL)
{
prev = cur;
cur = cur->addr;
}
prev->addr = NULL;
printf(";Popped %d\n", cur->data);
free(cur);
count--;
return start;
}
void display(NODE start)
{
while (start != NULL)
{
printf("%d ", start->data);
start = start->addr;
}
}
int main()
{
NODE start;
start = getnode();
push(start, 1);
display(start);
pop(start);
display(start);
return 0;
} |
the_stack_data/148577408.c | #include <unistd.h>
#include <errno.h>
#include <string.h>
// For threads this needs to synchronize with chdir
#ifdef _REENTRANT
#error "getcwd doesn't yet support multiple threads"
#endif
char *__wasilibc_cwd = "/";
char *getcwd(char *buf, size_t size)
{
if (!buf) {
buf = strdup(__wasilibc_cwd);
if (!buf) {
errno = ENOMEM;
return NULL;
}
} else {
size_t len = strlen(__wasilibc_cwd);
if (size < strlen(__wasilibc_cwd) + 1) {
errno = ERANGE;
return NULL;
}
strcpy(buf, __wasilibc_cwd);
}
return buf;
}
|
the_stack_data/893841.c | /* This file is part of The Firekylin Operating System.
*
* Copyright 2016 Liuxiaofeng
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <sys/types.h>
#include <sys/syscall.h>
#include <sys/unistd.h>
#include <sys/fcntl.h>
#include <errno.h>
int dup2(int fd, int fd2)
{
return fcntl(fd, F_DUPFD, fd2);
}
|
the_stack_data/234519308.c | #include <stdio.h>
int main() {
int mark1, mark2;
float avg;
printf("Input marks for subject 1 :");
scanf("%d", &mark1);
printf("Input marks for subject 2 :");
scanf("%d", &mark2);
avg=(mark1 + mark2 )/2;
printf("Average is %.2f ",avg);
return 0;
}
|
the_stack_data/232956727.c | /*-
* Copyright (c) 1991, 1993
* Dave Safford. 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. Neither the name of the University 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 REGENTS 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 REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD: src/crypto/telnet/libtelnet/sra.c,v 1.1.2.7 2002/05/16 08:46:49 markm Exp $
*/
#ifdef SRA
#ifdef ENCRYPTION
#include <sys/types.h>
#include <arpa/telnet.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <ttyent.h>
#ifndef NOPAM
#include <security/pam_appl.h>
#else
#include <unistd.h>
#endif
#include "auth.h"
#include "misc.h"
#include "encrypt.h"
#include "pk.h"
char pka[HEXKEYBYTES+1], ska[HEXKEYBYTES+1], pkb[HEXKEYBYTES+1];
char *user, *pass, *xuser, *xpass;
DesData ck;
IdeaData ik;
extern int auth_debug_mode;
extern char line[16];
static int sra_valid = 0;
static int passwd_sent = 0;
static unsigned char str_data[1024] = {
IAC, SB, TELOPT_AUTHENTICATION, 0, AUTHTYPE_SRA, };
#define SMALL_LEN 256
#define XSMALL_LEN 513
#define SRA_KEY 0
#define SRA_USER 1
#define SRA_CONTINUE 2
#define SRA_PASS 3
#define SRA_ACCEPT 4
#define SRA_REJECT 5
static int check_user(char *, const char *);
/* support routine to send out authentication message */
static int
Data(Authenticator *ap, int type, void *d, int c)
{
unsigned char *p = str_data + 4;
unsigned char *cd = (unsigned char *)d;
if (c == -1)
c = strlen((char *)cd);
if (auth_debug_mode) {
printf("%s:%d: [%d] (%d)",
str_data[3] == TELQUAL_IS ? ">>>IS" : ">>>REPLY",
str_data[3],
type, c);
printd(d, c);
printf("\r\n");
}
*p++ = ap->type;
*p++ = ap->way;
*p++ = type;
while (c-- > 0) {
if ((*p++ = *cd++) == IAC)
*p++ = IAC;
}
*p++ = IAC;
*p++ = SE;
if (str_data[3] == TELQUAL_IS)
printsub('>', &str_data[2], p - (&str_data[2]));
return(net_write(str_data, p - str_data));
}
int
sra_init(Authenticator *ap __unused, int server)
{
if (server)
str_data[3] = TELQUAL_REPLY;
else
str_data[3] = TELQUAL_IS;
user = malloc(SMALL_LEN);
xuser = malloc(XSMALL_LEN);
pass = malloc(SMALL_LEN);
xpass = malloc(XSMALL_LEN);
if (user == NULL || xuser == NULL || pass == NULL || xpass == NULL)
return 0; /* malloc failed */
passwd_sent = 0;
genkeys(pka, ska);
return(1);
}
/* client received a go-ahead for sra */
int
sra_send(Authenticator *ap)
{
/* send PKA */
if (auth_debug_mode)
printf("Sent PKA to server.\r\n" );
printf("Trying SRA secure login:\r\n");
if (!Data(ap, SRA_KEY, (void *)pka, HEXKEYBYTES)) {
if (auth_debug_mode)
printf("Not enough room for authentication data\r\n");
return(0);
}
return(1);
}
/* server received an IS -- could be SRA KEY, USER, or PASS */
void
sra_is(Authenticator *ap, unsigned char *data, int cnt)
{
int valid;
Session_Key skey;
if (cnt-- < 1)
goto bad;
switch (*data++) {
case SRA_KEY:
if (cnt < HEXKEYBYTES) {
Data(ap, SRA_REJECT, (void *)0, 0);
auth_finished(ap, AUTH_USER);
if (auth_debug_mode)
printf("SRA user rejected for bad PKB\r\n");
return;
}
if (auth_debug_mode)
printf("Sent pka\r\n");
if (!Data(ap, SRA_KEY, (void *)pka, HEXKEYBYTES)) {
if (auth_debug_mode)
printf("Not enough room\r\n");
return;
}
memcpy(pkb, data, HEXKEYBYTES);
pkb[HEXKEYBYTES] = '\0';
common_key(ska, pkb, &ik, &ck);
return;
case SRA_USER:
/* decode KAB(u) */
if (cnt > XSMALL_LEN - 1) /* Attempted buffer overflow */
break;
memcpy(xuser, data, cnt);
xuser[cnt] = '\0';
pk_decode(xuser, user, &ck);
auth_encrypt_user(user);
Data(ap, SRA_CONTINUE, (void *)0, 0);
return;
case SRA_PASS:
if (cnt > XSMALL_LEN - 1) /* Attempted buffer overflow */
break;
/* decode KAB(P) */
memcpy(xpass, data, cnt);
xpass[cnt] = '\0';
pk_decode(xpass, pass, &ck);
/* check user's password */
valid = check_user(user, pass);
if (valid) {
Data(ap, SRA_ACCEPT, (void *)0, 0);
skey.data = ck;
skey.type = SK_DES;
skey.length = 8;
encrypt_session_key(&skey, 1);
sra_valid = 1;
auth_finished(ap, AUTH_VALID);
if (auth_debug_mode)
printf("SRA user accepted\r\n");
} else {
Data(ap, SRA_CONTINUE, (void *)0, 0);
/*
Data(ap, SRA_REJECT, (void *)0, 0);
sra_valid = 0;
auth_finished(ap, AUTH_REJECT);
*/
if (auth_debug_mode)
printf("SRA user failed\r\n");
}
return;
default:
if (auth_debug_mode)
printf("Unknown SRA option %d\r\n", data[-1]);
}
bad:
Data(ap, SRA_REJECT, 0, 0);
sra_valid = 0;
auth_finished(ap, AUTH_REJECT);
}
/* client received REPLY -- could be SRA KEY, CONTINUE, ACCEPT, or REJECT */
void
sra_reply(Authenticator *ap, unsigned char *data, int cnt)
{
char uprompt[SMALL_LEN], tuser[SMALL_LEN];
Session_Key skey;
size_t i;
if (cnt-- < 1)
return;
switch (*data++) {
case SRA_KEY:
/* calculate common key */
if (cnt < HEXKEYBYTES) {
if (auth_debug_mode)
printf("SRA user rejected for bad PKB\r\n");
return;
}
memcpy(pkb, data, HEXKEYBYTES);
pkb[HEXKEYBYTES] = '\0';
common_key(ska, pkb, &ik, &ck);
enc_user:
/* encode user */
memset(tuser, 0, sizeof(tuser));
sprintf(uprompt, "User (%s): ", UserNameRequested);
if (telnet_gets(uprompt, tuser, SMALL_LEN-1, 1) == NULL) {
printf("\n");
exit(1);
}
if (tuser[0] == '\n' || tuser[0] == '\r' ) {
strlcpy(user, UserNameRequested, SMALL_LEN);
} else {
/* telnet_gets leaves the newline on */
for (i = 0; i < sizeof(tuser); i++) {
if (tuser[i] == '\n') {
tuser[i] = '\0';
break;
}
}
strlcpy(user, tuser, SMALL_LEN);
}
pk_encode(user, xuser, &ck);
/* send it off */
if (auth_debug_mode)
printf("Sent KAB(U)\r\n");
if (!Data(ap, SRA_USER, xuser, strlen(xuser))) {
if (auth_debug_mode)
printf("Not enough room\r\n");
return;
}
break;
case SRA_CONTINUE:
if (passwd_sent) {
passwd_sent = 0;
printf("[ SRA login failed ]\r\n");
goto enc_user;
}
/* encode password */
memset(pass, 0, SMALL_LEN);
if (telnet_gets("Password: ", pass, SMALL_LEN-1, 0) == NULL) {
printf("\n");
exit(1);
}
pk_encode(pass, xpass, &ck);
/* send it off */
if (auth_debug_mode)
printf("Sent KAB(P)\r\n");
if (!Data(ap, SRA_PASS, xpass, strlen(xpass))) {
if (auth_debug_mode)
printf("Not enough room\r\n");
return;
}
passwd_sent = 1;
break;
case SRA_REJECT:
printf("[ SRA refuses authentication ]\r\n");
printf("Trying plaintext login:\r\n");
auth_finished(0, AUTH_REJECT);
return;
case SRA_ACCEPT:
printf("[ SRA accepts you ]\r\n");
skey.data = ck;
skey.type = SK_DES;
skey.length = 8;
encrypt_session_key(&skey, 0);
auth_finished(ap, AUTH_VALID);
return;
default:
if (auth_debug_mode)
printf("Unknown SRA option %d\r\n", data[-1]);
return;
}
}
int
sra_status(Authenticator *ap __unused, char *name, int level)
{
if (level < AUTH_USER)
return(level);
if (UserNameRequested && sra_valid) {
strcpy(name, UserNameRequested);
return(AUTH_VALID);
} else {
return(AUTH_USER);
}
}
#define BUMP(buf, len) while (*(buf)) { ++(buf), --(len); }
#define ADDC(buf, len, c) if ((len) > 0) { *(buf)++ = (c); --(len); }
void
sra_printsub(unsigned char *data, int cnt, unsigned char *ubuf, int buflen)
{
char lbuf[32], *buf = (char *)ubuf;
int i;
buf[buflen-1] = '\0'; /* make sure its NULL terminated */
buflen -= 1;
switch (data[3]) {
case SRA_CONTINUE:
strncpy(buf, " CONTINUE ", buflen);
goto common;
case SRA_REJECT: /* Rejected (reason might follow) */
strncpy(buf, " REJECT ", buflen);
goto common;
case SRA_ACCEPT: /* Accepted (name might follow) */
strncpy(buf, " ACCEPT ", buflen);
common:
BUMP(buf, buflen);
if (cnt <= 4)
break;
ADDC(buf, buflen, '"');
for (i = 4; i < cnt; i++)
ADDC(buf, buflen, data[i]);
ADDC(buf, buflen, '"');
ADDC(buf, buflen, '\0');
break;
case SRA_KEY: /* Authentication data follows */
strncpy(buf, " KEY ", buflen);
goto common2;
case SRA_USER:
strncpy(buf, " USER ", buflen);
goto common2;
case SRA_PASS:
strncpy(buf, " PASS ", buflen);
goto common2;
default:
snprintf(lbuf, sizeof(lbuf), " %d (unknown)", data[3]);
strncpy(buf, lbuf, buflen);
common2:
BUMP(buf, buflen);
for (i = 4; i < cnt; i++) {
snprintf(lbuf, sizeof(lbuf), " %d", data[i]);
strncpy(buf, lbuf, buflen);
BUMP(buf, buflen);
}
break;
}
}
#ifdef NOPAM
static int
isroot(const char *usr)
{
struct passwd pws, *pwd;
char pwbuf[1024];
if (getpwnam_r(usr, &pws, pwbuf, sizeof(pwbuf), &pwd) != 0 ||
pwd == NULL)
return 0;
return (!pwd->pw_uid);
}
static int
rootterm(const char *ttyn)
{
struct ttyent *t;
return ((t = getttynam(ttyn)) && t->ty_status & TTY_SECURE);
}
static int
check_user(char *name, const char *cred)
{
struct passwd pws, *pw;
char pwbuf[1024];
char *xpasswd, *salt;
if (isroot(name) && !rootterm(line)) {
crypt("AA", "*"); /* Waste some time to simulate success */
return(0);
}
if (getpwnam_r(name, &pws, pwbuf, sizeof(pwbuf), &pw) == 0 &&
pw != NULL) {
if (pw->pw_shell == NULL)
return(0);
salt = pw->pw_passwd;
xpasswd = crypt(cred, salt);
/* The strcmp does not catch null passwords! */
if (*pw->pw_passwd == '\0' || strcmp(xpasswd, pw->pw_passwd))
return(0);
return(1);
}
return(0);
}
#else /* !NOPAM */
/*
* The following is stolen from ftpd, which stole it from the imap-uw
* PAM module and login.c. It is needed because we can't really
* "converse" with the user, having already gone to the trouble of
* getting their username and password through an encrypted channel.
*/
#define COPY_STRING(s) (s ? strdup(s) : NULL)
struct cred_t {
const char *uname;
const char *pass;
};
typedef struct cred_t cred_t;
static int
auth_conv(int num_msg, const struct pam_message **msg,
struct pam_response **resp, void *appdata)
{
int i;
cred_t *cred = appdata;
struct pam_response *reply = malloc(sizeof(*reply) * num_msg);
if (reply == NULL)
return PAM_BUF_ERR;
for (i = 0; i < num_msg; i++) {
switch (msg[i]->msg_style) {
case PAM_PROMPT_ECHO_ON: /* assume want user name */
reply[i].resp_retcode = PAM_SUCCESS;
reply[i].resp = COPY_STRING(cred->uname);
/* PAM frees resp. */
break;
case PAM_PROMPT_ECHO_OFF: /* assume want password */
reply[i].resp_retcode = PAM_SUCCESS;
reply[i].resp = COPY_STRING(cred->pass);
/* PAM frees resp. */
break;
case PAM_TEXT_INFO:
case PAM_ERROR_MSG:
reply[i].resp_retcode = PAM_SUCCESS;
reply[i].resp = NULL;
break;
default: /* unknown message style */
free(reply);
return PAM_CONV_ERR;
}
}
*resp = reply;
return PAM_SUCCESS;
}
/*
* The PAM version as a side effect may put a new username in *name.
*/
static int
check_user(char *name, const char *cred)
{
pam_handle_t *pamh = NULL;
const void *item;
int rval;
int e;
cred_t auth_cred = { name, cred };
struct pam_conv conv = { &auth_conv, &auth_cred };
e = pam_start("telnetd", name, &conv, &pamh);
if (e != PAM_SUCCESS) {
syslog(LOG_ERR, "pam_start: %s", pam_strerror(pamh, e));
return 0;
}
#if 0 /* Where can we find this value? */
e = pam_set_item(pamh, PAM_RHOST, remotehost);
if (e != PAM_SUCCESS) {
syslog(LOG_ERR, "pam_set_item(PAM_RHOST): %s",
pam_strerror(pamh, e));
return 0;
}
#endif
e = pam_authenticate(pamh, 0);
switch (e) {
case PAM_SUCCESS:
/*
* With PAM we support the concept of a "template"
* user. The user enters a login name which is
* authenticated by PAM, usually via a remote service
* such as RADIUS or TACACS+. If authentication
* succeeds, a different but related "template" name
* is used for setting the credentials, shell, and
* home directory. The name the user enters need only
* exist on the remote authentication server, but the
* template name must be present in the local password
* database.
*
* This is supported by two various mechanisms in the
* individual modules. However, from the application's
* point of view, the template user is always passed
* back as a changed value of the PAM_USER item.
*/
if ((e = pam_get_item(pamh, PAM_USER,
&item)) == PAM_SUCCESS)
strlcpy(name, item, SMALL_LEN);
else
syslog(LOG_ERR, "Couldn't get PAM_USER: %s",
pam_strerror(pamh, e));
rval = 1;
#if 0 /* pam_securetty(8) should be used to enforce this */
if (isroot(name) && !rootterm(line))
rval = 0;
#endif
break;
case PAM_AUTH_ERR:
case PAM_USER_UNKNOWN:
case PAM_MAXTRIES:
rval = 0;
break;
default:
syslog(LOG_ERR, "auth_pam: %s", pam_strerror(pamh, e));
rval = 0;
break;
}
if ((e = pam_end(pamh, e)) != PAM_SUCCESS) {
syslog(LOG_ERR, "pam_end: %s", pam_strerror(pamh, e));
rval = 0;
}
return rval;
}
#endif /* !NOPAM */
#endif /* ENCRYPTION */
#endif /* SRA */
|
the_stack_data/92325323.c | #include <stdio.h>
#include <stdlib.h>
#include <time.h>
unsigned int input(char *title) {
printf("%s", title);
unsigned int size;
scanf("%u", &size);
return (size);
};
unsigned int * generate_random_vector(unsigned int size) {
unsigned int *vector = malloc(sizeof (*vector) * size);
for (unsigned int i = 0; i < size; i++) {
vector[i] = rand() % 10;
};
return (vector);
};
unsigned int ** generate_random_matrix(unsigned int size) {
unsigned int **matrix = malloc(sizeof (*matrix) * size);
for (unsigned int i = 0; i < size; i++) {
matrix[i] = generate_random_vector(size);
};
return (matrix);
};
unsigned int ** multiplication_matrices(unsigned int size, unsigned int **matrix_a, unsigned int **matrix_b) {
unsigned int **matrix = malloc(sizeof (*matrix) * size);
for (unsigned int i = 0; i < size; i++) {
matrix[i] = malloc(sizeof (*matrix[i]) * size);
for (unsigned int t = 0; t < size; t++) {
for (unsigned int n = 0; n < size; n++) {
matrix[i][t] += matrix_a[i][n] * matrix_b[n][t];
};
};
};
return (matrix);
};
void print(unsigned int size, unsigned int **matrix) {
for (unsigned int i = 0; i < size; i++) {
for (unsigned int n = 0; n < size; n++) {
printf("%u ", matrix[i][n]);
};
printf("\n");
};
};
int main(void) {
srand(time(NULL));
unsigned int size = input("enter size: ");
printf("\nA:\n");
unsigned int **matrix_a = generate_random_matrix(size);
print(size, matrix_a);
printf("\nB:\n");
unsigned int **matrix_b = generate_random_matrix(size);
print(size, matrix_b);
printf("\nC:\n");
unsigned int begin = time(NULL);
unsigned int **matrix_c = multiplication_matrices(size, matrix_a, matrix_b);
unsigned int end = time(NULL);
print(size, matrix_c);
printf("\ntime: %u seconds\n", (end - begin));
free(matrix_a);
free(matrix_b);
free(matrix_c);
return (0);
};
|
the_stack_data/100141341.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#define BUF_SIZE 200
int main(int argc, char *argv[])
{
int sock_fd, conn_fd;
struct sockaddr_in server_addr;
char buff[BUF_SIZE];
int ret;
int port_number = 2047;
// 创建socket描述符
if ((sock_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
fprintf(stderr,"Socket error:%s\n\a", strerror(errno));
exit(1);
}
// 填充sockaddr_in结构
bzero(&server_addr, sizeof(struct sockaddr_in));
server_addr.sin_family = AF_INET;
server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
server_addr.sin_port = htons(port_number);
// 绑定sock_fd描述符
if (bind(sock_fd, (struct sockaddr *)(&server_addr), sizeof(struct sockaddr)) == -1) {
fprintf(stderr,"Bind error:%s\n\a", strerror(errno));
exit(1);
}
// 监听sock_fd描述符
if(listen(sock_fd, 5) == -1) {
fprintf(stderr,"Listen error:%s\n\a", strerror(errno));
exit(1);
}
while(1) {
// 接受请求
if ((conn_fd = accept(sock_fd, (struct sockaddr *)NULL, NULL)) == -1) {
printf("accept socket error: %s\n\a", strerror(errno));
continue;
}
// 开子进程处理数据
if (fork() == 0) {
while(1) {
// 接受数据
ret = recv(conn_fd, buff, BUF_SIZE, 0);
if (ret <= 0) {
// 客户端关闭
printf("client close\n");
close(conn_fd);
break;
} else {
// 添加结束符
if (ret < BUF_SIZE) {
memset(&buff[ret], '\0', 1);
}
printf("recv msg from client: %s\n", buff);
// 发送数据
send(conn_fd, "Hello", 6, 0);
}
}
close(conn_fd);
exit(0);
}
}
close(sock_fd);
exit(0);
} |
the_stack_data/126702857.c | #include <stdlib.h>
#include <string.h>
#include <stdio.h>
int main() {
char **test = malloc(sizeof(char *) * 10);
for (int i = 0; i < 10; i++) {
test[i] = malloc(10);
}
strcat(test[0], "hello");
printf("%s, %s\n", test[0], test[1]);
}
|
the_stack_data/187642995.c | #include <stdio.h>
#include <stdlib.h>
int main()
{
//we have to find out the largest no. by using dynamic memory allocation
int a ,b,*ptr,i=0,j,n;
printf("Enter the no of elements you want to enter");
scanf("%d",&n);
ptr = (int*)calloc(n,sizeof(int));
if(ptr== NULL)
{
printf("the memory is unavialable");
exit(0);
}
printf("Enter the no. one by one");
for(i=0;i<n;i++)
scanf("%d",ptr+i);
//now we have to find out the largest no...
a=*ptr;
printf("%d\n",a);
for(i=0;i<n-1;i++)
{
if(a<*(ptr+i+1))
{
a=*(ptr+i+1);
printf("%d\n",a);
}
}
printf("\n\n%d",a);
free(ptr);
return 0;
}
|
the_stack_data/340655.c | #include<stdio.h>
int main()
{
int i,j,n,k,t;
scanf("%d",&t);
int numer[t];
int val[t][100],store[100];
for(i=0;i<t;i++)
{
scanf("%d %d",&n,&k);
numer[i]=n;
for(j=0;j<n;j++)
scanf("%d",&store[j]);
for(j=0;j<n;j++)
{
if(store[j]<=k)
{
k-=store[j];
val[i][j]=1;
}
else
val[i][j]=0;
}
}
for(i=0;i<t;i++)
{
for(j=0;j<numer[i];j++)
printf("%d",val[i][j]);
printf("\n");
}
}
|
the_stack_data/73576261.c | #include<stdio.h>
#include<math.h>
int zspd(int x);
int main()
{
int n,a,i,flag;
scanf("%d",&n);
flag=zspd(n+1);
if(flag==0)
printf("%d",n+1);
else
{
i=2;
while(flag==1)
{
flag=zspd(n+i);
i++;
}
printf("%d",n+i-1);
}
return 0;
}
int zspd(int x)
{
double a;
int i,flag;
flag=0;
a=sqrt(x);
for(i=2;i<a+1;i++)
{
if(x%i==0)
flag=1;
}
return flag;
} |
the_stack_data/190769495.c | #include <stdio.h>
#ifdef PLAYSTATION1
#include <psx.h>
#include "LMP3D/LMP3D.h"
#include "LMP3D/PS1/PS1.h"
extern short sincostbl[4096];
#define fastsin(v) sincostbl[v&0xFFF];
#define fastcos(v) sincostbl[(v+1024)&0xFFF];
void LMP3D_MatrixRotateXS(short *matrix,short rotate)
{
short cosAngle = fastcos(rotate);
short sinAngle = fastsin(rotate);
matrix[0+0] = 1<<12;
matrix[0+1] = 0<<12;
matrix[0+2] = 0<<12;
matrix[3+0] = 0<<12;
matrix[3+1] = cosAngle;
matrix[3+2] = sinAngle;
matrix[6+0] = 0<<12;
matrix[6+1] = -sinAngle;
matrix[6+2] = cosAngle;
}
void LMP3D_MatrixRotateYS(short *matrix,short rotate)
{
short cosAngle = fastcos(rotate);
short sinAngle = fastsin(rotate);
matrix[0+0] = cosAngle;
matrix[0+1] = 0<<12;
matrix[0+2] = -sinAngle;
matrix[3+0] = 0<<12;
matrix[3+1] = 1<<12;
matrix[3+2] = 0<<12;
matrix[6+0] = sinAngle;
matrix[6+1] = 0<<12;
matrix[6+2] = cosAngle;
}
void LMP3D_MatrixRotateZS(short *matrix,short rotate)
{
short cosAngle = fastcos(rotate);
short sinAngle = fastsin(rotate);
matrix[0+0] = cosAngle;
matrix[0+1] = sinAngle;
matrix[0+2] = 0<<12;
matrix[3+0] = -sinAngle;
matrix[3+1] = cosAngle;
matrix[3+2] = 0<<12;
matrix[6+0] = 0<<12;
matrix[6+1] = 0<<12;
matrix[6+2] = 1<<12;
matrix[6+3] = 0;
}
void LMP3D_MatrixMultiply(float* dest,float* src1,float* src2)
{
}
#endif
|
the_stack_data/127341.c | /*
* Square matrix multiplication
* A[N][N] * B[N][N] = C[N][N]
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/timeb.h>
#include <malloc.h>
#define N 512
//#define N 16
// read timer in second
double read_timer() {
struct timeb tm;
ftime(&tm);
return (double) tm.time + (double) tm.millitm / 1000.0;
}
void init(float **A) {
int i, j;
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
A[i][j] = (float)rand()/(float)(RAND_MAX/10.0);
}
}
}
void matmul_simd(float **A, float **B, float **C) {
int i,j,k;
float temp;
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
temp = 0;
#pragma omp simd reduction(+:temp)
for (k = 0; k < N; k++) {
temp += A[i][k] * B[j][k];
}
C[i][j] = temp;
}
}
}
// Debug functions
void print_matrix(float **matrix) {
for (int i = 0; i<8; i++) {
printf("[");
for (int j = 0; j<8; j++) {
printf("%.2f ", matrix[i][j]);
}
puts("]");
}
puts("");
}
void matmul_serial(float **A, float **B, float **C) {
int i,j,k;
float temp;
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
temp = 0;
for (k = 0; k < N; k++) {
temp += A[i][k] * B[j][k];
}
C[i][j] = temp;
}
}
}
float check(float **A, float **B){
float difference = 0;
for(int i = 0;i<N; i++){
for (int j = 0; j<N; j++)
{ difference += A[i][j]- B[i][j];}
}
return difference;
}
// Main
int main(int argc, char *argv[]) {
//Set everything up
float **A = malloc(sizeof(float*)*N);
float **B = malloc(sizeof(float*)*N);
float **C_simd = malloc(sizeof(float*)*N);
float **C_serial = malloc(sizeof(float*)*N);
float **BT = malloc(sizeof(float*)*N);
for (int i = 0; i<N; i++) {
A[i] = malloc(sizeof(float)*N);
B[i] = malloc(sizeof(float)*N);
C_simd[i] = malloc(sizeof(float)*N);
C_serial[i] = malloc(sizeof(float)*N);
BT[i] = malloc(sizeof(float)*N);
}
srand(time(NULL));
init(A);
init(B);
for(int line = 0; line<N; line++){
for(int col = 0; col<N; col++){
BT[line][col] = B[col][line];
}
}
int i;
int num_runs = 10;
double elapsed = read_timer();
for (i=0; i<num_runs; i++)
matmul_simd(A, BT, C_simd);
elapsed = (read_timer() - elapsed);
double elapsed_serial = read_timer();
for (i=0; i<num_runs; i++)
matmul_serial(A, BT, C_serial);
elapsed_serial = (read_timer() - elapsed_serial);
print_matrix(A);
print_matrix(BT);
puts("=\n");
print_matrix(C_simd);
puts("---------------------------------");
print_matrix(C_serial);
double gflops_omp = ((((2.0 * N) * N) * N * num_runs) / (1.0e9 * elapsed));
double gflops_serial = ((((2.0 * N) * N) * N * num_runs) / (1.0e9 * elapsed_serial));
printf("======================================================================================================\n");
printf("\tMatrix Multiplication: A[N][N] * B[N][N] = C[N][N], N=%d\n", N);
printf("------------------------------------------------------------------------------------------------------\n");
printf("Performance:\t\tRuntime (s)\t GFLOPS\n");
printf("------------------------------------------------------------------------------------------------------\n");
printf("matmul_omp:\t\t%4f\t%4f\n", elapsed, gflops_omp);
printf("matmul_serial:\t\t%4f\t%4f\n", elapsed_serial, gflops_serial);
printf("Correctness check: %f\n", check(C_simd,C_serial));
return 0;
}
|
the_stack_data/100407.c | // EXPECT: 40
int main() {
int i = 5;
i <<= 3;
return i;
} |
the_stack_data/706379.c | #include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <pthread.h>
#define THRNUM 4
static pthread_barrier_t barr;
static void *thr_func(void *ptr)
{
int n = (int)ptr;
char c='a'+n;
while (1) {
write(1, &c, 1);
sleep(rand()%5);
pthread_barrier_wait(&barr);
}
pthread_exit(NULL);
}
int
main()
{
int i;
int err;
pthread_t tid[THRNUM];
pthread_barrier_init(&barr, NULL, THRNUM);
for (i=0;i<THRNUM;++i) {
err = pthread_create(tid+i, NULL, thr_func, (void*)i);
if (err) {
fprintf(stderr, "pthread_create(): %s\n", strerror(err));
exit(1);
}
}
while (1) pause();
pthread_barrier_destroy(&barr);
exit(0);
}
|
the_stack_data/234517096.c | /*
* SigV4 Utility Library v1.0.0
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @file memmove.c
* @brief A stub for memmove so that the proofs for functions that call
* memmove run much faster.
*/
#include <string.h>
/* This is a clang macro not available on linux */
#ifndef __has_builtin
#define __has_builtin( x ) 0
#endif
#if __has_builtin( __builtin___memmove_chk )
void * __builtin___memmove_chk( void * dest,
const void * src,
size_t n,
size_t m )
{
/* Attempting to read or write 0 bytes will make __CPROVER_r/w_ok
* fail. However, per ANSI C specification, memcpy must be able
* to handle a copy length of zero. */
__CPROVER_assert( ( n == 0 ) || __CPROVER_w_ok( dest, n ), "write" );
__CPROVER_assert( ( n == 0 ) || __CPROVER_r_ok( src, n ), "read" );
return dest;
}
#else /* if __has_builtin( __builtin___memmove_chk ) */
void * memmove( void * dest,
const void * src,
size_t n )
{
__CPROVER_assert( __CPROVER_w_ok( dest, n ), "write" );
__CPROVER_assert( __CPROVER_r_ok( src, n ), "read" );
return dest;
}
#endif /* if __has_builtin( __builtin___memmove_chk ) */
|
the_stack_data/93886874.c | /*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2016 Glenn Ruben Bakke
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#if BLUETOOTH_SD
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include "py/runtime.h"
#include "ble_drv.h"
#include "mpconfigport.h"
#include "nrf_sdm.h"
#include "ble_gap.h"
#include "ble.h" // sd_ble_uuid_encode
#define BLE_DRIVER_VERBOSE 0
#if BLE_DRIVER_VERBOSE
#define BLE_DRIVER_LOG printf
#else
#define BLE_DRIVER_LOG(...)
#endif
#define BLE_ADV_LENGTH_FIELD_SIZE 1
#define BLE_ADV_AD_TYPE_FIELD_SIZE 1
#define BLE_AD_TYPE_FLAGS_DATA_SIZE 1
#define MSEC_TO_UNITS(TIME, RESOLUTION) (((TIME) * 1000) / (RESOLUTION))
#define UNIT_0_625_MS (625)
#define UNIT_10_MS (10000)
#define APP_CFG_NON_CONN_ADV_TIMEOUT 0 // Disable timeout.
#define NON_CONNECTABLE_ADV_INTERVAL MSEC_TO_UNITS(100, UNIT_0_625_MS)
#define BLE_MIN_CONN_INTERVAL MSEC_TO_UNITS(12, UNIT_0_625_MS)
#define BLE_MAX_CONN_INTERVAL MSEC_TO_UNITS(12, UNIT_0_625_MS)
#define BLE_SLAVE_LATENCY 0
#define BLE_CONN_SUP_TIMEOUT MSEC_TO_UNITS(4000, UNIT_10_MS)
#define SD_TEST_OR_ENABLE() \
if (ble_drv_stack_enabled() == 0) { \
(void)ble_drv_stack_enable(); \
}
static volatile bool m_adv_in_progress;
static volatile bool m_tx_in_progress;
static ble_drv_gap_evt_callback_t gap_event_handler;
static ble_drv_gatts_evt_callback_t gatts_event_handler;
static mp_obj_t mp_gap_observer;
static mp_obj_t mp_gatts_observer;
#if (BLUETOOTH_SD == 130) || (BLUETOOTH_SD == 132) || (BLUETOOTH_SD == 140)
static volatile bool m_primary_service_found;
static volatile bool m_characteristic_found;
static volatile bool m_write_done;
static volatile ble_drv_adv_evt_callback_t adv_event_handler;
static volatile ble_drv_gattc_evt_callback_t gattc_event_handler;
static volatile ble_drv_disc_add_service_callback_t disc_add_service_handler;
static volatile ble_drv_disc_add_char_callback_t disc_add_char_handler;
static volatile ble_drv_gattc_char_data_callback_t gattc_char_data_handle;
static mp_obj_t mp_adv_observer;
static mp_obj_t mp_gattc_observer;
static mp_obj_t mp_gattc_disc_service_observer;
static mp_obj_t mp_gattc_disc_char_observer;
static mp_obj_t mp_gattc_char_data_observer;
#endif
#if (BLUETOOTH_SD != 100) && (BLUETOOTH_SD != 110)
#include "nrf_nvic.h"
#ifdef NRF52
nrf_nvic_state_t nrf_nvic_state = {0};
#endif // NRF52
#endif // (BLUETOOTH_SD != 100)
#if (BLUETOOTH_SD == 100 ) || (BLUETOOTH_SD == 110)
void softdevice_assert_handler(uint32_t pc, uint16_t line_number, const uint8_t * p_file_name) {
BLE_DRIVER_LOG("ERROR: SoftDevice assert!!!");
}
#else
void softdevice_assert_handler(uint32_t id, uint32_t pc, uint32_t info) {
BLE_DRIVER_LOG("ERROR: SoftDevice assert!!!");
}
#endif
uint32_t ble_drv_stack_enable(void) {
m_adv_in_progress = false;
m_tx_in_progress = false;
#if (BLUETOOTH_SD == 100) || (BLUETOOTH_SD == 110)
#if BLUETOOTH_LFCLK_RC
uint32_t err_code = sd_softdevice_enable(NRF_CLOCK_LFCLKSRC_RC_250_PPM_250MS_CALIBRATION,
softdevice_assert_handler);
#else
uint32_t err_code = sd_softdevice_enable(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM,
softdevice_assert_handler);
#endif // BLUETOOTH_LFCLK_RC
#else
#if BLUETOOTH_LFCLK_RC
nrf_clock_lf_cfg_t clock_config = {
.source = NRF_CLOCK_LF_SRC_RC,
.rc_ctiv = 16,
.rc_temp_ctiv = 2,
#if (BLUETOOTH_SD == 140)
.accuracy = 0
#else
.xtal_accuracy = 0
#endif
};
#else
nrf_clock_lf_cfg_t clock_config = {
.source = NRF_CLOCK_LF_SRC_XTAL,
.rc_ctiv = 0,
.rc_temp_ctiv = 0,
#if (BLUETOOTH_SD == 140)
.accuracy = NRF_CLOCK_LF_ACCURACY_20_PPM
#else
.xtal_accuracy = NRF_CLOCK_LF_XTAL_ACCURACY_20_PPM
#endif
};
#endif
uint32_t err_code = sd_softdevice_enable(&clock_config,
softdevice_assert_handler);
#endif
BLE_DRIVER_LOG("SoftDevice enable status: " UINT_FMT "\n", (uint16_t)err_code);
#if NRF51
err_code = sd_nvic_EnableIRQ(SWI2_IRQn);
#else
err_code = sd_nvic_EnableIRQ(SWI2_EGU2_IRQn);
#endif
BLE_DRIVER_LOG("IRQ enable status: " UINT_FMT "\n", (uint16_t)err_code);
// Enable BLE stack.
#if (BLUETOOTH_SD != 140)
ble_enable_params_t ble_enable_params;
memset(&ble_enable_params, 0x00, sizeof(ble_enable_params));
ble_enable_params.gatts_enable_params.attr_tab_size = BLE_GATTS_ATTR_TAB_SIZE_DEFAULT;
ble_enable_params.gatts_enable_params.service_changed = 0;
#if (BLUETOOTH_SD == 132)
ble_enable_params.gap_enable_params.periph_conn_count = 1;
ble_enable_params.gap_enable_params.central_conn_count = 1;
#endif
#endif
#if (BLUETOOTH_SD == 100) || (BLUETOOTH_SD == 110)
err_code = sd_ble_enable(&ble_enable_params);
#else
#if (BLUETOOTH_SD == 132)
uint32_t app_ram_start = 0x200039c0;
err_code = sd_ble_enable(&ble_enable_params, &app_ram_start); // 8K SD headroom from linker script.
BLE_DRIVER_LOG("BLE ram size: " UINT_FMT "\n", (uint16_t)app_ram_start);
#elif (BLUETOOTH_SD == 140)
uint32_t app_ram_start = 0x20004000;
err_code = sd_ble_enable(&app_ram_start);
BLE_DRIVER_LOG("BLE ram size: " UINT_FMT "\n", (uint16_t)app_ram_start);
#else
err_code = sd_ble_enable(&ble_enable_params, (uint32_t *)0x20001870);
#endif
#endif
BLE_DRIVER_LOG("BLE enable status: " UINT_FMT "\n", (uint16_t)err_code);
// set up security mode
ble_gap_conn_params_t gap_conn_params;
ble_gap_conn_sec_mode_t sec_mode;
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);
const char device_name[] = "micr";
if ((err_code = sd_ble_gap_device_name_set(&sec_mode,
(const uint8_t *)device_name,
strlen(device_name))) != 0) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
"Cannot apply GAP parameters."));
}
// set connection parameters
memset(&gap_conn_params, 0, sizeof(gap_conn_params));
gap_conn_params.min_conn_interval = BLE_MIN_CONN_INTERVAL;
gap_conn_params.max_conn_interval = BLE_MAX_CONN_INTERVAL;
gap_conn_params.slave_latency = BLE_SLAVE_LATENCY;
gap_conn_params.conn_sup_timeout = BLE_CONN_SUP_TIMEOUT;
if (sd_ble_gap_ppcp_set(&gap_conn_params) != 0) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
"Cannot set PPCP parameters."));
}
return err_code;
}
void ble_drv_stack_disable(void) {
sd_softdevice_disable();
}
uint8_t ble_drv_stack_enabled(void) {
uint8_t is_enabled;
uint32_t err_code = sd_softdevice_is_enabled(&is_enabled);
(void)err_code;
BLE_DRIVER_LOG("Is enabled status: " UINT_FMT "\n", (uint16_t)err_code);
return is_enabled;
}
void ble_drv_address_get(ble_drv_addr_t * p_addr) {
SD_TEST_OR_ENABLE();
ble_gap_addr_t local_ble_addr;
#if (BLUETOOTH_SD == 132 && BLE_API_VERSION == 3) || (BLUETOOTH_SD == 140)
uint32_t err_code = sd_ble_gap_addr_get(&local_ble_addr);
#else
uint32_t err_code = sd_ble_gap_address_get(&local_ble_addr);
#endif
if (err_code != 0) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
"Can not query for the device address."));
}
BLE_DRIVER_LOG("ble address, type: " HEX2_FMT ", " \
"address: " HEX2_FMT ":" HEX2_FMT ":" HEX2_FMT ":" \
HEX2_FMT ":" HEX2_FMT ":" HEX2_FMT "\n", \
local_ble_addr.addr_type, \
local_ble_addr.addr[5], local_ble_addr.addr[4], local_ble_addr.addr[3], \
local_ble_addr.addr[2], local_ble_addr.addr[1], local_ble_addr.addr[0]);
p_addr->addr_type = local_ble_addr.addr_type;
memcpy(p_addr->addr, local_ble_addr.addr, 6);
}
bool ble_drv_uuid_add_vs(uint8_t * p_uuid, uint8_t * idx) {
SD_TEST_OR_ENABLE();
if (sd_ble_uuid_vs_add((ble_uuid128_t const *)p_uuid, idx) != 0) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
"Can not add Vendor Specific 128-bit UUID."));
}
return true;
}
bool ble_drv_service_add(ubluepy_service_obj_t * p_service_obj) {
SD_TEST_OR_ENABLE();
if (p_service_obj->p_uuid->type > BLE_UUID_TYPE_BLE) {
ble_uuid_t uuid;
uuid.type = p_service_obj->p_uuid->uuid_vs_idx;
uuid.uuid = p_service_obj->p_uuid->value[0];
uuid.uuid += p_service_obj->p_uuid->value[1] << 8;
if (sd_ble_gatts_service_add(p_service_obj->type,
&uuid,
&p_service_obj->handle) != 0) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
"Can not add Service."));
}
} else if (p_service_obj->p_uuid->type == BLE_UUID_TYPE_BLE) {
BLE_DRIVER_LOG("adding service\n");
ble_uuid_t uuid;
uuid.type = p_service_obj->p_uuid->type;
uuid.uuid = p_service_obj->p_uuid->value[0];
uuid.uuid += p_service_obj->p_uuid->value[1] << 8;
if (sd_ble_gatts_service_add(p_service_obj->type,
&uuid,
&p_service_obj->handle) != 0) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
"Can not add Service."));
}
}
return true;
}
bool ble_drv_characteristic_add(ubluepy_characteristic_obj_t * p_char_obj) {
ble_gatts_char_md_t char_md;
ble_gatts_attr_md_t cccd_md;
ble_gatts_attr_t attr_char_value;
ble_uuid_t uuid;
ble_gatts_attr_md_t attr_md;
memset(&char_md, 0, sizeof(char_md));
char_md.char_props.broadcast = (p_char_obj->props & UBLUEPY_PROP_BROADCAST) ? 1 : 0;
char_md.char_props.read = (p_char_obj->props & UBLUEPY_PROP_READ) ? 1 : 0;
char_md.char_props.write_wo_resp = (p_char_obj->props & UBLUEPY_PROP_WRITE_WO_RESP) ? 1 : 0;
char_md.char_props.write = (p_char_obj->props & UBLUEPY_PROP_WRITE) ? 1 : 0;
char_md.char_props.notify = (p_char_obj->props & UBLUEPY_PROP_NOTIFY) ? 1 : 0;
char_md.char_props.indicate = (p_char_obj->props & UBLUEPY_PROP_INDICATE) ? 1 : 0;
#if 0
char_md.char_props.auth_signed_wr = (p_char_obj->props & UBLUEPY_PROP_NOTIFY) ? 1 : 0;
#endif
char_md.p_char_user_desc = NULL;
char_md.p_char_pf = NULL;
char_md.p_user_desc_md = NULL;
char_md.p_sccd_md = NULL;
// if cccd
if (p_char_obj->attrs & UBLUEPY_ATTR_CCCD) {
memset(&cccd_md, 0, sizeof(cccd_md));
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm);
cccd_md.vloc = BLE_GATTS_VLOC_STACK;
char_md.p_cccd_md = &cccd_md;
} else {
char_md.p_cccd_md = NULL;
}
uuid.type = p_char_obj->p_uuid->type;
uuid.uuid = p_char_obj->p_uuid->value[0];
uuid.uuid += p_char_obj->p_uuid->value[1] << 8;
memset(&attr_md, 0, sizeof(attr_md));
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
attr_md.vloc = BLE_GATTS_VLOC_STACK;
attr_md.rd_auth = 0;
attr_md.wr_auth = 0;
attr_md.vlen = 1;
memset(&attr_char_value, 0, sizeof(attr_char_value));
attr_char_value.p_uuid = &uuid;
attr_char_value.p_attr_md = &attr_md;
attr_char_value.init_len = sizeof(uint8_t);
attr_char_value.init_offs = 0;
#if (BLUETOOTH_SD == 140)
attr_char_value.max_len = (BLE_GATT_ATT_MTU_DEFAULT - 3);
#else
attr_char_value.max_len = (GATT_MTU_SIZE_DEFAULT - 3);
#endif
ble_gatts_char_handles_t handles;
if (sd_ble_gatts_characteristic_add(p_char_obj->service_handle,
&char_md,
&attr_char_value,
&handles) != 0) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
"Can not add Characteristic."));
}
// apply handles to object instance
p_char_obj->handle = handles.value_handle;
p_char_obj->user_desc_handle = handles.user_desc_handle;
p_char_obj->cccd_handle = handles.cccd_handle;
p_char_obj->sccd_handle = handles.sccd_handle;
return true;
}
bool ble_drv_advertise_data(ubluepy_advertise_data_t * p_adv_params) {
SD_TEST_OR_ENABLE();
uint8_t byte_pos = 0;
#if (BLUETOOTH_SD == 140)
uint8_t adv_data[BLE_GAP_ADV_SR_MAX_LEN_DEFAULT];
#else
uint8_t adv_data[BLE_GAP_ADV_MAX_SIZE];
#endif
if (p_adv_params->device_name_len > 0) {
ble_gap_conn_sec_mode_t sec_mode;
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);
if (sd_ble_gap_device_name_set(&sec_mode,
p_adv_params->p_device_name,
p_adv_params->device_name_len) != 0) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
"Can not apply device name in the stack."));
}
BLE_DRIVER_LOG("Device name applied\n");
adv_data[byte_pos] = (BLE_ADV_AD_TYPE_FIELD_SIZE + p_adv_params->device_name_len);
byte_pos += BLE_ADV_LENGTH_FIELD_SIZE;
adv_data[byte_pos] = BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME;
byte_pos += BLE_ADV_AD_TYPE_FIELD_SIZE;
memcpy(&adv_data[byte_pos], p_adv_params->p_device_name, p_adv_params->device_name_len);
// increment position counter to see if it fits, and in case more content should
// follow in this adv packet.
byte_pos += p_adv_params->device_name_len;
}
// Add FLAGS only if manually controlled data has not been used.
if (p_adv_params->data_len == 0) {
// set flags, default to disc mode
adv_data[byte_pos] = (BLE_ADV_AD_TYPE_FIELD_SIZE + BLE_AD_TYPE_FLAGS_DATA_SIZE);
byte_pos += BLE_ADV_LENGTH_FIELD_SIZE;
adv_data[byte_pos] = BLE_GAP_AD_TYPE_FLAGS;
byte_pos += BLE_AD_TYPE_FLAGS_DATA_SIZE;
adv_data[byte_pos] = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
byte_pos += 1;
}
if (p_adv_params->num_of_services > 0) {
bool type_16bit_present = false;
bool type_128bit_present = false;
for (uint8_t i = 0; i < p_adv_params->num_of_services; i++) {
ubluepy_service_obj_t * p_service = (ubluepy_service_obj_t *)p_adv_params->p_services[i];
if (p_service->p_uuid->type == UBLUEPY_UUID_16_BIT) {
type_16bit_present = true;
}
if (p_service->p_uuid->type == UBLUEPY_UUID_128_BIT) {
type_128bit_present = true;
}
}
if (type_16bit_present) {
uint8_t size_byte_pos = byte_pos;
// skip length byte for now, apply total length post calculation
byte_pos += BLE_ADV_LENGTH_FIELD_SIZE;
adv_data[byte_pos] = BLE_GAP_AD_TYPE_16BIT_SERVICE_UUID_COMPLETE;
byte_pos += BLE_ADV_AD_TYPE_FIELD_SIZE;
uint8_t uuid_total_size = 0;
uint8_t encoded_size = 0;
for (uint8_t i = 0; i < p_adv_params->num_of_services; i++) {
ubluepy_service_obj_t * p_service = (ubluepy_service_obj_t *)p_adv_params->p_services[i];
ble_uuid_t uuid;
uuid.type = p_service->p_uuid->type;
uuid.uuid = p_service->p_uuid->value[0];
uuid.uuid += p_service->p_uuid->value[1] << 8;
// calculate total size of uuids
if (sd_ble_uuid_encode(&uuid, &encoded_size, NULL) != 0) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
"Can not encode UUID, to check length."));
}
// do encoding into the adv buffer
if (sd_ble_uuid_encode(&uuid, &encoded_size, &adv_data[byte_pos]) != 0) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
"Can encode UUID into the advertisment packet."));
}
BLE_DRIVER_LOG("encoded uuid for service %u: ", 0);
for (uint8_t j = 0; j < encoded_size; j++) {
BLE_DRIVER_LOG(HEX2_FMT " ", adv_data[byte_pos + j]);
}
BLE_DRIVER_LOG("\n");
uuid_total_size += encoded_size; // size of entry
byte_pos += encoded_size; // relative to adv data packet
BLE_DRIVER_LOG("ADV: uuid size: %u, type: %u, uuid: %x%x, vs_idx: %u\n",
encoded_size, p_service->p_uuid->type,
p_service->p_uuid->value[1],
p_service->p_uuid->value[0],
p_service->p_uuid->uuid_vs_idx);
}
adv_data[size_byte_pos] = (BLE_ADV_AD_TYPE_FIELD_SIZE + uuid_total_size);
}
if (type_128bit_present) {
uint8_t size_byte_pos = byte_pos;
// skip length byte for now, apply total length post calculation
byte_pos += BLE_ADV_LENGTH_FIELD_SIZE;
adv_data[byte_pos] = BLE_GAP_AD_TYPE_128BIT_SERVICE_UUID_COMPLETE;
byte_pos += BLE_ADV_AD_TYPE_FIELD_SIZE;
uint8_t uuid_total_size = 0;
uint8_t encoded_size = 0;
for (uint8_t i = 0; i < p_adv_params->num_of_services; i++) {
ubluepy_service_obj_t * p_service = (ubluepy_service_obj_t *)p_adv_params->p_services[i];
ble_uuid_t uuid;
uuid.type = p_service->p_uuid->uuid_vs_idx;
uuid.uuid = p_service->p_uuid->value[0];
uuid.uuid += p_service->p_uuid->value[1] << 8;
// calculate total size of uuids
if (sd_ble_uuid_encode(&uuid, &encoded_size, NULL) != 0) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
"Can not encode UUID, to check length."));
}
// do encoding into the adv buffer
if (sd_ble_uuid_encode(&uuid, &encoded_size, &adv_data[byte_pos]) != 0) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
"Can encode UUID into the advertisment packet."));
}
BLE_DRIVER_LOG("encoded uuid for service %u: ", 0);
for (uint8_t j = 0; j < encoded_size; j++) {
BLE_DRIVER_LOG(HEX2_FMT " ", adv_data[byte_pos + j]);
}
BLE_DRIVER_LOG("\n");
uuid_total_size += encoded_size; // size of entry
byte_pos += encoded_size; // relative to adv data packet
BLE_DRIVER_LOG("ADV: uuid size: %u, type: %x%x, uuid: %u, vs_idx: %u\n",
encoded_size, p_service->p_uuid->type,
p_service->p_uuid->value[1],
p_service->p_uuid->value[0],
p_service->p_uuid->uuid_vs_idx);
}
adv_data[size_byte_pos] = (BLE_ADV_AD_TYPE_FIELD_SIZE + uuid_total_size);
}
}
if ((p_adv_params->data_len > 0) && (p_adv_params->p_data != NULL)) {
#if (BLUETOOTH_SD == 140)
if (p_adv_params->data_len + byte_pos > BLE_GAP_ADV_SR_MAX_LEN_DEFAULT) {
#else
if (p_adv_params->data_len + byte_pos > BLE_GAP_ADV_MAX_SIZE) {
#endif
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
"Can not fit data into the advertisment packet."));
}
memcpy(adv_data, p_adv_params->p_data, p_adv_params->data_len);
byte_pos += p_adv_params->data_len;
}
// scan response data not set
uint32_t err_code;
#if (BLUETOOTH_SD == 140)
const ble_data_t ble_adv_data = {
.p_data = adv_data,
.len = byte_pos
};
if ((err_code = sd_ble_gap_adv_data_set(BLE_GAP_ADV_SET_HANDLE_DEFAULT, &ble_adv_data, NULL)) != 0) {
#else
if ((err_code = sd_ble_gap_adv_data_set(adv_data, byte_pos, NULL, 0)) != 0) {
#endif
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
"Can not apply advertisment data. status: 0x" HEX2_FMT, (uint16_t)err_code));
}
BLE_DRIVER_LOG("Set Adv data size: " UINT_FMT "\n", byte_pos);
static ble_gap_adv_params_t m_adv_params;
// initialize advertising params
memset(&m_adv_params, 0, sizeof(m_adv_params));
if (p_adv_params->connectable) {
#if (BLUETOOTH_SD == 140)
m_adv_params.properties.connectable = 1;
m_adv_params.properties.scannable = 1;
#else
m_adv_params.type = BLE_GAP_ADV_TYPE_ADV_IND;
#endif
} else {
#if (BLUETOOTH_SD == 140)
m_adv_params.properties.connectable = 0;
#else
m_adv_params.type = BLE_GAP_ADV_TYPE_ADV_NONCONN_IND;
#endif
}
m_adv_params.p_peer_addr = NULL; // undirected advertisement
m_adv_params.fp = BLE_GAP_ADV_FP_ANY;
m_adv_params.interval = MSEC_TO_UNITS(100, UNIT_0_625_MS); // approx 8 ms
#if (BLUETOOTH_SD == 140)
m_adv_params.duration = 0; // infinite advertisment
m_adv_params.properties.legacy_pdu = 1;
m_adv_params.primary_phy = BLE_GAP_PHY_1MBPS;
#else
m_adv_params.timeout = 0; // infinite advertisment
#endif
ble_drv_advertise_stop();
#if (BLUETOOTH_SD == 140)
err_code = sd_ble_gap_adv_start(BLE_GAP_ADV_SET_HANDLE_DEFAULT, &m_adv_params, BLE_CONN_CFG_TAG_DEFAULT);
#else
err_code = sd_ble_gap_adv_start(&m_adv_params);
#endif
if (err_code != 0) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
"Can not start advertisment. status: 0x" HEX2_FMT, (uint16_t)err_code));
}
m_adv_in_progress = true;
return true;
}
void ble_drv_advertise_stop(void) {
if (m_adv_in_progress == true) {
uint32_t err_code;
#if (BLUETOOTH_SD == 140)
if ((err_code = sd_ble_gap_adv_stop(BLE_GAP_ADV_SET_HANDLE_DEFAULT)) != 0) {
#else
if ((err_code = sd_ble_gap_adv_stop()) != 0) {
#endif
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
"Can not stop advertisment. status: 0x" HEX2_FMT, (uint16_t)err_code));
}
}
m_adv_in_progress = false;
}
void ble_drv_attr_s_read(uint16_t conn_handle, uint16_t handle, uint16_t len, uint8_t * p_data) {
ble_gatts_value_t gatts_value;
memset(&gatts_value, 0, sizeof(gatts_value));
gatts_value.len = len;
gatts_value.offset = 0;
gatts_value.p_value = p_data;
uint32_t err_code = sd_ble_gatts_value_get(conn_handle,
handle,
&gatts_value);
if (err_code != 0) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
"Can not read attribute value. status: 0x" HEX2_FMT, (uint16_t)err_code));
}
}
void ble_drv_attr_s_write(uint16_t conn_handle, uint16_t handle, uint16_t len, uint8_t * p_data) {
ble_gatts_value_t gatts_value;
memset(&gatts_value, 0, sizeof(gatts_value));
gatts_value.len = len;
gatts_value.offset = 0;
gatts_value.p_value = p_data;
uint32_t err_code = sd_ble_gatts_value_set(conn_handle, handle, &gatts_value);
if (err_code != 0) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
"Can not write attribute value. status: 0x" HEX2_FMT, (uint16_t)err_code));
}
}
void ble_drv_attr_s_notify(uint16_t conn_handle, uint16_t handle, uint16_t len, uint8_t * p_data) {
uint16_t hvx_len = len;
ble_gatts_hvx_params_t hvx_params;
memset(&hvx_params, 0, sizeof(hvx_params));
hvx_params.handle = handle;
hvx_params.type = BLE_GATT_HVX_NOTIFICATION;
hvx_params.offset = 0;
hvx_params.p_len = &hvx_len;
hvx_params.p_data = p_data;
while (m_tx_in_progress) {
;
}
m_tx_in_progress = true;
uint32_t err_code;
if ((err_code = sd_ble_gatts_hvx(conn_handle, &hvx_params)) != 0) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
"Can not notify attribute value. status: 0x" HEX2_FMT, (uint16_t)err_code));
}
}
void ble_drv_gap_event_handler_set(mp_obj_t obj, ble_drv_gap_evt_callback_t evt_handler) {
mp_gap_observer = obj;
gap_event_handler = evt_handler;
}
void ble_drv_gatts_event_handler_set(mp_obj_t obj, ble_drv_gatts_evt_callback_t evt_handler) {
mp_gatts_observer = obj;
gatts_event_handler = evt_handler;
}
#if (BLUETOOTH_SD == 130) || (BLUETOOTH_SD == 132) || (BLUETOOTH_SD == 140)
void ble_drv_gattc_event_handler_set(mp_obj_t obj, ble_drv_gattc_evt_callback_t evt_handler) {
mp_gattc_observer = obj;
gattc_event_handler = evt_handler;
}
void ble_drv_adv_report_handler_set(mp_obj_t obj, ble_drv_adv_evt_callback_t evt_handler) {
mp_adv_observer = obj;
adv_event_handler = evt_handler;
}
void ble_drv_attr_c_read(uint16_t conn_handle, uint16_t handle, mp_obj_t obj, ble_drv_gattc_char_data_callback_t cb) {
mp_gattc_char_data_observer = obj;
gattc_char_data_handle = cb;
uint32_t err_code = sd_ble_gattc_read(conn_handle,
handle,
0);
if (err_code != 0) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
"Can not read attribute value. status: 0x" HEX2_FMT, (uint16_t)err_code));
}
while (gattc_char_data_handle != NULL) {
;
}
}
void ble_drv_attr_c_write(uint16_t conn_handle, uint16_t handle, uint16_t len, uint8_t * p_data, bool w_response) {
ble_gattc_write_params_t write_params;
if (w_response) {
write_params.write_op = BLE_GATT_OP_WRITE_REQ;
} else {
write_params.write_op = BLE_GATT_OP_WRITE_CMD;
}
write_params.flags = BLE_GATT_EXEC_WRITE_FLAG_PREPARED_CANCEL;
write_params.handle = handle;
write_params.offset = 0;
write_params.len = len;
write_params.p_value = p_data;
m_write_done = !w_response;
uint32_t err_code = sd_ble_gattc_write(conn_handle, &write_params);
if (err_code != 0) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
"Can not write attribute value. status: 0x" HEX2_FMT, (uint16_t)err_code));
}
while (m_write_done != true) {
;
}
}
void ble_drv_scan_start(void) {
SD_TEST_OR_ENABLE();
ble_gap_scan_params_t scan_params;
memset(&scan_params, 0, sizeof(ble_gap_scan_params_t));
scan_params.active = 1;
scan_params.interval = MSEC_TO_UNITS(100, UNIT_0_625_MS);
scan_params.window = MSEC_TO_UNITS(100, UNIT_0_625_MS);
#if (BLUETOOTH_SD == 140)
scan_params.filter_policy = BLE_GAP_SCAN_FP_ACCEPT_ALL;
scan_params.filter_duplicates = BLE_GAP_SCAN_DUPLICATES_SUPPRESS;
scan_params.scan_phy = BLE_GAP_PHY_1MBPS;
scan_params.duration = 0; // Infinite
#else
scan_params.timeout = 0; // Infinite
#endif
#if (BLUETOOTH_SD == 130)
scan_params.selective = 0;
scan_params.p_whitelist = NULL;
#elif (BLUETOOTH_SD == 132 && BLE_API_VERSION == 3)
scan_params.use_whitelist = 0;
#endif
uint32_t err_code;
if ((err_code = sd_ble_gap_scan_start(&scan_params)) != 0) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
"Can not start scanning. status: 0x" HEX2_FMT, (uint16_t)err_code));
}
}
void ble_drv_scan_stop(void) {
sd_ble_gap_scan_stop();
}
void ble_drv_connect(uint8_t * p_addr, uint8_t addr_type) {
SD_TEST_OR_ENABLE();
ble_gap_scan_params_t scan_params;
scan_params.active = 1;
scan_params.interval = MSEC_TO_UNITS(100, UNIT_0_625_MS);
scan_params.window = MSEC_TO_UNITS(100, UNIT_0_625_MS);
#if (BLUETOOTH_SD == 140)
scan_params.duration = 0; // Infinite
#else
scan_params.timeout = 0; // Infinite
#endif
#if (BLUETOOTH_SD == 130)
scan_params.selective = 0;
scan_params.p_whitelist = NULL;
#elif (BLUETOOTH_SD == 132 && BLE_API_VERSION == 3)
scan_params.use_whitelist = 0;
#endif
ble_gap_addr_t addr;
memset(&addr, 0, sizeof(addr));
addr.addr_type = addr_type;
memcpy(addr.addr, p_addr, 6);
BLE_DRIVER_LOG("GAP CONNECTING: "HEX2_FMT":"HEX2_FMT":"HEX2_FMT":"HEX2_FMT":"HEX2_FMT":"HEX2_FMT", type: %d\n",
addr.addr[0], addr.addr[1], addr.addr[2], addr.addr[3], addr.addr[4], addr.addr[5], addr.addr_type);
ble_gap_conn_params_t conn_params;
// (void)sd_ble_gap_ppcp_get(&conn_params);
// set connection parameters
memset(&conn_params, 0, sizeof(conn_params));
conn_params.min_conn_interval = BLE_MIN_CONN_INTERVAL;
conn_params.max_conn_interval = BLE_MAX_CONN_INTERVAL;
conn_params.slave_latency = BLE_SLAVE_LATENCY;
conn_params.conn_sup_timeout = BLE_CONN_SUP_TIMEOUT;
uint32_t err_code;
#if (BLUETOOTH_SD == 140)
if ((err_code = sd_ble_gap_connect(&addr, &scan_params, &conn_params, BLE_CONN_CFG_TAG_DEFAULT)) != 0) {
#else
if ((err_code = sd_ble_gap_connect(&addr, &scan_params, &conn_params)) != 0) {
#endif
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
"Can not connect. status: 0x" HEX2_FMT, (uint16_t)err_code));
}
}
bool ble_drv_discover_services(mp_obj_t obj, uint16_t conn_handle, uint16_t start_handle, ble_drv_disc_add_service_callback_t cb) {
BLE_DRIVER_LOG("Discover primary services. Conn handle: 0x" HEX2_FMT "\n",
conn_handle);
mp_gattc_disc_service_observer = obj;
disc_add_service_handler = cb;
m_primary_service_found = false;
uint32_t err_code;
err_code = sd_ble_gattc_primary_services_discover(conn_handle,
start_handle,
NULL);
if (err_code != 0) {
return false;
}
// busy loop until last service has been iterated
while (disc_add_service_handler != NULL) {
;
}
if (m_primary_service_found) {
return true;
} else {
return false;
}
}
bool ble_drv_discover_characteristic(mp_obj_t obj,
uint16_t conn_handle,
uint16_t start_handle,
uint16_t end_handle,
ble_drv_disc_add_char_callback_t cb) {
BLE_DRIVER_LOG("Discover characteristicts. Conn handle: 0x" HEX2_FMT "\n",
conn_handle);
mp_gattc_disc_char_observer = obj;
disc_add_char_handler = cb;
ble_gattc_handle_range_t handle_range;
handle_range.start_handle = start_handle;
handle_range.end_handle = end_handle;
m_characteristic_found = false;
uint32_t err_code;
err_code = sd_ble_gattc_characteristics_discover(conn_handle, &handle_range);
if (err_code != 0) {
return false;
}
// busy loop until last service has been iterated
while (disc_add_char_handler != NULL) {
;
}
if (m_characteristic_found) {
return true;
} else {
return false;
}
}
void ble_drv_discover_descriptors(void) {
}
#endif
static void ble_evt_handler(ble_evt_t * p_ble_evt) {
// S132 event ranges.
// Common 0x01 -> 0x0F
// GAP 0x10 -> 0x2F
// GATTC 0x30 -> 0x4F
// GATTS 0x50 -> 0x6F
// L2CAP 0x70 -> 0x8F
switch (p_ble_evt->header.evt_id) {
case BLE_GAP_EVT_CONNECTED:
BLE_DRIVER_LOG("GAP CONNECT\n");
m_adv_in_progress = false;
gap_event_handler(mp_gap_observer, p_ble_evt->header.evt_id, p_ble_evt->evt.gap_evt.conn_handle, p_ble_evt->header.evt_len - (2 * sizeof(uint16_t)), NULL);
ble_gap_conn_params_t conn_params;
(void)sd_ble_gap_ppcp_get(&conn_params);
(void)sd_ble_gap_conn_param_update(p_ble_evt->evt.gap_evt.conn_handle, &conn_params);
break;
case BLE_GAP_EVT_DISCONNECTED:
BLE_DRIVER_LOG("GAP DISCONNECT\n");
gap_event_handler(mp_gap_observer, p_ble_evt->header.evt_id, p_ble_evt->evt.gap_evt.conn_handle, p_ble_evt->header.evt_len - (2 * sizeof(uint16_t)), NULL);
break;
case BLE_GATTS_EVT_HVC:
gatts_event_handler(mp_gatts_observer, p_ble_evt->header.evt_id, p_ble_evt->evt.gatts_evt.params.hvc.handle, p_ble_evt->header.evt_len - (2 * sizeof(uint16_t)), NULL);
break;
case BLE_GATTS_EVT_WRITE:
BLE_DRIVER_LOG("GATTS write\n");
uint16_t handle = p_ble_evt->evt.gatts_evt.params.write.handle;
uint16_t data_len = p_ble_evt->evt.gatts_evt.params.write.len;
uint8_t * p_data = &p_ble_evt->evt.gatts_evt.params.write.data[0];
gatts_event_handler(mp_gatts_observer, p_ble_evt->header.evt_id, handle, data_len, p_data);
break;
case BLE_GAP_EVT_CONN_PARAM_UPDATE:
BLE_DRIVER_LOG("GAP CONN PARAM UPDATE\n");
break;
case BLE_GATTS_EVT_SYS_ATTR_MISSING:
// No system attributes have been stored.
(void)sd_ble_gatts_sys_attr_set(p_ble_evt->evt.gatts_evt.conn_handle, NULL, 0, 0);
break;
#if (BLUETOOTH_SD == 132 && BLE_API_VERSION == 3) || (BLUETOOTH_SD == 140)
case BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST:
BLE_DRIVER_LOG("GATTS EVT EXCHANGE MTU REQUEST\n");
(void)sd_ble_gatts_exchange_mtu_reply(p_ble_evt->evt.gatts_evt.conn_handle, 23); // MAX MTU size
break;
#endif
#if (BLUETOOTH_SD == 140)
case BLE_GATTS_EVT_HVN_TX_COMPLETE:
#else
case BLE_EVT_TX_COMPLETE:
#endif
BLE_DRIVER_LOG("BLE EVT TX COMPLETE\n");
m_tx_in_progress = false;
break;
case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
BLE_DRIVER_LOG("BLE EVT SEC PARAMS REQUEST\n");
// pairing not supported
(void)sd_ble_gap_sec_params_reply(p_ble_evt->evt.gatts_evt.conn_handle,
BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP,
NULL, NULL);
break;
#if (BLUETOOTH_SD == 130) || (BLUETOOTH_SD == 132) || (BLUETOOTH_SD == 140)
case BLE_GAP_EVT_ADV_REPORT:
BLE_DRIVER_LOG("BLE EVT ADV REPORT\n");
ble_drv_adv_data_t adv_data = {
.p_peer_addr = p_ble_evt->evt.gap_evt.params.adv_report.peer_addr.addr,
.addr_type = p_ble_evt->evt.gap_evt.params.adv_report.peer_addr.addr_type,
#if (BLUETOOTH_SD == 140)
.is_scan_resp = p_ble_evt->evt.gap_evt.params.adv_report.type.scannable,
#else
.is_scan_resp = p_ble_evt->evt.gap_evt.params.adv_report.scan_rsp,
#endif
.rssi = p_ble_evt->evt.gap_evt.params.adv_report.rssi,
.data_len = p_ble_evt->evt.gap_evt.params.adv_report.dlen,
.p_data = p_ble_evt->evt.gap_evt.params.adv_report.data,
#if (BLUETOOTH_SD != 140)
.adv_type = p_ble_evt->evt.gap_evt.params.adv_report.type
#endif
};
// TODO: Fix unsafe callback to possible undefined callback...
adv_event_handler(mp_adv_observer,
p_ble_evt->header.evt_id,
&adv_data);
break;
case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST:
BLE_DRIVER_LOG("BLE EVT CONN PARAM UPDATE REQUEST\n");
(void)sd_ble_gap_conn_param_update(p_ble_evt->evt.gap_evt.conn_handle,
&p_ble_evt->evt.gap_evt.params.conn_param_update_request.conn_params);
break;
case BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP:
BLE_DRIVER_LOG("BLE EVT PRIMARY SERVICE DISCOVERY RESPONSE\n");
BLE_DRIVER_LOG(">>> service count: %d\n", p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp.count);
for (uint16_t i = 0; i < p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp.count; i++) {
ble_gattc_service_t * p_service = &p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp.services[i];
ble_drv_service_data_t service;
service.uuid_type = p_service->uuid.type;
service.uuid = p_service->uuid.uuid;
service.start_handle = p_service->handle_range.start_handle;
service.end_handle = p_service->handle_range.end_handle;
disc_add_service_handler(mp_gattc_disc_service_observer, &service);
}
if (p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp.count > 0) {
m_primary_service_found = true;
}
// mark end of service discovery
disc_add_service_handler = NULL;
break;
case BLE_GATTC_EVT_CHAR_DISC_RSP:
BLE_DRIVER_LOG("BLE EVT CHAR DISCOVERY RESPONSE\n");
BLE_DRIVER_LOG(">>> characteristic count: %d\n", p_ble_evt->evt.gattc_evt.params.char_disc_rsp.count);
for (uint16_t i = 0; i < p_ble_evt->evt.gattc_evt.params.char_disc_rsp.count; i++) {
ble_gattc_char_t * p_char = &p_ble_evt->evt.gattc_evt.params.char_disc_rsp.chars[i];
ble_drv_char_data_t char_data;
char_data.uuid_type = p_char->uuid.type;
char_data.uuid = p_char->uuid.uuid;
char_data.decl_handle = p_char->handle_decl;
char_data.value_handle = p_char->handle_value;
char_data.props |= (p_char->char_props.broadcast) ? UBLUEPY_PROP_BROADCAST : 0;
char_data.props |= (p_char->char_props.read) ? UBLUEPY_PROP_READ : 0;
char_data.props |= (p_char->char_props.write_wo_resp) ? UBLUEPY_PROP_WRITE_WO_RESP : 0;
char_data.props |= (p_char->char_props.write) ? UBLUEPY_PROP_WRITE : 0;
char_data.props |= (p_char->char_props.notify) ? UBLUEPY_PROP_NOTIFY : 0;
char_data.props |= (p_char->char_props.indicate) ? UBLUEPY_PROP_INDICATE : 0;
#if 0
char_data.props |= (p_char->char_props.auth_signed_wr) ? UBLUEPY_PROP_NOTIFY : 0;
#endif
disc_add_char_handler(mp_gattc_disc_char_observer, &char_data);
}
if (p_ble_evt->evt.gattc_evt.params.char_disc_rsp.count > 0) {
m_characteristic_found = true;
}
// mark end of characteristic discovery
disc_add_char_handler = NULL;
break;
case BLE_GATTC_EVT_READ_RSP:
BLE_DRIVER_LOG("BLE EVT READ RESPONSE, offset: 0x"HEX2_FMT", length: 0x"HEX2_FMT"\n",
p_ble_evt->evt.gattc_evt.params.read_rsp.offset,
p_ble_evt->evt.gattc_evt.params.read_rsp.len);
gattc_char_data_handle(mp_gattc_char_data_observer,
p_ble_evt->evt.gattc_evt.params.read_rsp.len,
p_ble_evt->evt.gattc_evt.params.read_rsp.data);
// mark end of read
gattc_char_data_handle = NULL;
break;
case BLE_GATTC_EVT_WRITE_RSP:
BLE_DRIVER_LOG("BLE EVT WRITE RESPONSE\n");
m_write_done = true;
break;
case BLE_GATTC_EVT_HVX:
BLE_DRIVER_LOG("BLE EVT HVX RESPONSE\n");
break;
#endif
default:
BLE_DRIVER_LOG(">>> unhandled evt: 0x" HEX2_FMT "\n", p_ble_evt->header.evt_id);
break;
}
}
#if (BLUETOOTH_SD == 140)
static uint8_t m_ble_evt_buf[sizeof(ble_evt_t) + (BLE_GATT_ATT_MTU_DEFAULT)] __attribute__ ((aligned (4)));
#else
static uint8_t m_ble_evt_buf[sizeof(ble_evt_t) + (GATT_MTU_SIZE_DEFAULT)] __attribute__ ((aligned (4)));
#endif
#ifdef NRF51
void SWI2_IRQHandler(void) {
#else
void SWI2_EGU2_IRQHandler(void) {
#endif
uint32_t evt_id;
uint32_t err_code;
do {
err_code = sd_evt_get(&evt_id);
// TODO: handle non ble events
} while (err_code != NRF_ERROR_NOT_FOUND && err_code != NRF_SUCCESS);
uint16_t evt_len = sizeof(m_ble_evt_buf);
do {
err_code = sd_ble_evt_get(m_ble_evt_buf, &evt_len);
ble_evt_handler((ble_evt_t *)m_ble_evt_buf);
} while (err_code != NRF_ERROR_NOT_FOUND && err_code != NRF_SUCCESS);
}
#endif // BLUETOOTH_SD
|
the_stack_data/31434.c | #include <stdio.h>
int main()
{
// declaration
int a, b, c, largest;
// user input
printf("Enter 1st number: ");
scanf("%d", &a);
printf("Enter 2nd number: ");
scanf("%d", &b);
printf("Enter 3rd number: ");
scanf("%d", &c);
largest = a > b ? (a > c ? a : c) : (b > c ? b : c);
// output
printf("The largest number is : %d", largest);
return 0;
}
|
the_stack_data/16372.c | #include <stdio.h>
int cycle (int n) {
int length = 0;
while (n != 1) {
if ( n%2 == 1 ){
n = n*3 + 1;
length ++;
} else {
n /= 2;
length ++;
}
}
return length+1;
}
int main() {
int i,j,oi,oj;
int k;
int temp;
int now,max;
while (scanf("%d %d",&i,&j) != EOF) {
max = 0;
oi = i; oj = j;
if (i>j) {
temp = i;
i = j;
j = temp;
}
for (k=i;k<=j;k++) {
now = cycle(k);
if (now>max) {
max = now;
}
}
printf("%d %d %d\n",oi,oj,max);
}
return 0;
}
|
the_stack_data/139185.c | //*****************************************************************************
//
// uart_handler.c
//
// Copyright (c) 2006-2012 Texas Instruments Incorporated. All rights reserved.
// Software License Agreement
//
// Texas Instruments (TI) is supplying this software for use solely and
// exclusively on TI's microcontroller products. The software is owned by
// TI and/or its suppliers, and is protected under applicable copyright
// laws. You may not combine this software with "viral" open-source
// software in order to form a larger program.
//
// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
// DAMAGES, FOR ANY REASON WHATSOEVER.
//
// This is part of revision 9453 of the Stellaris Firmware Development Package.
//
//*****************************************************************************
#ifdef __WIN32
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
#include <windows.h>
#else
#include <fcntl.h>
#include <termios.h>
#include <unistd.h>
#endif
//*****************************************************************************
//
//! \addtogroup uart_handler UART Handler API
//! This section describes the functions that are responsible for handling the
//! transfer of data over the UART port. These functions use Microsoft Windows
//! APIs to communicate with the UART.
//! @{
//
//*****************************************************************************
//*****************************************************************************
//
//! This variable holds the open handle to the UART in use by this
//! application.
//
//*****************************************************************************
#ifdef __WIN32
static HANDLE g_hComPort;
#else
static int g_iComPort = -1;
#endif
//*****************************************************************************
//
//! OpenUART() opens the UART port.
//!
//! \param pszComPort is the text representation of the COM port to be
//! opened. "COM1" is the valid string to use to open COM port 1 on the
//! host.
//! \param ulBaudRate is the baud rate to configure the UART to use.
//!
//! This function is used to open the host UART with the given baud rate. The
//! rest of the settings are fixed at No Parity, 8 data bits and 1 stop bit.
//!
//! \return The function returns zero to indicated success while any non-zero
//! value indicates a failure.
//
//*****************************************************************************
int
OpenUART(char *pszComPort, unsigned long ulBaudRate)
{
#ifdef __WIN32
DCB sDCB;
COMMTIMEOUTS sCommTimeouts;
g_hComPort = CreateFile(pszComPort, GENERIC_READ | GENERIC_WRITE, 0, NULL,
OPEN_EXISTING, 0, NULL);
if(g_hComPort == INVALID_HANDLE_VALUE)
{
return(-1);
}
if(GetCommState(g_hComPort, &sDCB) == 0)
{
return(-1);
}
sDCB.BaudRate = ulBaudRate;
sDCB.ByteSize = 8;
sDCB.Parity = NOPARITY;
sDCB.StopBits = ONESTOPBIT;
sDCB.fAbortOnError = TRUE;
sDCB.fOutxCtsFlow = FALSE;
sDCB.fOutxDsrFlow = FALSE;
sDCB.fDtrControl = DTR_CONTROL_ENABLE;
if(SetCommState(g_hComPort, &sDCB) == 0)
{
return(-1);
}
if(GetCommTimeouts(g_hComPort, &sCommTimeouts) == 0)
{
return(-1);
}
sCommTimeouts.ReadIntervalTimeout = 8000;
sCommTimeouts.ReadTotalTimeoutConstant = 8000;
sCommTimeouts.ReadTotalTimeoutMultiplier = 8000;
sCommTimeouts.WriteTotalTimeoutConstant = 8000;
sCommTimeouts.WriteTotalTimeoutMultiplier = 8000;
if(SetCommTimeouts(g_hComPort, &sCommTimeouts) == 0)
{
return(-1);
}
return(0);
#else
struct termios sOptions;
g_iComPort = open(pszComPort, O_RDWR | O_NOCTTY | O_NDELAY);
if(g_iComPort == -1)
{
return(-1);
}
fcntl(g_iComPort, F_SETFL, 0);
tcgetattr(g_iComPort, &sOptions);
if(ulBaudRate == 9600)
{
cfsetispeed(&sOptions, B9600);
cfsetospeed(&sOptions, B9600);
}
else if(ulBaudRate == 19200)
{
cfsetispeed(&sOptions, B19200);
cfsetospeed(&sOptions, B19200);
}
else if(ulBaudRate == 38400)
{
cfsetispeed(&sOptions, B38400);
cfsetospeed(&sOptions, B38400);
}
else if(ulBaudRate == 57600)
{
cfsetispeed(&sOptions, B57600);
cfsetospeed(&sOptions, B57600);
}
else if(ulBaudRate == 115200)
{
cfsetispeed(&sOptions, B115200);
cfsetospeed(&sOptions, B115200);
}
else
{
cfsetispeed(&sOptions, B230400);
cfsetospeed(&sOptions, B230400);
}
sOptions.c_cflag |= (CLOCAL | CREAD);
sOptions.c_cflag &= ~(CSIZE);
sOptions.c_cflag |= CS8;
sOptions.c_cflag &= ~(PARENB);
sOptions.c_cflag &= ~(CSTOPB);
sOptions.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
sOptions.c_oflag &= ~(OPOST);
tcsetattr(g_iComPort, TCSANOW, &sOptions);
return(0);
#endif
}
//*****************************************************************************
//
//! CloseUART() closes the UART port.
//!
//! This function closes the UART port that was opened by a call to OpenUART().
//!
//! \returns This function returns zero to indicate success while any non-zero
//! value indicates a failure.
//
//*****************************************************************************
int
CloseUART(void)
{
#ifdef __WIN32
return(CloseHandle(g_hComPort));
#else
if(g_iComPort != -1)
{
close(g_iComPort);
}
return(0);
#endif
}
//*****************************************************************************
//
//! UARTSendData() sends data over a UART port.
//!
//! \param pucData
//! The buffer to write out to the UART port.
//! \param ucSize
//! The number of bytes provided in pucData buffer that should be written
//! out to the port.
//!
//! This function sends ucSize bytes of data from the buffer pointed to by
//! pucData via the UART port that was opened by a call to OpenUART().
//!
//! \return This function returns zero to indicate success while any non-zero
//! value indicates a failure.
//
//*****************************************************************************
int
UARTSendData(unsigned char const *pucData, unsigned char ucSize)
{
#ifdef __WIN32
unsigned long ulNumBytes;
//
// Send the Ack back to the device.
//
if(WriteFile(g_hComPort, pucData, ucSize, &ulNumBytes, NULL) == 0)
{
return(-1);
}
if(ulNumBytes != ucSize)
{
return(-1);
}
return(0);
#else
if(write(g_iComPort, pucData, ucSize) != ucSize)
{
return(-1);
}
return(0);
#endif
}
//*****************************************************************************
//
//! UARTReceiveData() receives data over a UART port.
//!
//! \param pucData is the buffer to read data into from the UART port.
//! \param ucSize is the number of bytes provided in pucData buffer that should
//! be written with data from the UART port.
//!
//! This function reads back ucSize bytes of data from the UART port, that was
//! opened by a call to OpenUART(), into the buffer that is pointed to by
//! pucData.
//!
//! \return This function returns zero to indicate success while any non-zero
//! value indicates a failure.
//
//*****************************************************************************
int
UARTReceiveData(unsigned char *pucData, unsigned char ucSize)
{
#ifdef __WIN32
unsigned long ulNumBytes;
if(ReadFile(g_hComPort, pucData, ucSize, &ulNumBytes, NULL) == 0)
{
return(-1);
}
if(ulNumBytes != ucSize)
{
return(-1);
}
return(0);
#else
if(read(g_iComPort, pucData, ucSize) != ucSize)
{
return(-1);
}
return(0);
#endif
}
//*****************************************************************************
//
// Close the Doxygen group.
//! @}
//
//*****************************************************************************
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.