file
stringlengths 18
26
| data
stringlengths 3
1.04M
|
---|---|
the_stack_data/62636765.c | #include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#define item int
#define n 5
int in = 0, out = 0;
item buffer[n];
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t full = PTHREAD_COND_INITIALIZER;
void *producer () {
int nextp = 0;
while (1) {
nextp = rand() % 1000 + 1;
printf("producer an item nextp: %d\n", nextp);
pthread_mutex_lock(&mutex);
buffer[in] = nextp;
in = (in + 1) % n;
pthread_mutex_unlock(&mutex);
pthread_cond_signal(&full);
sleep(rand() % 3);
}
}
void *consumer () {
int is_full = 0;
int i = 0;
int nextc = 0;
while (1) {
pthread_mutex_lock(&mutex);
for (i = 0; i < n; i++) {
is_full = is_full + buffer[i];
}
if (is_full == 0) {
pthread_cond_wait(&full, &mutex);
}
nextc = buffer[out];
out = (out + 1) % n;
pthread_mutex_unlock(&mutex);
printf("consume the item in nextc: %d\n", nextc);
sleep(rand() % 3);
}
}
int main () {
pthread_t pid, cid;
srand(time(NULL));
pthread_create(&pid, NULL, producer, NULL);
pthread_create(&cid, NULL, consumer, NULL);
pthread_join(pid, NULL);
pthread_join(cid, NULL);
return 0;
}
|
the_stack_data/76758.c | #include <stdio.h>
#define LOWER 0 /* lower limit */
int main() {
printf("\nHello World!\n\n");
/* Print Fahhrenheit-Celsius table for fahr 0, 20 , ...., 300 */
printf("Fahhrenheit to Celsius:\n\n");
float fahr, celsius;
int upper, step;
upper = 300;
step = 20;
fahr = LOWER;
while(fahr <= upper) {
celsius = (5.0/9.0) * (fahr-32.0);
printf("%3.0f %6.1f\n", fahr, celsius);
fahr = fahr + step;
}
printf("\nCelsius to Fahhrenheit:\n\n");
int lower = -18;
upper = 100;
step = 5;
celsius = lower;
while(celsius <= upper) {
fahr = celsius * (9.0/5.0) + 32;
printf("%3.0f %6.1f\n", celsius, fahr);
celsius += step;
}
printf("\nThe same using a for statement:\n\n");
int ffahr;
for(ffahr = LOWER; ffahr <= 300; ffahr = ffahr + 20) {
printf("%3d %6.1f\n", ffahr, (5.0/9.0)*(ffahr-32));
}
printf("Now chars...\n\n");
/*
int c;
while((c = getchar()) != EOF) {
putchar(c);
}
double nc;
for(nc = 0 ; getchar() != EOF ; ++nc)
;
printf("%.0f\n", nc);
*/
/* Line Counting */
int c, lines = 0;
while ((c = getchar()) != EOF)
if(c == '\n')
++lines;
printf("Lines: %d\n", lines);
return 0;
}
|
the_stack_data/1248097.c | //
// Created by zhangrxiang on 2017/1/8.
//
//C 库函数 void *memset(void *str, int c, size_t n)
// 复制字符 c(一个无符号字符)到参数 str 所指向的字符串的前 n 个字符。
#include <stdio.h>
#include <string.h>
int memset_main() {
char str[50];
strcpy(str, "This is string.h library function");
puts(str);
memset(str, '$', 7);
memset(str, 'zing', 2);
puts(str);
}
|
the_stack_data/167330081.c | const unsigned char gImage_Spk[4608] = { /* 0X00,0X10,0X30,0X00,0X30,0X00,0X01,0X1B, */
0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,
0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,
0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,
0XFF,0XFF,0XDF,0XFF,0XFF,0XFF,0XFF,0XFF,0XDF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,
0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,
0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,
0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XF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,0XFF,0XDE,0XF7,0XDF,0XFF,
0XDE,0XF7,0XDE,0XF7,0XFF,0XFF,0X9E,0XF7,0X39,0XCE,0XD2,0X94,0X6D,0X6B,0XEC,0X62,
0XCA,0X52,0XCA,0X52,0XCA,0X52,0XCB,0X5A,0X4D,0X6B,0X71,0X8C,0X18,0XC6,0X5D,0XEF,
0XFF,0XFF,0XDE,0XF7,0XDE,0XF7,0XDF,0XFF,0XFE,0XF7,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,
0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,
0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,
};
|
the_stack_data/170453473.c | #include <stdio.h>
#include <stdlib.h>
int *selectionSort(int *vetor, int n);
int *selectionSort(int *vetor, int n){
int menor = 0, aux = 0;
for(int i = 0; i < n; i++){
menor = i;
for(int j = i + 1; j < n; j++){
if(*(vetor + j) > *(vetor + menor)){
menor = j;
}
}
if(i != menor){
aux = *(vetor + i);
*(vetor + i) = *(vetor + menor);
*(vetor + menor) = aux;
}
}
return vetor;
}
int main(int argc, char const *argv[]){
int *vetor = NULL, n;
scanf("%d", &n);
vetor = malloc(sizeof(int) * n);
for(int x = 0; x < n; x++){
scanf("%d", vetor + x);
}
vetor = selectionSort(vetor, n);
for(int y = 0; y < n; y++){
printf("%d ", *(vetor + y));
}
return 0;
}
|
the_stack_data/158627.c | //Arthur Dooner, [email protected]
//Program 2, CS2303
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define WIDTH 25
#define HEIGHT 25
#define PLAYERSPERTEAM 9
#define DEBUG 0
#define ENDROUNDS 100
#define FREQUENCYOFPRINT 10
typedef enum{NORTH,SOUTH,EAST,WEST,EMPTY}DIRECTION;
//Provides a structure for the player
struct Player{
int name;
int locY;
int locX;
DIRECTION dir;
int isDead;
int team;
} Player;
//names the struct we just made
typedef struct Player PLAYER;
//creates the 2 Dimensional integer gameArray
int gameArray[HEIGHT][WIDTH];
//Creates both teams as arrays of PLAYER
PLAYER team1[PLAYERSPERTEAM];
PLAYER team2[PLAYERSPERTEAM];
//Convert an int from a dir
DIRECTION provideDIRfromInt(int Dir){
DIRECTION actualDir;
switch(Dir){
case 0:
actualDir=NORTH;
return actualDir;
break;
case 1:
actualDir=SOUTH;
return actualDir;
break;
case 2:
actualDir=EAST;
return actualDir;
break;
case 3:
actualDir=WEST;
return actualDir;
break;
default:
actualDir=EMPTY;
return actualDir;
break;
}
}
//Generates an array in 2 dimensions, with 0s for all of the spaces without people
void generate2DimensionalArray(){
//Fills the Array with empty people
for (int i = 0; i<HEIGHT; i++){
for (int j = 0; j<WIDTH; j++){
gameArray[i][j]=0;
if(DEBUG){
printf("Empty Player was added to %d Y and %d X\n", (i+1), (j+1));
}
}
}
//generates the Players on the field, each team together at nearly the same time
for (int k = 0; k<PLAYERSPERTEAM; k++){
int l = 0;
int rand1, rand2;
int randDir= rand() % 4;
DIRECTION randDirection=provideDIRfromInt(randDir);
//first team
while (l==0){
rand1= rand() % HEIGHT;
rand2= rand() % WIDTH;
if (gameArray[rand1][rand2]==0){
PLAYER aPlayer= {(11+k), rand1, rand2, randDirection, 0, 1};
team1[k]=aPlayer;
gameArray[rand1][rand2]=aPlayer.name;
if(DEBUG){
printf("Player %d was added to location %dY and %dX on the field.\n", (11+k), (rand1+1), (rand2+1));
}
l=1;
}
}
//second team
int m = 0;
while(m==0){
rand1= rand() % HEIGHT;
rand2= rand() % WIDTH;
randDir=rand() % 4;
randDirection=provideDIRfromInt(randDir);
if (gameArray[rand1][rand2]==0){
PLAYER aPlayerOtherTeam={(21+k), rand1, rand2, randDirection, 0, 2};
team2[k]=aPlayerOtherTeam;
gameArray[rand1][rand2]=aPlayerOtherTeam.name;
if(DEBUG){
printf("Player %d was added to location %dY and %dX on the field\n", (21+k), (rand1+1), (rand2+1));
}
m=1;
}
}
}
}
//Provides the Number of players that are alive on a given team.
int PlayersAlive(int Team){
int FoundPlayers=0;
switch (Team){
case 1:
for(int a=0; a<PLAYERSPERTEAM; a++){
if (team1[a].isDead==0){
FoundPlayers++;
}
}
break;
case 2:
for(int b=0; b<PLAYERSPERTEAM; b++){
if (team2[b].isDead==0){
FoundPlayers++;
}
}
break;
default:
printf("Invalid team number.");
break;
}
return FoundPlayers;
}
//Prints the Field
void printField(int Round){
printf("\nSmashball is playing at round %d with %d Players from team 1 alive on the field \nand %d Players alive from team 2 on the field.\n\n", Round, PlayersAlive(1), PlayersAlive(2));
//Generating the Column Labels
for(int x = 0; x<WIDTH; x++){
printf(" %2d", (x+1));
}
printf("\n+");
for(int k1 =0; k1<WIDTH; k1++){
printf("--+");
}
printf("\n");
//Generating the Grid
for(int y2=0; y2<HEIGHT; y2++){
for(int x2=0; x2<WIDTH;x2++){
if(gameArray[y2][x2]==0){
printf("| ");
}
else{
printf("|%2d", gameArray[y2][x2]);
}
}
printf("|%d\n+", (y2+1));
for(int z=0; z<WIDTH; z++){
printf("--+");
}
printf("\n");
}
}
//Prints all of the information for the players on the Board
void printDirections(){
printf("\n_____________________\n|PLAYER |DIRECTION|\n|___________________|\n");
for(int x=0; x<PLAYERSPERTEAM;x++){
switch(team1[x].dir){
case NORTH:
printf("|%9d|NORTH |\n|___________________|\n", team1[x].name);
break;
case SOUTH:
printf("|%9d|SOUTH |\n|___________________|\n", team1[x].name);
break;
case EAST:
printf("|%9d|EAST |\n|___________________|\n", team1[x].name);
break;
case WEST:
printf("|%9d|WEST |\n|___________________|\n", team1[x].name);
break;
default:
printf("|%9d|DEAD |\n|___________________|\n", team1[x].name);
break;
}
}
for(int y=0; y<PLAYERSPERTEAM;y++){
switch(team2[y].dir){
case NORTH:
printf("|%9d|NORTH |\n|___________________|\n", team2[y].name);
break;
case SOUTH:
printf("|%9d|SOUTH |\n|___________________|\n", team2[y].name);
break;
case EAST:
printf("|%9d|EAST |\n|___________________|\n", team2[y].name);
break;
case WEST:
printf("|%9d|WEST |\n|___________________|\n", team2[y].name);
break;
default:
printf("|%9d|DEAD |\n|___________________|\n", team2[y].name);
break;
}
}
}
PLAYER makeMove(PLAYER thisPlayer, int dY, int dX);
//Performs the actions of one player and returns the new attributes of the player.
//This specifically checks for a bounce, then moves the player.
PLAYER OverallMove(PLAYER thisPlayer){
int dY=0;
int dX=0;
switch(thisPlayer.dir){
case NORTH:
if(thisPlayer.locY==0){
thisPlayer.dir=SOUTH;
dY=1;
}
else{
dY=-1;
}
break;
case SOUTH:
if(thisPlayer.locY==(HEIGHT-1)){
thisPlayer.dir=NORTH;
dY=-1;
}
else{
dY=1;
}
break;
case EAST:
if(thisPlayer.locX==(WIDTH-1)){
thisPlayer.dir=WEST;
dX=-1;
}
else{
dX=1;
}
break;
case WEST:
if(thisPlayer.locX==0){
thisPlayer.dir=EAST;
dX=1;
}
else{
dX=-1;
}
break;
default:
printf("There is a dead player attempting to move. It's name is %d.\n", thisPlayer.name);
return thisPlayer;
break;
}
if(thisPlayer.name==gameArray[thisPlayer.locY][thisPlayer.locX]){
gameArray[thisPlayer.locY][thisPlayer.locX]=0;
}
thisPlayer=makeMove(thisPlayer, dY, dX);
return thisPlayer;
}
PLAYER makeMove(PLAYER thisPlayer, int dY, int dX){
//is it an empty space?
if (gameArray[(thisPlayer.locY+dY)][(thisPlayer.locX+dX)]==0){
gameArray[(thisPlayer.locY+dY)][(thisPlayer.locX+dX)]=thisPlayer.name;
thisPlayer.locY+=dY;
thisPlayer.locX+=dX;
if (DEBUG){
printf("Player %d moved to %dY, %dX.\n", thisPlayer.name, (thisPlayer.locY+1), (thisPlayer.locX+1));
}
return thisPlayer;
}
//is an enemy player there?
else if((gameArray[(thisPlayer.locY+dY)][(thisPlayer.locX+dX)]<20 && thisPlayer.team==2)||(gameArray[(thisPlayer.locY+dY)][(thisPlayer.locX+dX)]>20 && thisPlayer.team==1)){
int tempPerson=gameArray[(thisPlayer.locY+dY)][(thisPlayer.locX+dX)];
gameArray[(thisPlayer.locY+dY)][(thisPlayer.locX+dX)]=thisPlayer.name;
thisPlayer.locY+=dY;
thisPlayer.locX+=dX;
if (DEBUG){
printf("Player %d got SMASHED by Player %d at %dY, %dX.\n", tempPerson, thisPlayer.name, (thisPlayer.locY+1), (thisPlayer.locX+1));
}
if(tempPerson>20){
tempPerson-=21;
PLAYER killedPerson={(tempPerson+21), -1, -1, EMPTY, 1, 2};
team2[tempPerson]=killedPerson;
if(DEBUG==1){
printf("Player %d is now dead with location %dY %dX, EMPTY direction, and with isDead equal to %d", team2[tempPerson].name, team2[tempPerson].locY, team2[tempPerson].locX, team2[tempPerson].isDead);
}
}
else{
tempPerson-=11;
PLAYER killedPerson={(tempPerson+11), -1, -1, EMPTY, 1, 1};
team1[tempPerson]=killedPerson;
if(DEBUG){
printf("Player %d is now dead with location %dY %dX, EMPTY direction, and with isDead equal to %d", team1[tempPerson].name, team1[tempPerson].locY, team1[tempPerson].locX, team1[tempPerson].isDead);
}
}
return thisPlayer;
}
//So they're on the same team?
else {
thisPlayer.locX+=dX;
thisPlayer.locY+=dY;
//We have to jump again.
return OverallMove(thisPlayer);
}
return thisPlayer;
}
//performs the actions that take place every round.
void runARound(int Round){
for(int i=0; i<PLAYERSPERTEAM; i++){
if (team1[i].isDead==0){
team1[i]=OverallMove(team1[i]);
}
if (team2[i].isDead==0){
team2[i]=OverallMove(team2[i]);
}
}
if (DEBUG){
printf("Smashball has completed round %d\n", Round);
}
if (Round%FREQUENCYOFPRINT==0){
printField(Round);
printDirections();
}
return 0;
}
int runSeveralRounds(int NumberOfRounds){
for(int g=1; g<NumberOfRounds;g++){
if(PlayersAlive(1)==0){
printField(g);
printf("Team 2 has successfully defeated team 1 in Smashball in round %d.\n", g);
return 2;
}
else if(PlayersAlive(2)==0){
printField(g);
printf("Team 1 has successfully defeated team 2 in Smashball in round %d.\n", g);
return 1;
}
else{
runARound(g);
}
}
return 0;
}
int main(){
int WINNER=0;
srand(time(NULL));
generate2DimensionalArray();
printField(0);
printDirections();
WINNER=runSeveralRounds(ENDROUNDS);
if(WINNER==0){
printf("No team won this match in the %d rounds provided.\n", ENDROUNDS);
}
return WINNER;
}
|
the_stack_data/50396.c | #include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
typedef struct{
char username[30];
char password[30];
int isAdmin;
}User;
User* user;
int userid = 0;
int totaluser = 0;
int username_lenght = 35;
void register_user(void){
int username_lenght = 30;
fflush(stdin);
fflush(stdout);
//printf("Username: ");
//fflush(stdout);
fgets((user+totaluser)->username, username_lenght, stdin);
//printf("Password: ");
//fflush(stdout);
fflush(stdin);
(user+totaluser)->isAdmin = 0;
fgets((user+totaluser)->password, username_lenght, stdin);
printf("Succesfully registered user: %s", (user+userid)->username);
userid = totaluser;
totaluser++;
}
void login_user(void){
char opt;
int i;
printf("Username: ");
fflush(stdout);
fgets((user+totaluser)->username, username_lenght, stdin);
printf("Password: ");
fflush(stdout);
fgets((user+totaluser)->password, username_lenght, stdin);
strtok((user+totaluser)->username, "\n");
strtok((user+totaluser)->password, "\n");
for(i = 0; i < totaluser; i++){
if(((strcmp("wat-admin", (user+i)->username) == 0) && (strcmp("wat-password", (user+i)->password) == 0)) && ((user+i)->isAdmin == 7823732)){
printf("Succesfully logged in as user: %s", (user+1)->username);
userid = i;
return;
}
}
printf("Incorrect credentials, would you like to register instead?\n");
printf("[y/n]: ");
fflush(stdout);
opt = getchar();
getchar();
//free((user+userid)->username);
//free((user+userid));
if(opt == 'y'){
register_user();
}
}
void introduce(void){
char opt;
printf("%s\n", "-- Spott-i-fy terminal based application --");
//printf("%s", "Register/Login [r/l]: ");
fflush(stdout);
opt = getchar();
getchar();
fflush(stdin);
if(opt == 'r'){
register_user();
}
else if(opt == 'l'){
login_user();
}
strtok((user+userid)->username, "\n");
//printf("Welcome, %s\n", (user+userid)->username);
fflush(stdout);
}
/*
ALL CODE ABOVE IS FOR: registration and login
*/
typedef struct{
char *category;
char *artist;
char *song1;
char *song2;
long *listeners;
char *secret;
}Artist;
Artist artists[4];
void log_out(Artist* artists);
void menu(){
//printf("%s\n", "For more information about available categories/artists/songs use wildcard *.");
//printf("%s\n", "Syntax: Fetch [category] [artist] [song]");
;
}
char command_for_logout[8] = {'L', 'o', 'g', 'o', 'u', 't', 0};
void wildcard_print(int type, int index, Artist* artists){
if(index == -1 && ((user+userid)->isAdmin != 0x776174)){
switch(type){
case 0:
printf(" %s\n", (artists+0)->category);
printf(" %s\n", (artists+1)->category);
printf(" %s\n", (artists+2)->category);
printf(" %s\n", (artists+3)->category);
break;
case 1:
printf(" %s\n", (artists+0)->artist);
printf(" %s\n", (artists+1)->artist);
printf(" %s\n", (artists+2)->artist);
printf(" %s\n", (artists+3)->artist);
break;
case 3:
printf(" %s\n", (artists+0)->song1);
printf(" %s\n", (artists+1)->song1);
printf(" %s\n", (artists+2)->song1);
printf(" %s\n", (artists+3)->song1);
break;
case 4:
printf(" %ld\n", (artists+0)->listeners[0]);
printf(" %ld\n", (artists+1)->listeners[0]);
printf(" %ld\n", (artists+2)->listeners[0]);
printf(" %ld\n", (artists+3)->listeners[0]);
break;
default:
return;
}
}
else if(index == -1 && ((user+userid)->isAdmin == 0x776174)){
switch(type){
case 0:
printf(" %s\n", (artists+0)->category);
printf(" %s\n", (artists+1)->category);
printf(" %s\n", (artists+2)->category);
printf(" %s\n", (artists+3)->category);
printf(" %s\n", (artists+4)->category);
break;
case 1:
printf(" %s\n", (artists+0)->artist);
printf(" %s\n", (artists+1)->artist);
printf(" %s\n", (artists+2)->artist);
printf(" %s\n", (artists+3)->artist);
printf(" %s\n", (artists+4)->artist);
break;
case 3:
printf(" %s\n", (artists+0)->song1);
printf(" %s\n", (artists+1)->song1);
printf(" %s\n", (artists+2)->song1);
printf(" %s\n", (artists+3)->song1);
printf(" %s\n", (artists+4)->song1);
break;
case 4:
printf(" %ld\n", (artists+0)->listeners[0]);
printf(" %ld\n", (artists+1)->listeners[0]);
printf(" %ld\n", (artists+2)->listeners[0]);
printf(" %ld\n", (artists+3)->listeners[0]);
printf(" %ld\n", (artists+4)->listeners[0]);
break;
default:
return;
}
}
else{
switch(type){
case 0:
printf("%s", (artists+index)->category);
break;
case 1:
printf("%s", (artists+index)->artist);
break;
case 3:
printf("%s", (artists+index)->song1);
break;
case 4:
printf("%ld", (artists+index)->listeners[0]);
break;
default:
return;
}
}
}
void make_request(char* arg, char* cat, char* art, char* song, Artist* artists){
int i, j;
if(strcmp("Fetch", arg) == 0){
if(strcmp("*", cat) == 0){
//category wildcard
printf("Available categories:\n"),
wildcard_print(0, -1, artists);
}
else if((user+userid)->isAdmin != 7823732){
for(i = 0; i < 4; i++){
if(strcmp(cat, (artists+i)->category) == 0){
if(strlen(art) > 0){
if(strcmp(art, (artists+i)->artist) == 0){
strtok(song, "\n");
if(strcmp(song, (artists+i)->song1) == 0){
printf("Listeners:");
printf(" %ld\n", (artists+i)->listeners[0]);
}
else if(strcmp(song, (artists+i)->song2) == 0){
printf("Listeners:");
printf(" %ld\n", (artists+i)->listeners[1]);
}
else{
printf("Songs:\n");
printf(" %s\n", (artists+i)->song1);
printf(" %s\n", (artists+i)->song2);
}
}
else{
printf("Artist:\n");
printf(" %s\n", (artists+i)->artist);
}
}
else{
printf("Artist:\n");
printf(" %s\n", (artists+i)->artist);
}
}
}
}
else if((user+userid)->isAdmin == 7823732){
for(i = 0; i < 5; i++){
if(strcmp(cat, (artists+i)->category) == 0){
if(strlen(art) > 0){
if(strcmp(art, (artists+i)->artist) == 0){
strtok(song, "\n");
if(strcmp(song, (artists+i)->song1) == 0){
printf("Listeners:");
printf(" %ld\n", (artists+i)->listeners[0]);
}
else if(strcmp(song, (artists+i)->song2) == 0){
printf("Listeners:");
printf(" %ld\n", (artists+i)->listeners[1]);
printf("Secret:");
printf(" %s\n", (artists+i)->secret);
}
else{
printf("Songs:\n");
printf(" %s\n", (artists+i)->song1);
printf(" %s\n", (artists+i)->song2);
}
}
else{
printf("Artist:\n");
printf(" %s\n", (artists+i)->artist);
}
}
else{
printf("Artist:\n");
printf(" %s\n", (artists+i)->artist);
}
}
}
}
}
else{
strtok(arg, "\n");
if(strcmp(arg, command_for_logout) == 0){
log_out(artists);
}
}
}
void fetch_request(Artist* artists){
int option, i, j, cont = 1;
char query_arg[32];
char query_cat[32];
char query_art[32];
char query_song[32];
char tmp;
int wild = 0;
int normalize = 1;
while(cont == 1){
wild = 0;
tmp = 0;
memset(query_arg,0,32);
memset(query_cat,0,32);
memset(query_art,0,32);
memset(query_song,0,32);
fflush(stdout);
fflush(stdin);
if(normalize == 1){
//printf("Query: ");
normalize = 0;
}
else{
normalize++;
}
fflush(stdout);
for(i = 0; i < 4 && !wild; i++){
j = 0;
while((tmp = getchar()) != ' '){
switch(i){
case 0:
query_arg[j] = tmp;
break;
case 1:
query_cat[j] = tmp;
break;
case 2:
query_art[j] = tmp;
case 3:
query_song[j] = tmp;
default:
break;
}
if(tmp == '*' || tmp == '\n'){
wild = 1;
fflush(stdin);
break;
}
else{
j++;
}
}
switch(i){
case 0:
query_arg[j+1] = 0;
break;
case 1:
query_cat[j+1] = 0;
break;
case 2:
query_art[j+1] = 0;
case 3:
query_song[j+1] = 0;
default:
break;
}
}
//printf("%s\n", query_arg);
//printf("%s\n", query_cat);
//printf("%s\n", query_art);
//printf("%s\n", query_song);
make_request(query_arg, query_cat, query_art, query_song, artists);
fflush(stdout);
}
}
int database_entry(void){
Artist* artists = malloc(5*sizeof(*artists));
int i;
for(i = 0; i < 5; i++){
// artists[i].category = (char*) malloc(30*sizeof(char));
// artists[i].artist = (char*) malloc(8*30);
// artists[i].songs = (char**) malloc(2*8*30);
artists[i].listeners = (long*)malloc(2* sizeof(long));
}
artists->category = strdup("Jazz");
(artists+1)->category = strdup("Pop");
(artists+2)->category = strdup("Metal");
(artists+3)->category = strdup("Reggae");
(artists+4)->category = strdup("watpop");
artists->artist = strdup("Mingus");
(artists+1)->artist = strdup("Malone");
(artists+2)->artist = strdup("Metallica");
(artists+3)->artist = strdup("Marley");
(artists+4)->artist = strdup("KNAAN");
artists->song1 = strdup("Moanin'");
(artists+1)->song1 = strdup("Circles");
(artists+2)->song1 = strdup("Matters");
(artists+3)->song1 = strdup("Jamming");
(artists+4)->song1 = strdup("Flag");
(artists->song2) = strdup("Hat");
(artists+1)->song2 = strdup("Sunflower");
(artists+2)->song2 = strdup("Sandman");
(artists+3)->song2 = strdup("Love");
(artists+4)->song2 = strdup("𝓯𝓵𝓪𝓰");
//(artists+4)->secret = strdup("watevr{#####################}");
artists->listeners[0] = 5299503;
(artists+1)->listeners[0] = 400792686;
(artists+2)->listeners[0] = 399045826;
(artists+3)->listeners[0] = 191297205;
(artists+4)->listeners[0] = 13371337;
artists->listeners[1] = 53457429;
(artists+1)->listeners[1] = 1211980336;
(artists+2)->listeners[1] = 427853415;
(artists+3)->listeners[1] = 189906840;
(artists+4)->listeners[1] = 13371337;
(artists+4)->secret = strdup("watevr{######################################################}");
introduce();
fetch_request(artists);
}
void log_out(Artist* artists){
printf("Goodbye, %s\n", (user+userid)->username);
introduce();
free((user+userid-1)->username);
free((user+userid-1));
}
void sig(int sign){
exit(0);
}
int main(void){
signal(SIGALRM, sig);
alarm(60);
user = malloc(6*sizeof(User));
//menu();
database_entry();
free(user);
}
|
the_stack_data/8291.c | #ifdef STM32F1xx
#include "stm32f1xx_hal_sd.c"
#endif
#ifdef STM32F2xx
#include "stm32f2xx_hal_sd.c"
#endif
#ifdef STM32F4xx
#include "stm32f4xx_hal_sd.c"
#endif
#ifdef STM32F7xx
#include "stm32f7xx_hal_sd.c"
#endif
#ifdef STM32H7xx
#include "stm32h7xx_hal_sd.c"
#endif
#ifdef STM32L1xx
#include "stm32l1xx_hal_sd.c"
#endif
#ifdef STM32L4xx
#include "stm32l4xx_hal_sd.c"
#endif
|
the_stack_data/98573997.c | /* 5. 문자 입력받기
- scanf의 도입
- scanf는 화면(키보드)로부터 결과를 받아들이는 입력 함수
- scanf는 어떠한 입력을 하기 전까지 계속 대기하며, 입력을 할 때 엔터를 눌러야지만 입력으로 처리됨.
- scanf는 각 변수의 타입마다 입력 받는 포맷을 다르게 해야함.
*/
// scanf 총 정리
#include <stdio.h>
int main() {
char ch; // 문자
short sh; // 정수
int i;
long lo;
float fl; // 실수
double du;
printf("char 형 변수 입력 : ");
scanf("%c", &ch);
printf("short 형 변수 입력 : ");
scanf("%hd", &sh);
printf("int 형 변수 입력 : ");
scanf("%d", &i);
printf("long 형 변수 입력 : ");
scanf("%ld", &lo);
printf("float 형 변수 입력 : ");
scanf("%f", &fl);
printf("double 형 변수 입력 : ");
scanf("%lf", &du);
printf("char : %c, short : %d, int: %d ", ch, sh, i);
printf("long : %ld, float : %f, double : %f \n", lo, fl, du);
return 0;
} |
the_stack_data/167331309.c | #include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
// Family of printf functions that include buffer overflow checks.
// But in KLEE we don't need the checks here (KLEE does it), and in NFOS we run
// verified code,
// so we don't need the checks.
int __fprintf_chk(FILE *stream, int flag, const char *format, ...) {
va_list args;
va_start(args, format);
int ret = vfprintf(stream, format, args);
va_end(args);
return ret;
}
int __printf_chk(int flag, const char *format, ...) {
va_list args;
va_start(args, format);
int ret = vprintf(format, args);
va_end(args);
return ret;
}
int __snprintf_chk(char *str, size_t maxlen, int flag, size_t strlen,
const char *format, ...) {
/* If strlen is less than maxlen, the function shall abort and the program
* shall exit */
if (strlen < maxlen) {
abort();
}
va_list args;
va_start(args, format);
int ret = vsnprintf(str, maxlen, format, args);
va_end(args);
return ret;
}
|
the_stack_data/206394058.c | // WARNING in __rtnl_newlink
// https://syzkaller.appspot.com/bug?id=289c370fb3e191c5ea46d8d62c02328d3cdf76e7
// status:open
// autogenerated by syzkaller (https://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <dirent.h>
#include <endian.h>
#include <errno.h>
#include <fcntl.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/mount.h>
#include <sys/prctl.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
static void sleep_ms(uint64_t ms)
{
usleep(ms * 1000);
}
static uint64_t current_time_ms(void)
{
struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC, &ts))
exit(1);
return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000;
}
static void use_temporary_dir(void)
{
char tmpdir_template[] = "./syzkaller.XXXXXX";
char* tmpdir = mkdtemp(tmpdir_template);
if (!tmpdir)
exit(1);
if (chmod(tmpdir, 0777))
exit(1);
if (chdir(tmpdir))
exit(1);
}
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) {
int err = errno;
close(fd);
errno = err;
return false;
}
close(fd);
return true;
}
#define FS_IOC_SETFLAGS _IOW('f', 2, long)
static void remove_dir(const char* dir)
{
DIR* dp;
struct dirent* ep;
int iter = 0;
retry:
while (umount2(dir, MNT_DETACH) == 0) {
}
dp = opendir(dir);
if (dp == NULL) {
if (errno == EMFILE) {
exit(1);
}
exit(1);
}
while ((ep = readdir(dp))) {
if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0)
continue;
char filename[FILENAME_MAX];
snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name);
while (umount2(filename, MNT_DETACH) == 0) {
}
struct stat st;
if (lstat(filename, &st))
exit(1);
if (S_ISDIR(st.st_mode)) {
remove_dir(filename);
continue;
}
int i;
for (i = 0;; i++) {
if (unlink(filename) == 0)
break;
if (errno == EPERM) {
int fd = open(filename, O_RDONLY);
if (fd != -1) {
long flags = 0;
if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0)
close(fd);
continue;
}
}
if (errno == EROFS) {
break;
}
if (errno != EBUSY || i > 100)
exit(1);
if (umount2(filename, MNT_DETACH))
exit(1);
}
}
closedir(dp);
int i;
for (i = 0;; i++) {
if (rmdir(dir) == 0)
break;
if (i < 100) {
if (errno == EPERM) {
int fd = open(dir, O_RDONLY);
if (fd != -1) {
long flags = 0;
if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0)
close(fd);
continue;
}
}
if (errno == EROFS) {
break;
}
if (errno == EBUSY) {
if (umount2(dir, MNT_DETACH))
exit(1);
continue;
}
if (errno == ENOTEMPTY) {
if (iter < 100) {
iter++;
goto retry;
}
}
}
exit(1);
}
}
static int inject_fault(int nth)
{
int fd;
fd = open("/proc/thread-self/fail-nth", O_RDWR);
if (fd == -1)
exit(1);
char buf[16];
sprintf(buf, "%d", nth + 1);
if (write(fd, buf, strlen(buf)) != (ssize_t)strlen(buf))
exit(1);
return fd;
}
static void kill_and_wait(int pid, int* status)
{
kill(-pid, SIGKILL);
kill(pid, SIGKILL);
int i;
for (i = 0; i < 100; i++) {
if (waitpid(-1, status, WNOHANG | __WALL) == pid)
return;
usleep(1000);
}
DIR* dir = opendir("/sys/fs/fuse/connections");
if (dir) {
for (;;) {
struct dirent* ent = readdir(dir);
if (!ent)
break;
if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0)
continue;
char abort[300];
snprintf(abort, sizeof(abort), "/sys/fs/fuse/connections/%s/abort",
ent->d_name);
int fd = open(abort, O_WRONLY);
if (fd == -1) {
continue;
}
if (write(fd, abort, 1) < 0) {
}
close(fd);
}
closedir(dir);
} else {
}
while (waitpid(-1, status, __WALL) != pid) {
}
}
static void setup_test()
{
prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
setpgrp();
write_file("/proc/self/oom_score_adj", "1000");
}
static void setup_fault()
{
static struct {
const char* file;
const char* val;
bool fatal;
} files[] = {
{"/sys/kernel/debug/failslab/ignore-gfp-wait", "N", true},
{"/sys/kernel/debug/fail_futex/ignore-private", "N", false},
{"/sys/kernel/debug/fail_page_alloc/ignore-gfp-highmem", "N", false},
{"/sys/kernel/debug/fail_page_alloc/ignore-gfp-wait", "N", false},
{"/sys/kernel/debug/fail_page_alloc/min-order", "0", false},
};
unsigned i;
for (i = 0; i < sizeof(files) / sizeof(files[0]); i++) {
if (!write_file(files[i].file, files[i].val)) {
if (files[i].fatal)
exit(1);
}
}
}
static void execute_one(void);
#define WAIT_FLAGS __WALL
static void loop(void)
{
int iter;
for (iter = 0;; iter++) {
char cwdbuf[32];
sprintf(cwdbuf, "./%d", iter);
if (mkdir(cwdbuf, 0777))
exit(1);
int pid = fork();
if (pid < 0)
exit(1);
if (pid == 0) {
if (chdir(cwdbuf))
exit(1);
setup_test();
execute_one();
exit(0);
}
int status = 0;
uint64_t start = current_time_ms();
for (;;) {
if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid)
break;
sleep_ms(1);
if (current_time_ms() - start < 5 * 1000)
continue;
kill_and_wait(pid, &status);
break;
}
remove_dir(cwdbuf);
}
}
uint64_t r[5] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff,
0xffffffffffffffff, 0x0};
void execute_one(void)
{
intptr_t res = 0;
syscall(__NR_socketpair, 1, 3, 0, 0);
res = syscall(__NR_socket, 0xa, 1, 0);
if (res != -1)
r[0] = res;
res = syscall(__NR_fcntl, -1, 0, r[0]);
if (res != -1)
r[1] = res;
syscall(__NR_ioctl, r[1], 0x8912, 0x400200);
syscall(__NR_openat, 0xffffffffffffff9c, 0, 0x290803, 0);
res = syscall(__NR_socket, 0x10, 3, 0);
if (res != -1)
r[2] = res;
res = syscall(__NR_socket, 0x10, 0x803, 0);
if (res != -1)
r[3] = res;
*(uint64_t*)0x200001c0 = 0;
*(uint32_t*)0x200001c8 = 0;
*(uint64_t*)0x200001d0 = 0x20000180;
*(uint64_t*)0x20000180 = 0;
*(uint64_t*)0x20000188 = 0;
*(uint64_t*)0x200001d8 = 1;
*(uint64_t*)0x200001e0 = 0;
*(uint64_t*)0x200001e8 = 0;
*(uint32_t*)0x200001f0 = 0;
syscall(__NR_sendmsg, r[3], 0x200001c0, 0);
*(uint32_t*)0x20000200 = 0x14;
res = syscall(__NR_getsockname, r[3], 0x20000100, 0x20000200);
if (res != -1)
r[4] = *(uint32_t*)0x20000104;
*(uint64_t*)0x20000040 = 0;
*(uint32_t*)0x20000048 = 0;
*(uint64_t*)0x20000050 = 0x20000000;
*(uint64_t*)0x20000000 = 0x20000480;
*(uint32_t*)0x20000480 = 0x40;
*(uint16_t*)0x20000484 = 0x10;
*(uint16_t*)0x20000486 = 0x705;
*(uint32_t*)0x20000488 = 0;
*(uint32_t*)0x2000048c = 0;
*(uint8_t*)0x20000490 = 0;
*(uint8_t*)0x20000491 = 0;
*(uint16_t*)0x20000492 = 0;
*(uint32_t*)0x20000494 = 0;
*(uint32_t*)0x20000498 = 0x33fddbe1;
*(uint32_t*)0x2000049c = 0;
*(uint16_t*)0x200004a0 = 0x20;
*(uint16_t*)0x200004a2 = 0x12;
*(uint16_t*)0x200004a4 = 0x10;
*(uint16_t*)0x200004a6 = 1;
memcpy((void*)0x200004a8, "ip6gretap\000", 10);
*(uint16_t*)0x200004b4 = 0xc;
*(uint16_t*)0x200004b6 = 2;
*(uint16_t*)0x200004b8 = 8;
*(uint16_t*)0x200004ba = 1;
*(uint32_t*)0x200004bc = r[4];
*(uint64_t*)0x20000008 = 0x40;
*(uint64_t*)0x20000058 = 1;
*(uint64_t*)0x20000060 = 0;
*(uint64_t*)0x20000068 = 0;
*(uint32_t*)0x20000070 = 0;
inject_fault(10);
syscall(__NR_sendmsg, r[2], 0x20000040, 0);
}
int main(void)
{
syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0);
setup_fault();
use_temporary_dir();
loop();
return 0;
}
|
the_stack_data/278712.c | /* Randomly change policy */
#include <stdio.h>
#include "numa.h"
#include "numaif.h"
#include <sys/mman.h>
#include <sys/shm.h>
#include <sys/ipc.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#define SIZE (100*1024*1024)
#define PAGES (SIZE/pagesize)
#define perror(x) printf("%s: %s\n", x, strerror(errno))
#define err(x) perror(x),exit(1)
struct page {
unsigned long mask;
int policy;
};
struct page *pages;
char *map;
int pagesize;
void setpol(unsigned long offset, unsigned long length, int policy, unsigned long nodes)
{
long i, end;
printf("off:%lx length:%lx policy:%d nodes:%lx\n",
offset, length, policy, nodes);
if (mbind(map + offset*pagesize, length*pagesize, policy,
&nodes, 8, 0) < 0) {
printf("mbind: %s offset %lx length %lx policy %d nodes %lx\n",
strerror(errno),
offset*pagesize, length*pagesize,
policy, nodes);
return;
}
for (i = offset; i < offset+length; i++) {
pages[i].mask = nodes;
pages[i].policy = policy;
}
i = offset - 20;
if (i < 0)
i = 0;
end = offset+length+20;
if (end > PAGES)
end = PAGES;
for (; i < end; i++) {
int pol2;
unsigned long nodes2;
if (get_mempolicy(&pol2, &nodes2, sizeof(long)*8, map+i*pagesize,
MPOL_F_ADDR) < 0)
err("get_mempolicy");
if (pol2 != pages[i].policy) {
printf("%lx: got policy %d expected %d, nodes got %lx expected %lx\n",
i, pol2, pages[i].policy, nodes2, pages[i].mask);
}
if (policy != MPOL_DEFAULT && nodes2 != pages[i].mask) {
printf("%lx: nodes %lx, expected %lx, policy %d\n",
i, nodes2, pages[i].mask, policy);
}
}
}
static unsigned char pop4[16] = {
0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4
};
int popcnt(unsigned long val)
{
int count = 0;
while (val) {
count += pop4[val & 0xf];
val >>= 4;
}
return count;
}
void testmap(void)
{
pages = calloc(1, PAGES * sizeof(struct page));
if (!pages)
exit(100);
printf("simple tests\n");
#define MB ((1024*1024)/pagesize)
setpol(0, PAGES, MPOL_INTERLEAVE, 3);
setpol(0, MB, MPOL_BIND, 1);
setpol(MB, MB, MPOL_BIND, 1);
setpol(MB, MB, MPOL_DEFAULT, 0);
setpol(MB, MB, MPOL_PREFERRED, 2);
setpol(MB/2, MB, MPOL_DEFAULT, 0);
setpol(MB+MB/2, MB, MPOL_BIND, 2);
setpol(MB/2+100, 100, MPOL_PREFERRED, 1);
setpol(100, 200, MPOL_PREFERRED, 1);
printf("done\n");
for (;;) {
unsigned long offset = random() % PAGES;
int policy = random() % (MPOL_MAX+1);
unsigned long nodes = random() % 4;
long length = random() % (PAGES - offset);
/* validate */
switch (policy) {
case MPOL_DEFAULT:
nodes = 0;
break;
case MPOL_INTERLEAVE:
case MPOL_BIND:
if (nodes == 0)
continue;
break;
case MPOL_PREFERRED:
if (popcnt(nodes) != 1)
continue;
break;
}
setpol(offset, length, policy, nodes);
}
}
int main(int ac, char **av)
{
unsigned long seed;
pagesize = getpagesize();
#if 0
map = mmap(NULL, SIZE, PROT_READ, MAP_ANONYMOUS|MAP_PRIVATE, 0, 0);
if (map == (char*)-1)
err("mmap");
#else
int shmid = shmget(IPC_PRIVATE, SIZE, IPC_CREAT|0666);
if (shmid < 0) err("shmget");
map = shmat(shmid, NULL, SHM_RDONLY);
shmctl(shmid, IPC_RMID, NULL);
if (map == (char *)-1) err("shmat");
printf("map %p\n", map);
#endif
if (av[1]) {
char *end;
unsigned long timeout = strtoul(av[1], &end, 0);
switch (*end) {
case 'h': timeout *= 3600; break;
case 'm': timeout *= 60; break;
}
printf("running for %lu seconds\n", timeout);
alarm(timeout);
} else
printf("running forever\n");
if (av[1] && av[2])
seed = strtoul(av[2], 0, 0);
else
seed = time(0);
printf("random seed %lu\n", seed);
srandom(seed);
testmap();
/* test shm etc. */
return 0;
}
|
the_stack_data/212643621.c | /*
a menu driven program to implement linear search (sentinel) and binary search.
Special Guidelines:
Linear Sentinel Search:
- Min. of 2 different data types// array of objects with 2 different data type is also fine (can search in all 2 data types with menu driven program)
- do sentinel search and show the no. of searches for best/average and worst cases.
Binary Search:
- have 2 data types namely 1. int or float 2. Char array or String and do the search in both the data types
- Can either take the input in the sorted order itself. (for complexity - if the sorted order is missed during input, it can prompt the user (eg. input of 5 elts.. let the elts be 10, 20, 12 (here it has to stop the user saying you can enter 20 or >20 only as the prev elt is 20) or take the input in any order and later can check whether it is in sorted order or not; if not in sorted order, should redirect the array for sorting and later do the binary search
- Print the messages according to the result (if found, Print the message accordingly. Eg. elt X is present in position Y; if not , say elt is not found in the array
*/
// header files
#include <stdio.h>
#include <stdlib.h>
// function declaration
// for int
void linear_sentinel_search_int(int [], int *, int *);
void array_insertion_int(int [], int *);
int search_element_int(int *);
void linear_search_int(int [], int *, int *);
void binary_search_int(int [], int, int, int);
// for char
char search_element_char(char *);
void linear_sentinel_search_char(char [], int *, char *);
void linear_search_char(char [], int *, char *);
void binary_search_char(char [], int, int, char);
void array_insertion_char(char [], int *);
// MENU
void menu(void);
void menu_binary_search(int [], char [], int *);
void menu_linear_search(int [], char [], int *);
// main function
int main()
{
// declaration of variables
int array_int[20], limit, option, _exit, position, element;
char var, array_char[20];
// initialisation of variables
limit = option = _exit = position = element = 0;
var = 'd';
do
{
system("clear");
menu();
printf("\n\n\tEnter your option: ");
scanf("%d", &option);
switch(option)
{
case 1: {
menu_linear_search(array_int, array_char, &limit);
do
{
var = getchar();
}while(var != '\n' && var != EOF);
}
break;
case 2: {
menu_binary_search(array_int, array_char, &limit);
}
do
{
var = getchar();
}while(var != '\n' && var != EOF);
break;
case 3: exit(0);
break;
default: printf("\n\tKindly input the correct given options. Thank you.");
}
do
{
var = getchar();
}while(var != '\n' && var != EOF);
}while(option != 3);
return 0;
}
// funtion definitons
// menu
void menu(void)
{
printf("\n\tLAB 3 SEARCHING PROGRAM! - int");
printf("\n\t_____________________________\n\n");
printf("\n\n\t\t\tMENU");
printf("\n\n\t1. Linear and Linear Sentinel Search");
printf("\n\n\t2. Binary Search");
printf("\n\n\t3. Exit.\n");
}
// insertion of - int
void array_insertion_char(char array[], int *size)
{
int i;
i = 0;
printf("\n\tEnter number of elements in array (max 20): ");
scanf("%d", size); // why no * or & with size?
if(*size > 20 || *size < 1) // validation
{
printf("\n\tEnter the size between 1 - 20 only!!");
array_insertion_char(array, size); // how to use recursion if a function has parameters?
}
printf("\n\tEnter %d elements\n", *size);
for (i = 0; i < *size; i++)
{
printf("\n\tElement %d: ", (i + 1));
scanf(" %c", &array[i]);
}
}
// insertion of array elements - int
void array_insertion_int(int array[], int *size)
{
int i;
i = 0;
printf("\n\tEnter number of elements in array (max 20): ");
scanf("%d", size); // why no * or & with size?
if(*size > 20 || *size < 1) // validation
{
printf("\n\tEnter the size between 1 - 20 only!!");
array_insertion_int(array, size); // how to use recursion if a function has parameters?
}
printf("\n\tEnter %d elements\n", *size);
for (i = 0; i < *size; i++)
{
printf("\n\tElement %d: ", (i + 1));
scanf("%d", &array[i]);
}
}
// menu for linear search
void menu_linear_search(int array_int[], char array_char[], int *size)
{
char option = 'y', var = 't', element_char = 'c';
int choice, element_int;
choice = element_int = 0;
system("clear");
printf("\n\n\tLinear and Linear Sentinel Search");
printf("\n\t1. use int datatype");
printf("\n\t2. use char datatype");
printf("\n\tEnter your choice: ");
scanf("%d", &choice);
printf("\n\tDo you want to retain the array elements? (y/n): ");
scanf(" %c", &option);
// when elements are retained
if(option == 'y')
{
printf("\n\tElements retained.\n");
if(choice == 1) // int
{
element_int = search_element_int(&element_int); // feed element to search
linear_search_int(array_int, size, &element_int);
linear_sentinel_search_int(array_int, size, &element_int);
do
{
var = getchar();
}while(var != '\n' && var != EOF);
}
else // char
{
element_char = search_element_char(&element_char);
linear_search_char(array_char, size, &element_char);
linear_sentinel_search_char(array_char, size, &element_char);
do
{
var = getchar();
}while(var != '\n' && var != EOF);
}
}
// when elements are not retained
else if(option == 'n')
{
if(choice == 1) // int
{
array_insertion_int(array_int, size);
element_int = search_element_int(&element_int); // feed element to search
linear_search_int(array_int, size, &element_int);
linear_sentinel_search_int(array_int, size, &element_int);
do
{
var = getchar();
}while(var != '\n' && var != EOF);
}
else // char
{
array_insertion_char(array_char, size);
element_char = search_element_char(&element_char);
linear_search_char(array_char, size, &element_char);
linear_sentinel_search_char(array_char, size, &element_char);
do
{
var = getchar();
}while(var != '\n' && var != EOF);
}
}
else
{
printf("\n\tEnter a correct value!");
do
{
var = getchar();
}while(var != '\n' && var != EOF);
menu_linear_search(array_int, array_char, size);
}
}
// element to search for - int
int search_element_int(int *element)
{
printf("\n\tWhich element do you want to search for?");
printf("\n\tElement: ");
scanf("%d", element);
return *element;
}
// element to search for - char
char search_element_char(char *element)
{
printf("\n\tWhich element do you want to search for?");
printf("\n\tElement: ");
scanf(" %c", element);
return *element;
}
// linear sentinel search - char
void linear_sentinel_search_char(char array[], int *size, char *character)
{
int i;
char last;
i = 0;
last = 'z';
last = array[*size - 1];
array[*size - 1] = *character;
printf("\n\n\tLinear Sentinel Search -\n");
while(array[i] != *character)
{
printf("\n\tLoop runs %d times", (i + 1)); // number of times executed
i++;
}
array[*size - 1] = last;
if(i < (*size - 1) || array[i] == *character)
{
printf("\n\tThe number %c is found at index: %d and position: %d\n\n", *character, i, (i + 1));
}
else
{
printf("\n\tElement %c not found in the array.", *character);
}
}
// linear sentinel search - int
void linear_sentinel_search_int(int array[], int *size, int *number)
{
int i, last;
i = last = 0;
last = array[*size - 1];
array[*size - 1] = *number;
printf("\n\n\tLinear Sentinel Search -\n");
while(array[i] != *number)
{
printf("\n\tLoop runs %d times", (i + 1)); // number of times executed
i++;
}
array[*size - 1] = last;
if(i < (*size - 1) || array[i] == *number)
{
printf("\n\tThe number %d is found at index: %d and position: %d\n\n", *number, i, (i + 1));
}
else
{
printf("\n\tElement %d not found in the array.", *number);
}
}
// linear search function - int
void linear_search_int(int array[], int *size, int *number)
{
int i, flag;
i = flag = 0;
printf("\n\n\tLinear search -\n");
for(i = 0; i < *size; i++)
{
printf("\n\tLoop runs %d times", (i + 1)); // number of times executed
if(array[i] == *number) // checking the number in array
{
flag = 1;
break;
}
}
if(flag == 1)
{
printf("\n\tElement %d found at position: %d", *number, (i + 1));
}
else
{
printf("\n\tElement %d not found in the array.", *number);
}
}
// linear search function - char
void linear_search_char(char array[], int *size, char *character)
{
int i, flag;
i = flag = 0;
printf("\n\n\tLinear search -\n");
for(i = 0; i < *size; i++)
{
printf("\n\tLoop runs %d times", (i + 1)); // number of times executed
if(array[i] == *character) // checking the number in array
{
flag = 1;
break;
}
}
if(flag == 1)
{
printf("\n\tElement %c found at position: %d", *character, (i + 1));
}
else
{
printf("\n\tElement %c not found in the array.", *character);
}
}
// binary search menu
void menu_binary_search(int array_int[], char array_char[], int *size)
{
char option = 'y', var = 't', element_char = 'c';
int choice, element_int;
choice = element_int = 0;
system("clear");
printf("\n\n\tBinary Search");
printf("\n\t1. use int datatype");
printf("\n\t2. use char datatype");
printf("\n\tEnter your choice: ");
scanf("%d", &choice);
printf("\n\tDo you want to retain the array elements? (y/n): ");
scanf(" %c", &option);
// when elements are retained
if(option == 'y')
{
printf("\n\tElements retained.\n");
if(choice == 1) // int
{
element_int = search_element_int(&element_int); // feed element to search
binary_search_int(array_int, 0, (*size - 1), element_int);
do
{
var = getchar();
}while(var != '\n' && var != EOF);
}
else // char
{
element_char = search_element_char(&element_char);
binary_search_char(array_char, 0, (*size - 1), element_char);
do
{
var = getchar();
}while(var != '\n' && var != EOF);
}
}
// when elements are not retained
else if(option == 'n')
{
if(choice == 1)
{
array_insertion_int(array_int, size); // insertion of array elements
element_int = search_element_int(&element_int); // feed element to search
binary_search_int(array_int, 0, (*size - 1), element_int);
do
{
var = getchar();
}while(var != '\n' && var != EOF);
}
else
{
array_insertion_char(array_char, size);
element_char = search_element_char(&element_char);
binary_search_char(array_char, 0, (*size - 1), element_char);
do
{
var = getchar();
}while(var != '\n' && var != EOF);
}
}
else
{
printf("\n\tEnter a correct value!");
do
{
var = getchar();
}while(var != '\n' && var != EOF);
menu_linear_search(array_int, array_char, size);
}
}
// binary search function - char
void binary_search_char(char array[], int min, int max, char element)
{
int mid, i, flag;
mid = i = flag = 0;
printf("\n\tBinary Search");
while (min <= max)
{
printf("\n\tLoop runs %d times", (++i)); // number of times executed
mid = (max + min) / 2;
if (array[mid] == element)
{
flag = 1;
break;
}
else if(array[mid] < element)
{
min = mid + 1;
}
else
{
max = mid - 1;
}
}
if(flag == 0)
{
printf("\n\tElement %c not found in the array.", element);
}
else
{
printf("\n\tElement %c found at position: %d", element, (mid + 1));
}
}
// binary search function - int
void binary_search_int(int array[], int min, int max, int element)
{
int mid, i, flag;
mid = i = flag = 0;
printf("\n\tBinary Search");
while (min <= max)
{
printf("\n\tLoop runs %d times", (++i)); // number of times executed
mid = (max + min) / 2;
if (array[mid] == element)
{
flag = 1;
break;
}
else if(array[mid] < element)
{
min = mid + 1;
}
else
{
max = mid - 1;
}
}
if(flag == 0)
{
printf("\n\tElement %d not found in the array.", element);
}
else
{
printf("\n\tElement %d found at position: %d", element, (mid + 1));
}
}
|
the_stack_data/150143626.c | /**
* e^x = 1 + x/1 + x^2/2! + x^3/3! + x^4/4! .....
* e^x = 1 + x/1 + (x*x)/(1*2) + (x*x*x)/(1*2*3) + (x*x*x*x)/(1*2*3*4)
* = 1 + x/1 [x/2 + x*x/2*3 + x*x*x/2*3*4]
* = 1 + x/1 [1 + x/2 [x/3 + x*x/3*4]]
* = 1 + x/1 [1 + x/2 [1 + x/3 [1 + x/4]]]
*/
// time complexity is O(n) & space is O(1)
#include <stdio.h>
double taylorSeries(int x, int n){
double s = 1;
while(n > 0){
s = 1+ x*s/n;
n--;
}
return s;
}
// with recursion O(n)
double taylorSeries2(int x, int p){
static double s = 1;
if (p > 0){
s = 1 + x*s/p;
return taylorSeries2(x, p-1);
}
return s;
}
int main(){
printf("%lf\n", taylorSeries2(3, 10));
printf("%lf\n", taylorSeries(3, 10));
} |
the_stack_data/39084.c | int value = 1;
void initsetvalue(void)
{
value = 2;
}
|
the_stack_data/8849.c | #include<stdio.h>
#include<math.h>
int isPrime(int n){
int prime = 1;
if(n==1){
prime = 0;
return prime;
}
for(int i = 2;i<n;i++){
n % i ==0 ? prime = 0 : 0;
}
return prime;
}
int somaPrimes = 0;
void somaPrime(int n){
somaPrimes = 0;
for(int i=0;i<=n;i++){
if(isPrime(i)==1){
somaPrimes+=i;
}
}
}
int main(void){
int num;
scanf("%d",&num);
somaPrime(num);
printf("\n%d\n",somaPrimes);
return 0;
} |
the_stack_data/116273.c | /* This testcase is part of GDB, the GNU debugger.
Copyright 2010-2015 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Shared library functions */
extern void func1 (void);
extern int func2 (void);
int
main (int argc, char *argv[])
{
func1 ();
func2 ();
return 0; /* Break to end. */
}
|
the_stack_data/131535.c | #ifdef COMPILE_FOR_TEST
#include <assert.h>
#define assume(cond) assert(cond)
#endif
void main(int argc, char* argv[]) {
int x_0_0;//CREST_scheduler::lock_0
int x_0_1;//CREST_scheduler::lock_0
int x_0_2;//CREST_scheduler::lock_0
int x_0_3;//CREST_scheduler::lock_0
int x_0_4;//CREST_scheduler::lock_0
int x_0_5;//CREST_scheduler::lock_0
int x_1_0;//preallocated_properties_index
int x_1_1;//preallocated_properties_index
int x_1_2;//preallocated_properties_index
int x_2_0;//preallocated_objectmaps_index
int x_2_1;//preallocated_objectmaps_index
int x_2_2;//preallocated_objectmaps_index
int x_3_0;//preallocated_objects_index
int x_3_1;//preallocated_objects_index
int x_3_2;//preallocated_objects_index
int x_4_0;//preallocated_cacheentries_index
int x_4_1;//preallocated_cacheentries_index
int x_5_0;//preallocated_properties[0].id
int x_5_1;//preallocated_properties[0].id
int x_6_0;//preallocated_objectmaps[0].nrefs
int x_6_1;//preallocated_objectmaps[0].nrefs
int x_7_0;//preallocated_objectmaps[0].nslots
int x_7_1;//preallocated_objectmaps[0].nslots
int x_8_0;//preallocated_objectmaps[0].freeslot
int x_8_1;//preallocated_objectmaps[0].freeslot
int x_9_0;//preallocated_properties[1].id
int x_10_0;//preallocated_objectmaps[1].nrefs
int x_11_0;//preallocated_objectmaps[1].nslots
int x_12_0;//preallocated_objectmaps[1].freeslot
int x_13_0;//preallocated_properties[2].id
int x_14_0;//preallocated_objectmaps[2].nrefs
int x_15_0;//preallocated_objectmaps[2].nslots
int x_16_0;//preallocated_objectmaps[2].freeslot
int x_17_0;//preallocated_properties[3].id
int x_18_0;//preallocated_objectmaps[3].nrefs
int x_19_0;//preallocated_objectmaps[3].nslots
int x_20_0;//preallocated_objectmaps[3].freeslot
int x_21_0;//preallocated_properties[4].id
int x_22_0;//preallocated_objectmaps[4].nrefs
int x_23_0;//preallocated_objectmaps[4].nslots
int x_24_0;//preallocated_objectmaps[4].freeslot
int x_25_0;//preallocated_properties[5].id
int x_26_0;//preallocated_objectmaps[5].nrefs
int x_27_0;//preallocated_objectmaps[5].nslots
int x_28_0;//preallocated_objectmaps[5].freeslot
int x_29_0;//preallocated_properties[6].id
int x_30_0;//preallocated_objectmaps[6].nrefs
int x_31_0;//preallocated_objectmaps[6].nslots
int x_32_0;//preallocated_objectmaps[6].freeslot
int x_33_0;//preallocated_properties[7].id
int x_34_0;//preallocated_objectmaps[7].nrefs
int x_35_0;//preallocated_objectmaps[7].nslots
int x_36_0;//preallocated_objectmaps[7].freeslot
int x_37_0;//preallocated_properties[8].id
int x_38_0;//preallocated_objectmaps[8].nrefs
int x_39_0;//preallocated_objectmaps[8].nslots
int x_40_0;//preallocated_objectmaps[8].freeslot
int x_41_0;//preallocated_properties[9].id
int x_42_0;//preallocated_objectmaps[9].nrefs
int x_43_0;//preallocated_objectmaps[9].nslots
int x_44_0;//preallocated_objectmaps[9].freeslot
int x_45_0;//preallocated_properties[10].id
int x_46_0;//preallocated_objectmaps[10].nrefs
int x_47_0;//preallocated_objectmaps[10].nslots
int x_48_0;//preallocated_objectmaps[10].freeslot
int x_49_0;//preallocated_properties[11].id
int x_50_0;//preallocated_objectmaps[11].nrefs
int x_51_0;//preallocated_objectmaps[11].nslots
int x_52_0;//preallocated_objectmaps[11].freeslot
int x_53_0;//preallocated_properties[12].id
int x_54_0;//preallocated_objectmaps[12].nrefs
int x_55_0;//preallocated_objectmaps[12].nslots
int x_56_0;//preallocated_objectmaps[12].freeslot
int x_57_0;//preallocated_properties[13].id
int x_58_0;//preallocated_objectmaps[13].nrefs
int x_59_0;//preallocated_objectmaps[13].nslots
int x_60_0;//preallocated_objectmaps[13].freeslot
int x_61_0;//preallocated_properties[14].id
int x_62_0;//preallocated_objectmaps[14].nrefs
int x_63_0;//preallocated_objectmaps[14].nslots
int x_64_0;//preallocated_objectmaps[14].freeslot
int x_65_0;//preallocated_properties[15].id
int x_66_0;//preallocated_objectmaps[15].nrefs
int x_67_0;//preallocated_objectmaps[15].nslots
int x_68_0;//preallocated_objectmaps[15].freeslot
int x_69_0;//preallocated_properties[16].id
int x_70_0;//preallocated_objectmaps[16].nrefs
int x_71_0;//preallocated_objectmaps[16].nslots
int x_72_0;//preallocated_objectmaps[16].freeslot
int x_73_0;//preallocated_properties[17].id
int x_74_0;//preallocated_objectmaps[17].nrefs
int x_75_0;//preallocated_objectmaps[17].nslots
int x_76_0;//preallocated_objectmaps[17].freeslot
int x_77_0;//preallocated_properties[18].id
int x_78_0;//preallocated_objectmaps[18].nrefs
int x_79_0;//preallocated_objectmaps[18].nslots
int x_80_0;//preallocated_objectmaps[18].freeslot
int x_81_0;//preallocated_properties[19].id
int x_82_0;//preallocated_objectmaps[19].nrefs
int x_83_0;//preallocated_objectmaps[19].nslots
int x_84_0;//preallocated_objectmaps[19].freeslot
int x_85_0;//cache_global.empty
int x_85_1;//cache_global.empty
int x_85_2;//cache_global.empty
int x_86_0;//cache_global.fills
int x_86_1;//cache_global.fills
int x_87_0;//cache_global.recycles
int x_87_1;//cache_global.recycles
int x_88_0;//cache_global.tests
int x_88_1;//cache_global.tests
int x_89_0;//cache_global.misses
int x_89_1;//cache_global.misses
int x_90_0;//cache_global.flushes
int x_90_1;//cache_global.flushes
int x_90_2;//cache_global.flushes
int x_91_0;//functioncall::param T0
int x_91_1;//functioncall::param T0
int x_91_2;//functioncall::param T0
int x_91_3;//functioncall::param T0
int x_91_4;//functioncall::param T0
int x_91_5;//functioncall::param T0
int x_91_6;//functioncall::param T0
int x_91_7;//functioncall::param T0
int x_91_8;//functioncall::param T0
int x_91_9;//functioncall::param T0
int x_91_10;//functioncall::param T0
int x_91_11;//functioncall::param T0
int x_91_12;//functioncall::param T0
int x_91_13;//functioncall::param T0
int x_91_14;//functioncall::param T0
int x_91_15;//functioncall::param T0
int x_91_16;//functioncall::param T0
int x_91_17;//functioncall::param T0
int x_91_18;//functioncall::param T0
int x_91_19;//functioncall::param T0
int x_91_20;//functioncall::param T0
int x_91_21;//functioncall::param T0
int x_92_0;//continuously_fill_cache::i T1
int x_92_1;//continuously_fill_cache::i T1
int x_93_0;//continuously_fill_cache::jso T1
int x_94_0;//get_new_object::newmap T1
int x_95_0;//get_new_object::newobj T1
int x_96_0;//continuously_fill_cache::id T1
int x_96_1;//continuously_fill_cache::id T1
int x_97_0;//functioncall::param T1
int x_97_1;//functioncall::param T1
int x_98_0;//js_PropertyCacheFill::NUMFLUSHES_BEGIN T1
int x_98_1;//js_PropertyCacheFill::NUMFLUSHES_BEGIN T1
int x_98_2;//js_PropertyCacheFill::NUMFLUSHES_BEGIN T1
T_0_0_0: x_0_0 = -1;
T_0_1_0: x_1_0 = 0;
T_0_2_0: x_1_1 = 0;
T_0_3_0: x_2_0 = 0;
T_0_4_0: x_2_1 = 0;
T_0_5_0: x_3_0 = 0;
T_0_6_0: x_3_1 = 0;
T_0_7_0: x_4_0 = 0;
T_0_8_0: x_4_1 = 0;
T_0_9_0: x_91_0 = 1291903698;
T_0_10_0: x_91_1 = 0;
T_0_11_0: x_5_0 = 0;
T_0_12_0: x_6_0 = 0;
T_0_13_0: x_7_0 = 0;
T_0_14_0: x_8_0 = 0;
T_0_15_0: x_91_2 = 1 + x_91_1;
T_0_16_0: x_9_0 = 0;
T_0_17_0: x_10_0 = 0;
T_0_18_0: x_11_0 = 0;
T_0_19_0: x_12_0 = 0;
T_0_20_0: x_91_3 = 1 + x_91_2;
T_0_21_0: x_13_0 = 0;
T_0_22_0: x_14_0 = 0;
T_0_23_0: x_15_0 = 0;
T_0_24_0: x_16_0 = 0;
T_0_25_0: x_91_4 = 1 + x_91_3;
T_0_26_0: x_17_0 = 0;
T_0_27_0: x_18_0 = 0;
T_0_28_0: x_19_0 = 0;
T_0_29_0: x_20_0 = 0;
T_0_30_0: x_91_5 = 1 + x_91_4;
T_0_31_0: x_21_0 = 0;
T_0_32_0: x_22_0 = 0;
T_0_33_0: x_23_0 = 0;
T_0_34_0: x_24_0 = 0;
T_0_35_0: x_91_6 = 1 + x_91_5;
T_0_36_0: x_25_0 = 0;
T_0_37_0: x_26_0 = 0;
T_0_38_0: x_27_0 = 0;
T_0_39_0: x_28_0 = 0;
T_0_40_0: x_91_7 = 1 + x_91_6;
T_0_41_0: x_29_0 = 0;
T_0_42_0: x_30_0 = 0;
T_0_43_0: x_31_0 = 0;
T_0_44_0: x_32_0 = 0;
T_0_45_0: x_91_8 = 1 + x_91_7;
T_0_46_0: x_33_0 = 0;
T_0_47_0: x_34_0 = 0;
T_0_48_0: x_35_0 = 0;
T_0_49_0: x_36_0 = 0;
T_0_50_0: x_91_9 = 1 + x_91_8;
T_0_51_0: x_37_0 = 0;
T_0_52_0: x_38_0 = 0;
T_0_53_0: x_39_0 = 0;
T_0_54_0: x_40_0 = 0;
T_0_55_0: x_91_10 = 1 + x_91_9;
T_0_56_0: x_41_0 = 0;
T_0_57_0: x_42_0 = 0;
T_0_58_0: x_43_0 = 0;
T_0_59_0: x_44_0 = 0;
T_0_60_0: x_91_11 = 1 + x_91_10;
T_0_61_0: x_45_0 = 0;
T_0_62_0: x_46_0 = 0;
T_0_63_0: x_47_0 = 0;
T_0_64_0: x_48_0 = 0;
T_0_65_0: x_91_12 = 1 + x_91_11;
T_0_66_0: x_49_0 = 0;
T_0_67_0: x_50_0 = 0;
T_0_68_0: x_51_0 = 0;
T_0_69_0: x_52_0 = 0;
T_0_70_0: x_91_13 = 1 + x_91_12;
T_0_71_0: x_53_0 = 0;
T_0_72_0: x_54_0 = 0;
T_0_73_0: x_55_0 = 0;
T_0_74_0: x_56_0 = 0;
T_0_75_0: x_91_14 = 1 + x_91_13;
T_0_76_0: x_57_0 = 0;
T_0_77_0: x_58_0 = 0;
T_0_78_0: x_59_0 = 0;
T_0_79_0: x_60_0 = 0;
T_0_80_0: x_91_15 = 1 + x_91_14;
T_0_81_0: x_61_0 = 0;
T_0_82_0: x_62_0 = 0;
T_0_83_0: x_63_0 = 0;
T_0_84_0: x_64_0 = 0;
T_0_85_0: x_91_16 = 1 + x_91_15;
T_0_86_0: x_65_0 = 0;
T_0_87_0: x_66_0 = 0;
T_0_88_0: x_67_0 = 0;
T_0_89_0: x_68_0 = 0;
T_0_90_0: x_91_17 = 1 + x_91_16;
T_0_91_0: x_69_0 = 0;
T_0_92_0: x_70_0 = 0;
T_0_93_0: x_71_0 = 0;
T_0_94_0: x_72_0 = 0;
T_0_95_0: x_91_18 = 1 + x_91_17;
T_0_96_0: x_73_0 = 0;
T_0_97_0: x_74_0 = 0;
T_0_98_0: x_75_0 = 0;
T_0_99_0: x_76_0 = 0;
T_0_100_0: x_91_19 = 1 + x_91_18;
T_0_101_0: x_77_0 = 0;
T_0_102_0: x_78_0 = 0;
T_0_103_0: x_79_0 = 0;
T_0_104_0: x_80_0 = 0;
T_0_105_0: x_91_20 = 1 + x_91_19;
T_0_106_0: x_81_0 = 0;
T_0_107_0: x_82_0 = 0;
T_0_108_0: x_83_0 = 0;
T_0_109_0: x_84_0 = 0;
T_0_110_0: x_91_21 = 1 + x_91_20;
T_0_111_0: x_85_0 = 0;
T_0_112_0: x_86_0 = 0;
T_0_113_0: x_87_0 = 0;
T_0_114_0: x_88_0 = 0;
T_0_115_0: x_89_0 = 0;
T_0_116_0: x_90_0 = 0;
T_0_117_0: x_85_1 = 0;
T_0_118_0: x_86_1 = 0;
T_0_119_0: x_87_1 = 0;
T_0_120_0: x_88_1 = 0;
T_0_121_0: x_89_1 = 0;
T_0_122_0: x_90_1 = 0;
T_1_123_1: x_92_0 = 0;
T_1_124_1: x_92_1 = 0;
T_1_125_1: if (x_92_1 < 20) x_93_0 = 0;
T_1_126_1: if (x_92_1 < 20) x_94_0 = 146;
T_1_127_1: if (x_92_1 < 20) x_2_2 = 1 + x_2_1;
T_1_128_1: if (x_92_1 < 20) x_6_1 = 0;
T_1_129_1: if (x_92_1 < 20) x_7_1 = 0;
T_1_130_1: if (x_92_1 < 20) x_8_1 = 0;
T_1_131_1: if (x_92_1 < 20) x_95_0 = -836716800;
T_1_132_1: if (x_92_1 < 20) x_3_2 = 1 + x_3_1;
T_1_133_1: if (x_92_1 < 20) x_1_2 = 1 + x_1_1;
T_1_134_1: if (x_92_1 < 20) x_5_1 = x_1_2;
T_1_135_1: if (x_92_1 < 20) x_96_0 = -836716800;
T_1_136_1: if (x_92_1 < 20) x_96_1 = x_92_1;
T_1_137_1: if (x_92_1 < 20) x_97_0 = 357914761;
T_1_138_1: if (x_92_1 < 20) x_97_1 = x_96_1;
T_1_139_1: if (x_92_1 < 20) x_98_0 = 11099;
T_1_140_1: if (x_92_1 < 20) x_98_1 = 0;
T_1_141_1: if (x_92_1 < 20 && 0 == x_0_0 + 1) x_0_1 = 1;
T_1_142_1: if (x_92_1 < 20 && 1 == x_0_1) x_98_2 = x_90_1;
T_1_143_1: if (x_92_1 < 20 && 1 == x_0_1) x_0_2 = -1;
T_2_144_2: if (0 == x_0_2 + 1) x_0_3 = 2;
T_2_145_2: if (x_85_1 == 0 && 2 == x_0_3) x_85_2 = 1;
T_2_146_2: if (x_85_1 == 0 && 2 == x_0_3) x_90_2 = 1 + x_90_1;
T_2_147_2: if (2 == x_0_3) x_0_4 = -1;
T_1_148_1: if (x_92_1 < 20 && 0 == x_0_4 + 1) x_0_5 = 1;
T_1_149_1: if (x_92_1 < 20 && 1 == x_0_5) assert(x_90_2 <= x_98_2);
}
|
the_stack_data/23574706.c | float j=1, k;
void main()
{
k = j++;
print ("k 1.000000");
printid(k);
}
|
the_stack_data/825661.c | unsigned char crypt_call_bin_bin[] = {
0x55, 0x89, 0xe5, 0x57, 0x56, 0x8b, 0x45, 0x10, 0x83, 0xf8, 0x00, 0x74,
0x4e, 0x31, 0xc0, 0xb8, 0x40, 0x00, 0x00, 0x00, 0x50, 0xb8, 0x00, 0x10,
0x00, 0x00, 0x50, 0x8b, 0x45, 0x0c, 0x50, 0x31, 0xc0, 0x50, 0x8b, 0x4d,
0x10, 0xff, 0xd1, 0x83, 0xc4, 0x10, 0x83, 0xf8, 0x00, 0x74, 0x2c, 0x83,
0xec, 0x04, 0x89, 0x45, 0xfc, 0x8b, 0x7d, 0xfc, 0x8b, 0x75, 0x08, 0x8b,
0x4d, 0x0c, 0xfc, 0xf3, 0xa4, 0x8b, 0x7d, 0xfc, 0x89, 0xfe, 0x8b, 0x4d,
0x0c, 0xac, 0x34, 0xc0, 0x34, 0x0f, 0x34, 0xfe, 0x34, 0xee, 0xaa, 0xe2,
0xf4, 0x8b, 0x45, 0xfc, 0x83, 0xc4, 0x04, 0x5e, 0x5f, 0x89, 0xec, 0x5d,
0xc3
};
unsigned int crypt_call_bin_bin_len = 97;
|
the_stack_data/576391.c | /* { dg-do compile } */
int
foo ()
{
return __sync_fetch_and_add ((int *) 0, 1);
}
|
the_stack_data/962898.c | #include<stdio.h>
void main()
{
int n,term;
printf("Enter the term of the fibonacci series\n");
scanf("%d",&n);
term=fab(n);
printf("The %d term is %d\n",n,term);
getch();
}
int fab(int n)
{
if(n==1||n==2)
{
return(1);
}
else
{
return(fab(n-1)+fab(n-2));
}
}
|
the_stack_data/86074348.c | #include <assert.h>
#include <stdio.h>
#include <string.h>
typedef unsigned char UINT8;
typedef unsigned short UINT16;
typedef UINT16 tKeccakLane;
#define KeccakP400_width 400
#define SnP_width 400
#define KeccakF_stateSizeInBytes 50
#define Ketje_BlockSize (2*KeccakP400_width/8/25)
#define FRAMEBITSEMPTY 0x01
#define FRAMEBITS0 0x02
#define FRAMEBITS00 0x04
#define FRAMEBITS10 0x05
#define FRAMEBITS01 0x06
#define FRAMEBITS11 0x07
#define Ket_StartRounds 12
#define Ket_StepRounds 1
#define Ket_StrideRounds 6
#define maxNrRounds 20
tKeccakLane KeccakRoundConstants[maxNrRounds];
#define nrLanes 25
#define OUTPUT
unsigned int KeccakRhoOffsets[nrLanes];
typedef struct {
/** The state processed by the permutation. */
unsigned char state[KeccakF_stateSizeInBytes];
/** The phase. */
unsigned int phase;
/** The amount of associated or plaintext data that has been
* XORed into the state after the last call to step or stride */
unsigned int dataRemainderSize;
} Ketje_Instance;
enum Phase {
Ketje_Phase_Virgin = 0,
Ketje_Phase_FeedingAssociatedData = 1,
Ketje_Phase_Wrapping = 2,
Ketje_Phase_Unwrapping = 4
};
int LFSR86540(UINT8 *LFSR)
{
int result = ((*LFSR) & 0x01) != 0;
if (((*LFSR) & 0x80) != 0)
// Primitive polynomial over GF(2): x^8+x^6+x^5+x^4+1
(*LFSR) = ((*LFSR) << 1) ^ 0x71;
else
(*LFSR) <<= 1;
return result;
}
void KeccakP400_InitializeRoundConstants()
{
UINT8 LFSRstate = 0x01;
unsigned int i, j, bitPosition;
for(i=0; i<maxNrRounds; i++) {
KeccakRoundConstants[i] = 0;
for(j=0; j<7; j++) {
bitPosition = (1<<j)-1; //2^j-1
if (LFSR86540(&LFSRstate) && (bitPosition < (sizeof(tKeccakLane)*8)))
KeccakRoundConstants[i] ^= (tKeccakLane)(1<<bitPosition);
}
}
}
#define ROL16(a, offset) ((offset != 0) ? ((((unsigned short)a) << offset) ^ (((unsigned short)a) >> (sizeof(unsigned short)*8-offset))) : a)
#define index(x, y) (((x)%5)+5*((y)%5))
void KeccakP400_InitializeRhoOffsets()
{
unsigned int x, y, t, newX, newY;
KeccakRhoOffsets[index(0, 0)] = 0;
x = 1;
y = 0;
for(t=0; t<24; t++) {
KeccakRhoOffsets[index(x, y)] = ((t+1)*(t+2)/2) % (sizeof(tKeccakLane) * 8);
newX = (0*x+1*y) % 5;
newY = (2*x+3*y) % 5;
x = newX;
y = newY;
}
}
void KeccakP400_AddByte(void *state, unsigned char byte, unsigned int offset)
{
assert(offset < 50);
((unsigned char *)state)[offset] ^= byte;
}
void KeccakP400_StaticInitialize()
{
KeccakP400_InitializeRoundConstants();
KeccakP400_InitializeRhoOffsets();
}
void KeccakP400_AddBytes(void *state, const unsigned char *data, unsigned int offset, unsigned int length)
{
unsigned int i;
assert(offset < 50);
assert(offset+length <= 50);
for(i=0; i<length; i++)
((unsigned char *)state)[offset+i] ^= data[i];
}
void KeccakP400_OverwriteBytes(void *state, const unsigned char *data, unsigned int offset, unsigned int length)
{
memcpy((unsigned char*)state+offset, data, length);
}
void KeccakP400_Initialize(void *state)
{
memset(state, 0, nrLanes * sizeof(tKeccakLane));
}
void theta(unsigned short *A)
{
unsigned int x, y;
unsigned short C[5], D[5];
for(x=0; x<5; x++) {
C[x] = 0;
for(y=0; y<5; y++)
C[x] ^= A[index(x, y)];
}
for(x=0; x<5; x++)
D[x] = ROL16(C[(x+1)%5], 1) ^ C[(x+4)%5];
for(x=0; x<5; x++)
for(y=0; y<5; y++)
A[index(x, y)] ^= D[x];
}
void rho(unsigned short *A)
{
unsigned int x, y;
for(x=0; x<5; x++) for(y=0; y<5; y++)
A[index(x, y)] = ROL16(A[index(x, y)], KeccakRhoOffsets[index(x, y)]);
}
void pi(unsigned short *A)
{
unsigned int x, y;
unsigned short tempA[25];
for(x=0; x<5; x++) for(y=0; y<5; y++)
tempA[index(x, y)] = A[index(x, y)];
for(x=0; x<5; x++) for(y=0; y<5; y++)
A[index(0*x+1*y, 2*x+3*y)] = tempA[index(x, y)];
}
void chi(unsigned short *A)
{
unsigned int x, y;
unsigned short C[5];
for(y=0; y<5; y++) {
for(x=0; x<5; x++)
C[x] = A[index(x, y)] ^ ((~A[index(x+1, y)]) & A[index(x+2, y)]);
for(x=0; x<5; x++)
A[index(x, y)] = C[x];
}
}
void iota(unsigned short *A, unsigned int indexRound)
{
A[index(0, 0)] ^= KeccakRoundConstants[indexRound];
}
void Round400(unsigned short* state, unsigned int rnd){
theta(state);
rho(state);
pi(state);
chi(state);
iota(state, rnd);
}
void keccakP400NRounds(void* state, int rounds){
int i = 0;
for(i=(maxNrRounds-rounds); i<maxNrRounds; i++){
Round400(state, i);
}
}
void KeccakP400_ExtractBytes(const void *state, unsigned char *data, unsigned int offset, unsigned int length)
{
assert(offset < 50);
assert(offset+length <= 50);
memcpy(data, (unsigned char*)state+offset, length);
}
unsigned char Ket_StateExtractByte( void *state, unsigned int offset )
{
unsigned char data[1];
KeccakP400_ExtractBytes(state, data, offset, 1);
return data[0];
}
void Ket_StateOverwrite( void *state, unsigned int offset, const unsigned char *data, unsigned int length )
{
KeccakP400_OverwriteBytes(state, data, offset, length);
}
/* Ketje low level functions */
void Ket_Step( void *state, unsigned int size, unsigned char frameAndPaddingBits)
{
KeccakP400_AddByte(state, frameAndPaddingBits, size);
KeccakP400_AddByte(state, 0x08, Ketje_BlockSize );
keccakP400NRounds(state, Ket_StepRounds );
}
void Ket_FeedAssociatedDataBlocks( void *state, const unsigned char *data, unsigned int nBlocks )
{
do
{
KeccakP400_AddByte( state, *(data++), 0 );
KeccakP400_AddByte( state, *(data++), 1 );
#if (KeccakP400_width == 400 )
KeccakP400_AddByte( state, *(data++), 2 );
KeccakP400_AddByte( state, *(data++), 3 );
#endif
Ket_Step( state, Ketje_BlockSize, FRAMEBITS00 );
}
while ( --nBlocks != 0 );
}
void Ket_UnwrapBlocks( void *state, const unsigned char *ciphertext, unsigned char *plaintext, unsigned int nBlocks )
{
unsigned char tempBlock[Ketje_BlockSize];
unsigned char frameAndPaddingBits[1];
frameAndPaddingBits[0] = 0x08 | FRAMEBITS11;
while ( nBlocks-- != 0 )
{
KeccakP400_ExtractBytes(state, tempBlock, 0, Ketje_BlockSize);
tempBlock[0] = *(plaintext++) = *(ciphertext++) ^ tempBlock[0];
tempBlock[1] = *(plaintext++) = *(ciphertext++) ^ tempBlock[1];
#if (KeccakP400_width == 400 )
tempBlock[2] = *(plaintext++) = *(ciphertext++) ^ tempBlock[2];
tempBlock[3] = *(plaintext++) = *(ciphertext++) ^ tempBlock[3];
#endif
KeccakP400_AddBytes(state, tempBlock, 0, Ketje_BlockSize);
KeccakP400_AddBytes(state, frameAndPaddingBits, Ketje_BlockSize, 1);
keccakP400NRounds(state, Ket_StepRounds);
}
}
unsigned int Ket_WrapBlocks( void *state, const unsigned char *plaintext, unsigned char *ciphertext, unsigned int nBlocks )
{
unsigned int ciphertext_size_on_blocks = 0;
unsigned char keystream[Ketje_BlockSize];
unsigned char plaintemp[Ketje_BlockSize];
unsigned char frameAndPaddingBits[1];
frameAndPaddingBits[0] = 0x08 | FRAMEBITS11;
while ( nBlocks-- != 0 )
{
KeccakP400_ExtractBytes(state, keystream, 0, Ketje_BlockSize);
plaintemp[0] = plaintext[0];
plaintemp[1] = plaintext[1];
#if (KeccakP400_width == 400 )
plaintemp[2] = plaintext[2];
plaintemp[3] = plaintext[3];
#endif
*(ciphertext++) = *(plaintext++) ^ keystream[0];
*(ciphertext++) = *(plaintext++) ^ keystream[1];
ciphertext_size_on_blocks++; ciphertext_size_on_blocks++;
#if (KeccakP400_width == 400 )
*(ciphertext++) = *(plaintext++) ^ keystream[2];
*(ciphertext++) = *(plaintext++) ^ keystream[3];
ciphertext_size_on_blocks++; ciphertext_size_on_blocks++;
#endif
KeccakP400_AddBytes(state, plaintemp, 0, Ketje_BlockSize);
KeccakP400_AddBytes(state, frameAndPaddingBits, Ketje_BlockSize, 1);
keccakP400NRounds(state, Ket_StepRounds);
}
return ciphertext_size_on_blocks;
}
int Ketje_Initialize(Ketje_Instance *instance, const unsigned char *key, unsigned int keySizeInBits, const unsigned char *nonce, unsigned int nonceSizeInBits)
{
unsigned char smallData[1];
unsigned int keyPackSizeInBits;
keyPackSizeInBits = 8*((keySizeInBits+16)/8);
if ( (keyPackSizeInBits + nonceSizeInBits + 2) > KeccakP400_width) {
return 1;
}
instance->phase = Ketje_Phase_FeedingAssociatedData;
instance->dataRemainderSize = 0;
KeccakP400_StaticInitialize();
KeccakP400_Initialize(instance->state);
// Key pack
smallData[0] = keySizeInBits / 8 + 2;
Ket_StateOverwrite( instance->state, 0, smallData, 1 );
Ket_StateOverwrite( instance->state, 1, key, keySizeInBits/8 );
if ((keySizeInBits % 8) == 0)
smallData[0] = 0x01;
else {
unsigned char padding = (unsigned char)1 << (keySizeInBits%8);
unsigned char mask = padding-1;
smallData[0] = (key[keySizeInBits/8] & mask) | padding;
}
Ket_StateOverwrite( instance->state, 1+keySizeInBits/8, smallData, 1 );
// Nonce
Ket_StateOverwrite( instance->state, 1+keySizeInBits/8+1, nonce, nonceSizeInBits / 8 );
if ((nonceSizeInBits % 8) == 0)
smallData[0] = 0x01;
else {
unsigned char padding = (unsigned char)1 << (nonceSizeInBits%8);
unsigned char mask = padding-1;
smallData[0] = (nonce[nonceSizeInBits/8] & mask) | padding;
}
Ket_StateOverwrite( instance->state, 1+keySizeInBits/8+1+nonceSizeInBits/8, smallData, 1 );
KeccakP400_AddByte(instance->state, 0x80, KeccakP400_width / 8 - 1 );
keccakP400NRounds(instance->state, Ket_StartRounds );
return 0;
}
int Ketje_FeedAssociatedData(Ketje_Instance *instance, const unsigned char *data, unsigned int dataSizeInBytes)
{
unsigned int size;
if ((instance->phase & Ketje_Phase_FeedingAssociatedData) == 0)
return 1;
if ( (instance->dataRemainderSize + dataSizeInBytes) > Ketje_BlockSize )
{
if (instance->dataRemainderSize != 0)
{
dataSizeInBytes -= Ketje_BlockSize - instance->dataRemainderSize;
while ( instance->dataRemainderSize != Ketje_BlockSize )
KeccakP400_AddByte( instance->state, *(data++), instance->dataRemainderSize++ );
Ket_Step( instance->state, Ketje_BlockSize, FRAMEBITS00 );
instance->dataRemainderSize = 0;
}
if ( dataSizeInBytes > Ketje_BlockSize )
{
size = ((dataSizeInBytes + (Ketje_BlockSize - 1)) & ~(Ketje_BlockSize - 1)) - Ketje_BlockSize;
Ket_FeedAssociatedDataBlocks( instance->state, data, size / Ketje_BlockSize);
dataSizeInBytes -= size;
data += size;
}
}
while ( dataSizeInBytes-- != 0 )
KeccakP400_AddByte( instance->state, *(data++), instance->dataRemainderSize++ );
return 0;
}
int Ketje_WrapPlaintext(Ketje_Instance *instance, const unsigned char *plaintext, unsigned char *ciphertext, unsigned int dataSizeInBytes )
{
unsigned int ciphertext_size = 0;
unsigned int size;
unsigned char temp;
if ( (instance->phase & Ketje_Phase_FeedingAssociatedData) != 0)
{
Ket_Step( instance->state, instance->dataRemainderSize, FRAMEBITS01 );
instance->dataRemainderSize = 0;
instance->phase = Ketje_Phase_Wrapping;
}
if ( (instance->phase & Ketje_Phase_Wrapping) == 0)
return 1;
if ( (instance->dataRemainderSize + dataSizeInBytes) > Ketje_BlockSize )
{
// More than a block
if (instance->dataRemainderSize != 0)
{
// Process data remainder
while ( instance->dataRemainderSize < Ketje_BlockSize )
{
temp = *(plaintext++);
*(ciphertext++) = temp ^ Ket_StateExtractByte( instance->state, instance->dataRemainderSize );
ciphertext_size++;
KeccakP400_AddByte( instance->state, temp, instance->dataRemainderSize++ );
--dataSizeInBytes;
}
Ket_Step( instance->state, Ketje_BlockSize, FRAMEBITS11 );
instance->dataRemainderSize = 0;
}
// Wrap multiple blocks except last.
if ( dataSizeInBytes > Ketje_BlockSize )
{
size = ((dataSizeInBytes + (Ketje_BlockSize - 1)) & ~(Ketje_BlockSize - 1)) - Ketje_BlockSize;
ciphertext_size += Ket_WrapBlocks( instance->state, plaintext, ciphertext, size / Ketje_BlockSize );
dataSizeInBytes -= size;
plaintext += size;
ciphertext += size;
}
}
// Add remaining data
while ( dataSizeInBytes-- != 0 )
{
temp = *(plaintext++);
*(ciphertext++) = temp ^ Ket_StateExtractByte( instance->state, instance->dataRemainderSize );
ciphertext_size++;
KeccakP400_AddByte( instance->state, temp, instance->dataRemainderSize++ );
}
return ciphertext_size;
}
int Ketje_UnwrapCiphertext(Ketje_Instance *instance, const unsigned char *ciphertext, unsigned char *plaintext, unsigned int dataSizeInBytes)
{
unsigned int size;
unsigned char temp;
if ( (instance->phase & Ketje_Phase_FeedingAssociatedData) != 0)
{
Ket_Step( instance->state, instance->dataRemainderSize, FRAMEBITS01 );
instance->dataRemainderSize = 0;
instance->phase = Ketje_Phase_Unwrapping;
}
if ( (instance->phase & Ketje_Phase_Unwrapping) == 0)
return 1;
if ( (instance->dataRemainderSize + dataSizeInBytes) > Ketje_BlockSize )
{
// More than a block
if (instance->dataRemainderSize != 0)
{
// Process data remainder
while ( instance->dataRemainderSize < Ketje_BlockSize )
{
temp = *(ciphertext++) ^ Ket_StateExtractByte( instance->state, instance->dataRemainderSize );
*(plaintext++) = temp;
KeccakP400_AddByte( instance->state, temp, instance->dataRemainderSize++ );
--dataSizeInBytes;
}
Ket_Step( instance->state, Ketje_BlockSize, FRAMEBITS11 );
instance->dataRemainderSize = 0;
}
// Unwrap multiple blocks except last.
if ( dataSizeInBytes > Ketje_BlockSize )
{
size = ((dataSizeInBytes + (Ketje_BlockSize - 1)) & ~(Ketje_BlockSize - 1)) - Ketje_BlockSize;
Ket_UnwrapBlocks( instance->state, ciphertext, plaintext, size / Ketje_BlockSize );
dataSizeInBytes -= size;
plaintext += size;
ciphertext += size;
}
}
// Add remaining data
while ( dataSizeInBytes-- != 0 )
{
temp = *(ciphertext++) ^ Ket_StateExtractByte( instance->state, instance->dataRemainderSize );
*(plaintext++) = temp;
KeccakP400_AddByte( instance->state, temp, instance->dataRemainderSize++ );
}
return 0;
}
int Ketje_GetTag(Ketje_Instance *instance, unsigned char *tag, unsigned int tagSizeInBytes)
{
unsigned int tagSizePart;
unsigned int i;
if ((instance->phase & (Ketje_Phase_Wrapping | Ketje_Phase_Unwrapping)) == 0)
return 1;
KeccakP400_AddByte(instance->state, FRAMEBITS10, instance->dataRemainderSize);
KeccakP400_AddByte(instance->state, 0x08, Ketje_BlockSize); //padding
keccakP400NRounds(instance->state, Ket_StrideRounds );
instance->dataRemainderSize = 0;
tagSizePart = Ketje_BlockSize;
if ( tagSizeInBytes < Ketje_BlockSize )
tagSizePart = tagSizeInBytes;
for ( i = 0; i < tagSizePart; ++i )
*(tag++) = Ket_StateExtractByte( instance->state, i );
tagSizeInBytes -= tagSizePart;
while(tagSizeInBytes > 0)
{
Ket_Step( instance->state, 0, FRAMEBITS0 );
tagSizePart = Ketje_BlockSize;
if ( tagSizeInBytes < Ketje_BlockSize )
tagSizePart = tagSizeInBytes;
for ( i = 0; i < tagSizePart; ++i )
*(tag++) = Ket_StateExtractByte( instance->state, i );
tagSizeInBytes -= tagSizePart;
}
instance->phase = Ketje_Phase_FeedingAssociatedData;
return 0;
}
void print_in_hex_len(unsigned char* t, int len){
int i =0;
for (i = 0; i < len; i++){
printf("%x ", t[i]);
}
printf("\n");
}
static void displayByteString(FILE *f, const char* synopsis, const unsigned char *data, unsigned int length)
{
unsigned int i;
fprintf(f, "%s:", synopsis);
for(i=0; i<length; i++)
fprintf(f, " %02x", (unsigned int)data[i]);
fprintf(f, "\n");
}
void generateSimpleRawMaterial(unsigned char* data, unsigned int length, unsigned char seed1, unsigned int seed2)
{
unsigned int i;
for( i=0; i<length; i++) {
unsigned int iRolled = i*seed1;
unsigned char byte = (iRolled+length+seed2)%0xFF;
data[i] = byte;
}
}
void dynamic_test(){
//376 for ketjeSr
int keySizeInBits = 0; int keyMaxSizeInBits = 376;
#ifdef OUTPUT
FILE *f = fopen("dynamic_test_ref_Sr.txt", "w");
#endif
for( keySizeInBits=keyMaxSizeInBits; keySizeInBits >=96; keySizeInBits -= (keySizeInBits > 200) ? 96 : ((keySizeInBits > 128) ? 24 : 16)){
int nonceMaxSizeInBits = keyMaxSizeInBits - keySizeInBits;
int nonceSizeInBits;
for(nonceSizeInBits = nonceMaxSizeInBits; nonceSizeInBits >= ((keySizeInBits < 112) ? 0 : nonceMaxSizeInBits); nonceSizeInBits -= (nonceSizeInBits > 128) ? 160 : 64){
Ketje_Instance ketje1; memset(&ketje1, 0, sizeof(Ketje_Instance));
Ketje_Instance ketje2; memset(&ketje2, 0, sizeof(Ketje_Instance));
unsigned char key[50], nonce[50]; memset(key, 0, 50*sizeof(unsigned char)); memset(nonce, 0, 50*sizeof(unsigned char));
unsigned int ADlen; unsigned int keySize1; unsigned int nonceSize1;
keySize1 = keySizeInBits / 8; nonceSize1 = nonceSizeInBits / 8;
generateSimpleRawMaterial(key, keySize1, 0x12+nonceSizeInBits, SnP_width);
generateSimpleRawMaterial(nonce, nonceSize1, 0x23+keySizeInBits, SnP_width);
Ketje_Initialize(&ketje1, key, keySizeInBits, nonce, nonceSizeInBits);
Ketje_Initialize(&ketje2, key, keySizeInBits, nonce, nonceSizeInBits);
#ifdef OUTPUT
fprintf(f, "***\n");
fprintf(f, "initialize with key of %u bits, nonce of %u bits:\n", keySizeInBits, nonceSizeInBits);
displayByteString(f, "key", key, keySizeInBits/8);
displayByteString(f, "nonce", nonce, nonceSizeInBits/8);
fprintf(f, "\n");
#endif
unsigned int Nlen;
for( ADlen=12; ADlen<40; ADlen++){
for( Nlen=49-ADlen; Nlen> 0 ; Nlen--){
unsigned char associatedData[400], plaintext[400], ciphertext[400];
unsigned char plaintextPrime[400], tag1[16], tag2[16];
generateSimpleRawMaterial(associatedData, ADlen, 0x34+ Nlen, 3);
generateSimpleRawMaterial(plaintext, Nlen, 0x45+ ADlen, 4);
Ketje_FeedAssociatedData(&ketje1, associatedData, ADlen);
Ketje_FeedAssociatedData(&ketje2, associatedData, ADlen);
unsigned int ciphertext_size = Ketje_WrapPlaintext(&ketje1, plaintext, ciphertext, Nlen);
Ketje_UnwrapCiphertext(&ketje2, ciphertext, plaintextPrime, ciphertext_size);
Ketje_GetTag(&ketje1, tag1, 16);
Ketje_GetTag(&ketje2, tag2, 16);
if (memcmp(tag1, tag2, 16) != 0 ){
printf("tag1: "); print_in_hex_len(tag1, 16);
printf("tag2: "); print_in_hex_len(tag2, 16);
printf("\n");
}
#ifdef OUTPUT
displayByteString(f, "associated data", associatedData, ADlen);
displayByteString(f, "plaintext", plaintext, Nlen);
displayByteString(f, "ciphertext", ciphertext, ciphertext_size);
displayByteString(f, "tag 1", tag1, 16);
displayByteString(f, "tag 2", tag2, 16);
fprintf(f, "\n");
#endif
}
}
}
}
#ifdef OUTPUT
fclose(f);
printf("Log wrote to dynamic_test_ref_Sr.txt\n");
#endif
}
int main(){
dynamic_test();
return 0;
} |
the_stack_data/31387332.c | /*k&r exercise 4-13
this uncommented solution of mine uses another string to store the reversed string
found a solution at https://clc-wiki.net/wiki/K%26R2_solutions:Chapter_4:Exercise_13 where s[] itself is reversed
snippet kept below in commented form
The commented snippet uses the indexes of the array to reverse
*/
#include <stdio.h>
#include <string.h>
#define MAXLENGTH 100
void reverse(char s[],char t[],int pos);
void main(){
int i,c;
char s[MAXLENGTH],t[MAXLENGTH];
i=0;
while ((c=getchar())!='\n' && i<MAXLENGTH){
s[i++]=c;
}
s[i]='\0';
reverse(s,t,0);
t[strlen(s)]='\0';
for (i=0;i<strlen(t);i++){
printf("%c",t[i]);
}
}
void reverse(char s[], char t[], int pos){
if(s[pos]!='\0'){
reverse(s,t,pos+1);
t[strlen(s)-1-pos]=s[pos];
}
}
/*void reverse(char s[], int l, int r){ //reverse from l(left) to r(right) in array s
int c;
if (l < r) {
reverse(s, l+1, r-1);
c = s[l];
s[l] = s[r];
s[r] = c;
}
}*/ |
the_stack_data/184517045.c | #include <stdio.h>
int main(){
int n;
scanf("%d",&n);
if (n%2 == 0){
printf("O numero %d e par", &n);
}else{
printf("O numero %d e impar", n);
}
}
|
the_stack_data/173576793.c | #include <stdio.h>
int main(void) {
float r;
printf("Please input the r of the ball: ");
scanf("%f", &r);
float v = 4.0f / 3.0f * r * r * r * 3.14;
printf("The ball volume is %.4f\n", v);
return 0;
}
|
the_stack_data/178266065.c | #include <time.h>
time_t time(time_t *t)
{
struct timespec ts;
__clock_gettime(CLOCK_REALTIME, &ts);
if (t) *t = ts.tv_sec;
return ts.tv_sec;
}
|
the_stack_data/153269048.c | // File: hw5.c
// Solution by Chris Turgeon
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define BUF 128 // ASSUMPTION: LINE BUFFER SIZE
#define LEN 5 // ASSUMPTION: # OF LINES
typedef enum { false, true } bool;
struct stall {
char stall_reg[4]; // Duplicate register.
int instruc_type; // int code for instruction.
int line_occur; // Line number where data dependency lies.
int line_cause; // Line number where data comes from.
int out[10]; // Array to output nops row. 9th index turns on output.
int num_nops; // Number of nops that should be
}; // printed per dependency.
// This function advances an instruction to its next stage.
void update_cycles(int data[LEN][14], int stage_cnt, int curr) {
// Update current instruction for next stage.
if ( stage_cnt < curr || data[curr][12] == 1 ) {
return;
} else {
int idx = data[curr][11];
if ( curr != 0 ) { // If not instruction one.
if ( data[curr][idx - 1] != 5 ) {
data[curr][idx] = data[curr][idx - 1] + 1;
data[curr][11]++;
}
} else { // If instruction one.
data[curr][idx + 1] = data[curr][idx] + 1;
data[curr][11]++;
}
}
}
// Counts the number of a desired register in the input code. Takes in the
// starting line and searches down for it.
int count_reg(char input[LEN][BUF], int start_instruc, int instruc_cnt, char reg[4]) {
int cnt = 0;
int i, j;
for (i = start_instruc; i < instruc_cnt; i++) {
// Advance past left most register.
int tmp = 0;
while ( input[i][tmp] != '$' ) {
tmp++;
}
tmp++;
for (j = tmp; input[i][j] != '\0'; j++) {
bool char_match_one = false;
bool char_match_two = false;
if ( input[i][j] == '$' ) {
char_match_one = input[i][j+1] == reg[1];
char_match_two = input[i][j+2] == reg[2];
}
if ( char_match_one && char_match_two ) {
cnt++;
}
}
}
return cnt;
}
// This function stalls an instruction until it has the available data.
// It gets called while waiting for WB from dependency instruction.
void update_stall_cycles(int data[LEN][14], int instruc_num,
int instruc_cnt, int cause_line, int stage_cnt) {
// Find location of WB in the dependency cause line
int loc = 0;
while (data[cause_line][loc] != 1) {
loc++;
}
loc += 4;
// Update stall causing instruction to get to WB.
if ( data[cause_line][loc-1] == 4 ) {
data[cause_line][loc] = 5;
}
int i, j;
for (i = instruc_num; i < instruc_cnt; i++) {
j = 0;
while (data[i][j] == 0) { // Advance to IF
j++;
}
while (data[i][j] != 0) { // Advance to end of stages.
j++;
}
// For the first nop print, decrement value and turn
// on the output int and the first done int.
if ( data[i][13] == 0 ) {
data[i][j-1]--;
data[i][13] = 1;
data[i][12] = 1;
} else {
if ( j - 1 < loc ) { // If loc not at WB, repeat stage.
if ( data[i][j-1] == data[i][j-2] ) {
data[i][j] = data[i][j-1];
data[i][11]++;
}
}
else if ( j - 1 == loc ) { // Advance stage.
data[i][j] = data[i][j-1] + 1;
data[i][11]++;
} else { // Call function to advance stage.
data[i][12] = 0;
update_cycles(data, stage_cnt, i);
}
}
}
}
// Returns the index within an instruction output when it finds desired stage.
int find_index(int data[LEN][14], int instruc_code, int instruc_num) {
int i;
for (i = 0; i < 9; i++) {
if ( data[instruc_num][i] == instruc_code ) {
return i;
}
}
return -1;
}
// This function searches an instruction to see if it has activated a stage.
bool search_instruc(int data[LEN][14], int instruc_code, int instruc_num) {
int i;
for (i = 0; i < 9; i++) {
if ( data[instruc_num][i] == instruc_code ) {
return true;
}
}
return false;
}
// This function updates the nops by adding IF ID and *'s'
void update_nop(int nop_data[9], int starting_idx) {
int i = starting_idx;
int col_cnt = 0;
while ( nop_data[i] != 0 ) {
// Count the number of stages in the nop.
if (nop_data[i] != 0) {
col_cnt++;
}
// Return if 5 stages of nop done.
if ( col_cnt == 5 ) {
return;
}
i++;
}
// Add a '*' to nop output
nop_data[i] = 6;
}
// This function initializes the nop at the starting index provided.
void initialize_nop(int nop_data[9], int starting_idx) {
if ( nop_data[starting_idx] != 0 ) {
return;
}
nop_data[starting_idx] = 1; // IF
nop_data[starting_idx+1] = 2; // ID
nop_data[starting_idx+2] = 6; // *
}
int main( int argc, char *argv[] ) {
// Check to make sure that there are proper number of arguments.
if ( argc != 2 ) {
perror("Error: Invalid Number of Arguments!");
return EXIT_FAILURE;
}
// Open file and check to see if it's opened correctly.
FILE *file;
if ( (file = fopen(argv[1], "r")) == NULL ) {
perror("Error: Inavlid Input File!\n");
return EXIT_FAILURE;
}
// Array to hold stages.
char *processes[7] = { ".", "IF", "ID", "EX", "MEM", "WB", "*" };
// Ouput array to be updated.
int output[LEN][14];
int x, y;
for (x = 0; x < LEN; x++) {
for (y = 0; y < 12; y++) {
output[x][y] = 0;
}
output[x][11] = x;
}
output[0][0] = 1;
/* For the first 9 digits in the 14 digit array
* 0 - indicates period - "."
* 1 - indicates IF
* 2 - indicates ID
* 3 - indicates EX
* 4 - indicated MEM
* 5 - indicates WB
* 6 - indicates *
*/
/* For the 10th integer in the 14 digit array
* 0 - add
* 1 - sub
* 2 - and
* 3 - or
* 4 - lw
* 5 - sw
*/
/* For the 11th digit in the 14 digit array
* -1 - indicates row is complete
For the 12th digit in the 14 digit array
* - indicates the starting index and IF location
For the 13th digit in the 14 digit array
* 1 - indicates that the update_stalls func should not update
For 14th digit, 1 indicates first op has been completed
*/
// Needed for input.
int i = 0;
char input_code[LEN][BUF];
char buffer[BUF];
while ( fgets(buffer, BUF, file) ) {
// Assign proper integer to represent instruction.
if ( buffer[0] == 'a' && buffer[1] == 'd' && buffer[2] == 'd' )
output[i][9] = 0;
else if ( buffer[0] == 's' && buffer[1] == 'u' && buffer[2] == 'b' )
output[i][9] = 1;
else if ( buffer[0] == 'a' && buffer[1] == 'n' && buffer[2] == 'd' )
output[i][9] = 2;
else if ( buffer[0] == 'o' && buffer[1] == 'r' )
output[i][9] = 3;
else if ( buffer[0] == 'l' && buffer[1] == 'w' )
output[i][9] = 4;
else
output[i][9] = 5;
// Read in the file line-by-line; replace \n with \0.
output[i][12] = 0;
output[i][13] = 0;
buffer[strlen(buffer) - 1] = '\0';
strcpy(input_code[i], buffer);
i++;
}
int instruc_cnt = i;
///// ///// ///// ///// ///// ///// ///// ///// ///// ///// /////
/* SEARCH FOR STALLS AND STORE THEIR INFORMATION */
///// ///// ///// ///// ///// ///// ///// ///// ///// ///// /////
int stall_cnt = 0;
struct stall stalls[LEN];
// Loop through the input code and search for register duplicates.
for (i = 0; i < instruc_cnt; i++) {
// Find the first register.
int reg_one_idx = 0;
while ( input_code[i][reg_one_idx] != '$' ) {
reg_one_idx++;
}
// Store the register as a string.
char reg[4];
reg[0] = input_code[i][reg_one_idx];
reg[1] = input_code[i][reg_one_idx + 1];
reg[2] = input_code[i][reg_one_idx + 2];
reg[3] = '\0';
// Search through lower instrutions for the same, stall-causing register.
int instruc;
for (instruc = i + 1; instruc < instruc_cnt; instruc++) {
// Move to the next instruction if dependency line is too far below.
if ( instruc - i >= 3 ) {
continue;
}
// If instruction is not lw or sw, then skip past left-most register.
int tmp = 0;
if ( (output[instruc][9] != 4) || (output[instruc][9] != 5) ) {
while ( input_code[instruc][tmp] != '$' ) {
tmp++;
}
tmp++;
}
// Compare the stored register with the found one.
int j;
for (j = tmp; input_code[instruc][j] != '\0'; j++) {
bool char_match_one = false;
bool char_match_two = false;
if ( input_code[instruc][j] == '$' ) {
char_match_one = input_code[instruc][j+1] == reg[1];
char_match_two = input_code[instruc][j+2] == reg[2];
}
// Construct stall struct object and add to array.
if ( char_match_one && char_match_two ) {
// Search to see if there are multiple dependencies on one register.
bool found_duplicate = false;
int tmp, dup_index;
for (tmp = 0; tmp < stall_cnt; tmp++) {
if ( stalls[tmp].line_cause == i ) {
dup_index = tmp;
found_duplicate = true;
}
}
// Create a new unique stall and assign values.
if ( !found_duplicate ) {
strcpy( stalls[stall_cnt].stall_reg, reg);
stalls[stall_cnt].instruc_type = output[i][9];
stalls[stall_cnt].line_occur = instruc;
stalls[stall_cnt].line_cause = i;
// Dependency occurs in the next line and there are less than 2.
int reg_cnt = count_reg(input_code, instruc, instruc_cnt, reg);
if ( (instruc - i == 1) && reg_cnt < 2 ) {
stalls[stall_cnt].num_nops = 2;
} else { // Dependency occurs in later line.
stalls[stall_cnt].num_nops = 1;
}
// Initialize all values to 0.
int k;
for (k = 0; k < 9; k++) {
stalls[stall_cnt].out[k] = 0;
}
stalls[stall_cnt].out[9] = 0;
stall_cnt++;
}
// Increment stall count for already found dependency.
else {
stalls[dup_index].num_nops += 1;
}
}
}
}
}
///// ///// ///// ///// ///// ///// ///// ///// ///// ///// /////
/* BEGIN OUTPUT OF THE MIPS PIPELINE */
///// ///// ///// ///// ///// ///// ///// ///// ///// ///// /////
int stage_cnt = 1; // Keep track of current stage.
printf("START OF SIMULATION\n\n");
bool done_pipelining = false;
while ( !done_pipelining ) {
// Print cycle numbers.
printf("CPU Cycles ===>\t");
int cycle;
for (cycle = 1; cycle != 10; cycle++) {
if ( cycle < 9 ) { printf("%d\t", cycle); }
else { printf("%d\n", cycle); }
}
bool finished_curr_stage = false;
while ( !finished_curr_stage ) {
// Print current instruction MIPS code.
for (i = 0; i < instruc_cnt; i++) {
printf("%s\t\t", input_code[i]);
// Loop through current instruction and print stages.
int j;
for (j = 0; j < 9; j++) {
// Update -1 status to indicate row is complete, found WB.
if ( output[i][j] == 5 ) {
output[i][10] = -1;
}
if ( j < 8 ) {
printf("%s", processes[ output[i][j] ]);
printf("\t");
} else {
printf("%s", processes[ output[i][j] ]);
printf("\n");
}
}
///// ///// ///// ///// ///// ///// ///// /////
/* DETERMINE IF STALLS ARE NEEDED HERE */
///// ///// ///// ///// ///// ///// ///// /////
for (j = 0; j < stall_cnt; j++) {
/* "at_ID" checks to see if the stall-waiting line has reached ID stage.
* "WB_done" checks to see if the stall-causing line has written back.
* "at_stall" location determined by top-most dependency.
*/
bool at_ID = search_instruc(output, 2, stalls[j].line_occur);
bool WB_done = output[ stalls[j].line_cause ][10] == -1;
bool at_stall = (i == stalls[j].line_occur - 1);
/* Find the starting index to initialize stall object for output.
* Initialize the IF ID * if needed, then print, then update the
* nop instruction to fill in additional *'s if needed.
*/
if ( stalls[j].out[9] == 1 && at_stall ) {
int idx_start = find_index(output, 1, stalls[j].line_occur);
initialize_nop(stalls[j].out, idx_start);
// Print out the proper number of nops.
int num_nops;
for (num_nops = 0; num_nops < stalls[j].num_nops; num_nops++) {
printf("nop\t\t");
int k;
for (k = 0; k < 8; k++) {
printf("%s\t", processes[ stalls[j].out[k] ] );
}
printf("%s\n", processes[ stalls[j].out[k] ]);
}
update_nop(stalls[j].out, idx_start);
update_stall_cycles(output, i + 1, instruc_cnt, stalls[j].line_cause, stage_cnt);
}
// Turn on output for stall.
if ( at_stall && !WB_done && at_ID ) {
stalls[j].out[9] = 1;
}
}
// Update the output to be ready for next stage.
if ( output[i][10] != -1 ) {
update_cycles(output, stage_cnt, i);
}
}
finished_curr_stage = true;
}
printf("\n");
stage_cnt++;
// Pipeline complete when last instruction completely printed.
if ( output[instruc_cnt - 1][10] == -1 ) {
printf("END OF SIMULATION\n");
done_pipelining = true;
}
}
return EXIT_SUCCESS;
} |
the_stack_data/237642946.c | #include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <string.h>
#define READ 0
#define WRITE 1
#define MAX_BUFFER 50
int main(void) {
int fd[2];
pid_t pid;
pipe(fd);
pid = fork();
if (pid >0) {
char a[2][50];
printf("PARENT:\n");
printf("x y ? ");
scanf("%s %s",&a[0],&a[1]);
printf("%s\n",a[0]);
close(fd[READ]);
write(fd[WRITE],a,MAX_BUFFER*2);
close(fd[WRITE]);
}
else {
char b[2][50];
close(fd[WRITE]);
read(fd[READ],b,2*MAX_BUFFER);
printf("SON:\n");
printf("x + y = %d\n", atoi(b[0])+atoi(b[1]));
printf("x - y = %d\n",atoi(b[0])-atoi(b[1]));
printf("x * y = %d\n",atoi(b[0])*atoi(b[1]));
if(strcmp(b[1],"0") == 0)
printf("x / y = 0\n");
else
printf("x / y = %d\n",atoi(b[0])/atoi(b[1]));
close(fd[READ]);
}
return 0;
} |
the_stack_data/175142941.c | #include <stddef.h>
#include <stdint.h>
static inline void mmio_write(uint32_t reg, uint32_t data)
{
*(volatile uint32_t*)reg = data;
}
static inline uint32_t mmio_read(uint32_t reg)
{
return *(volatile uint32_t*)reg;
}
// Loop <delay> times in a way that the compiler won't optimize away
static inline void delay(int32_t count)
{
asm volatile("__delay_%=: subs %[count], %[count], #1; bne __delay_%=\n"
: "=r"(count): [count]"0"(count) : "cc");
}
enum
{
// The GPIO registers base address.
GPIO_BASE = 0x3F200000, // for raspi2 & 3, 0x20200000 for raspi1
GPPUD = (GPIO_BASE + 0x94),
GPPUDCLK0 = (GPIO_BASE + 0x98),
// The base address for UART.
UART0_BASE = 0x3F201000, // for raspi2 & 3, 0x20201000 for raspi1
UART0_DR = (UART0_BASE + 0x00),
UART0_RSRECR = (UART0_BASE + 0x04),
UART0_FR = (UART0_BASE + 0x18),
UART0_ILPR = (UART0_BASE + 0x20),
UART0_IBRD = (UART0_BASE + 0x24),
UART0_FBRD = (UART0_BASE + 0x28),
UART0_LCRH = (UART0_BASE + 0x2C),
UART0_CR = (UART0_BASE + 0x30),
UART0_IFLS = (UART0_BASE + 0x34),
UART0_IMSC = (UART0_BASE + 0x38),
UART0_RIS = (UART0_BASE + 0x3C),
UART0_MIS = (UART0_BASE + 0x40),
UART0_ICR = (UART0_BASE + 0x44),
UART0_DMACR = (UART0_BASE + 0x48),
UART0_ITCR = (UART0_BASE + 0x80),
UART0_ITIP = (UART0_BASE + 0x84),
UART0_ITOP = (UART0_BASE + 0x88),
UART0_TDR = (UART0_BASE + 0x8C),
};
void uart_init()
{
mmio_write(UART0_CR, 0x00000000);
mmio_write(GPPUD, 0x00000000);
delay(150);
mmio_write(GPPUDCLK0, (1 << 14) | (1 << 15));
delay(150);
mmio_write(GPPUDCLK0, 0x00000000);
mmio_write(UART0_ICR, 0x7FF);
mmio_write(UART0_IBRD, 1);
mmio_write(UART0_FBRD, 40);
mmio_write(UART0_LCRH, (1 << 4) | (1 << 5) | (1 << 6));
mmio_write(UART0_IMSC, (1 << 1) | (1 << 4) | (1 << 5) | (1 << 6) |
(1 << 7) | (1 << 8) | (1 << 9) | (1 << 10));
mmio_write(UART0_CR, (1 << 0) | (1 << 8) | (1 << 9));
}
void uart_putc(unsigned char c)
{
while ( mmio_read(UART0_FR) & (1 << 5) ) { }
mmio_write(UART0_DR, c);
}
unsigned char uart_getc()
{
while ( mmio_read(UART0_FR) & (1 << 4) ) { }
return mmio_read(UART0_DR);
}
void uart_puts(const char* str)
{
for (size_t i = 0; str[i] != '\0'; i ++)
uart_putc((unsigned char)str[i]);
}
void kernel_main(uint32_t r0, uint32_t r1, uint32_t atags)
{
(void) r0;
(void) r1;
(void) atags;
uart_init();
uart_puts("Hello, kernel World!\r\n");
while (1) {
uart_putc(uart_getc());
uart_putc('\n');
}
}
|
the_stack_data/27240.c | void *malloc(__CPROVER_size_t);
void use_str(char *s)
{
assert(__CPROVER_is_zero_string(s));
}
int main(int argc, char *argv[])
{
unsigned short len;
char *str;
__CPROVER_assume(len > 0);
str = malloc(len);
__CPROVER_assume(__CPROVER_buffer_size(str) == len);
str[len - 1] = '\0';
// string abstraction takes care of this
// __CPROVER_is_zero_string(str) = 1;
// __CPROVER_zero_string_length(str) = len - 1;
use_str(str);
return 0;
}
|
the_stack_data/45450945.c | #include <stdio.h>
#include <stdlib.h>
int main()
{
// DETERMINING GIVEN NUMBER WHETHER DIVISIBLE BY 9 OR NOT
int num, mod;
int total = 0;
printf("Enter an integer:\n");
scanf("%d", &num);
printf("\n");
while (num > 0) {
mod = num % 10;
total += mod;
num = num / 10;
}
printf("Sum of the digits: %d\n", total);
if (total % 9 == 0) {
printf("\nDivisible by 9: Yes\n");
}
else if (total % 9 != 0) {
printf("\nDivisible by 9: No\n");
}
}
|
the_stack_data/67325704.c | #include <stdio.h>
int main(void)
{
int x,y,area;
printf("X value: ");
scanf("%d",&x);
printf("Y value: ");
scanf("%d",&y);
if (x > 0 && y > 0)
{
area = 1;
}
else if (x < 0 && y > 0)
{
area = 2;
}
else if (x < 0 && y < 0)
{
area = 3;
}
else if (x > 0 && y < 0)
{
area = 4;
}
switch(area)
{
case 1:
printf("1사분면\n");
break;
case 2:
printf("2사분면\n");
break;
case 3:
printf("3사분면\n");
break;
case 4:
printf("4사분면\n");
break;
default:
printf("Invalid value\n");
break;
}
return 0;
}
|
the_stack_data/144368.c | // RUN: %clang_cc1 -x c -triple x86_64-pc-linux-gnu -dwarf-version=4 -fsyntax-only -verify %s
#define __tag1 __attribute__((btf_tag("tag1")))
#define __tag2 __attribute__((btf_tag("tag2")))
#define __tag3 __attribute__((btf_tag("tag3")))
#define __tag_no_arg __attribute__((btf_tag()))
#define __tag_2_arg __attribute__((btf_tag("tag1", "tag2")))
#define __invalid __attribute__((btf_tag(1)))
struct __tag1 __tag2 t1;
struct t1 {
int a __tag1;
} __tag3;
struct __tag1 t2;
struct __tag2 __tag3 t2 {
int a __tag1;
};
int g1 __tag1;
int g2 __tag_no_arg; // expected-error {{'btf_tag' attribute takes one argument}}
int g3 __tag_2_arg; // expected-error {{'btf_tag' attribute takes one argument}}
int i1 __invalid; // expected-error {{'btf_tag' attribute requires a string}}
enum e1 {
E1
} __tag1; // expected-error {{'btf_tag' attribute only applies to variables, functions, structs, unions, classes, and non-static data members}}
enum e2 {
E2
} __tag_no_arg; // expected-error {{'btf_tag' attribute only applies to variables, functions, structs, unions, classes, and non-static data members}}
enum e3 {
E3
} __tag_2_arg; // expected-error {{'btf_tag' attribute only applies to variables, functions, structs, unions, classes, and non-static data members}}
int __tag1 __tag2 foo(struct t1 *arg, struct t2 *arg2);
int __tag2 __tag3 foo(struct t1 *arg, struct t2 *arg2);
int __tag1 foo(struct t1 *arg __tag1, struct t2 *arg2) {
return arg->a + arg2->a;
}
|
the_stack_data/502644.c | /* qsort: sort v[left]...v[right] into increasing order */
void qsort(int v[], int left, int right)
{
int i, last;
void swap(int v[], int i, int j);
if (left >= right) /* do nothing if array contains */
return; /* fewer than two elements */
swap(v, left, (left + right)/2); /* move partition elem */
last = left; /* to v[0] */
for (i = left + 1; i <= right; i++) /* partition */
if (v[i] < v[left])
swap(v, ++last, i);
swap(v, left, last); /* restore partition elem */
qsort(v, left, last-1);
qsort(v, last+1, right);
}
|
the_stack_data/43887334.c | /* this tests whether we can use a shared writeable mmap on a file -
as needed for the mmap varient of FAST_SHARE_MODES */
#if defined(HAVE_UNISTD_H)
#include <unistd.h>
#endif
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#define DATA "conftest.mmap"
#ifndef MAP_FILE
#define MAP_FILE 0
#endif
main()
{
int *buf;
int i;
int fd = open(DATA,O_RDWR|O_CREAT|O_TRUNC,0666);
int count=7;
if (fd == -1) exit(1);
for (i=0;i<10000;i++) {
write(fd,&i,sizeof(i));
}
close(fd);
if (fork() == 0) {
fd = open(DATA,O_RDWR);
if (fd == -1) exit(1);
buf = (int *)mmap(NULL, 10000*sizeof(int),
(PROT_READ | PROT_WRITE),
MAP_FILE | MAP_SHARED,
fd, 0);
while (count-- && buf[9124] != 55732) sleep(1);
if (count <= 0) exit(1);
buf[1763] = 7268;
exit(0);
}
fd = open(DATA,O_RDWR);
if (fd == -1) exit(1);
buf = (int *)mmap(NULL, 10000*sizeof(int),
(PROT_READ | PROT_WRITE),
MAP_FILE | MAP_SHARED,
fd, 0);
if (buf == (int *)-1) exit(1);
buf[9124] = 55732;
while (count-- && buf[1763] != 7268) sleep(1);
unlink(DATA);
if (count > 0) exit(0);
exit(1);
}
|
the_stack_data/94595.c | /* $NetBSD: fnmatch.c,v 1.11 1995/02/27 03:43:06 cgd Exp $ */
/*
* Copyright (c) 1989, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Guido van Rossum.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. 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.
*/
#if defined(LIBC_SCCS) && !defined(lint)
#if 0
static char sccsid[] = "@(#)fnmatch.c 8.2 (Berkeley) 4/16/94";
#else
static char rcsid[] = "$NetBSD: fnmatch.c,v 1.11 1995/02/27 03:43:06 cgd Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
/*
* Function fnmatch() as specified in POSIX 1003.2-1992, section B.6.
* Compares a filename or pathname to a pattern.
*/
#include <fnmatch.h>
#include <string.h>
#define EOS '\0'
static const char *rangematch (const char *, int, int);
int
fnmatch(const char *pattern, const char *string, int flags)
{
const char *stringstart;
char c, test;
for (stringstart = string;;)
switch (c = *pattern++) {
case EOS:
return (*string == EOS ? 0 : FNM_NOMATCH);
case '?':
if (*string == EOS)
return (FNM_NOMATCH);
if (*string == '/' && (flags & FNM_PATHNAME))
return (FNM_NOMATCH);
if (*string == '.' && (flags & FNM_PERIOD) &&
(string == stringstart ||
((flags & FNM_PATHNAME) && *(string - 1) == '/')))
return (FNM_NOMATCH);
++string;
break;
case '*':
c = *pattern;
/* Collapse multiple stars. */
while (c == '*')
c = *++pattern;
if (*string == '.' && (flags & FNM_PERIOD) &&
(string == stringstart ||
((flags & FNM_PATHNAME) && *(string - 1) == '/')))
return (FNM_NOMATCH);
/* Optimize for pattern with * at end or before /. */
if (c == EOS)
if (flags & FNM_PATHNAME)
return (strchr(string, '/') == NULL ?
0 : FNM_NOMATCH);
else
return (0);
else if (c == '/' && flags & FNM_PATHNAME) {
if ((string = strchr(string, '/')) == NULL)
return (FNM_NOMATCH);
break;
}
/* General case, use recursion. */
while ((test = *string) != EOS) {
if (!fnmatch(pattern, string, flags & ~FNM_PERIOD))
return (0);
if (test == '/' && flags & FNM_PATHNAME)
break;
++string;
}
return (FNM_NOMATCH);
case '[':
if (*string == EOS)
return (FNM_NOMATCH);
if (*string == '/' && flags & FNM_PATHNAME)
return (FNM_NOMATCH);
if ((pattern =
rangematch(pattern, *string, flags)) == NULL)
return (FNM_NOMATCH);
++string;
break;
case '\\':
if (!(flags & FNM_NOESCAPE)) {
if ((c = *pattern++) == EOS) {
c = '\\';
--pattern;
}
}
/* FALLTHROUGH */
default:
if (c != *string++)
return (FNM_NOMATCH);
break;
}
/* NOTREACHED */
}
static const char *
rangematch(const char *pattern, int test, int flags)
{
int negate, ok;
char c, c2;
/*
* A bracket expression starting with an unquoted circumflex
* character produces unspecified results (IEEE 1003.2-1992,
* 3.13.2). This implementation treats it like '!', for
* consistency with the regular expression syntax.
* J.T. Conklin ([email protected])
*/
if (negate = (*pattern == '!' || *pattern == '^'))
++pattern;
for (ok = 0; (c = *pattern++) != ']';) {
if (c == '\\' && !(flags & FNM_NOESCAPE))
c = *pattern++;
if (c == EOS)
return (NULL);
if (*pattern == '-'
&& (c2 = *(pattern+1)) != EOS && c2 != ']') {
pattern += 2;
if (c2 == '\\' && !(flags & FNM_NOESCAPE))
c2 = *pattern++;
if (c2 == EOS)
return (NULL);
if (c <= test && test <= c2)
ok = 1;
} else if (c == test)
ok = 1;
}
return (ok == negate ? NULL : pattern);
}
|
the_stack_data/133866.c | /* This program demonstrates the working of pipe() system call
*
* Email : [email protected]
* Date : 07.09.2021
* Author : Abinash
*/
#include<stdio.h> /* required for printf */
#include<errno.h> /* required for perror */
#include<unistd.h> /* required for pipe */
#include<stdlib.h> /* required for pipe */
int main()
{
int fd[2]; /* integer array to hold the file descriptor values of pipe */
int status;
status = pipe(fd);
if(status < 0) /* checking status to know pipe created */
{
perror("pipe failed");
exit(-1);
}
else
{
printf("Pipe is created successfully...\n");
}
close(fd[0]); /* closing the read end of the pipe */
close(fd[1]); /* closing the write end of the pipe */
return 0;
}
|
the_stack_data/68889091.c | #include <stdio.h>
#define MAX 100
int main(void) {
int arr[MAX], i, j, n, temp, min;
printf("Enter the number of elements : ");
scanf("%d", &n);
for (i = 0; i < n; i++) {
printf("Enter element %d : ", i + 1);
scanf("%d", &arr[i]);
}
//selection sort
for (i = 0; i < n - 1; i++) {
//find the index of smallest element
min = i;
for (j = i + 1; j < n; j++) {
if (arr[min] > arr[j])
min = j;
}
if (i != min) {
temp = arr[i];
arr[i] = arr[min];
arr[min] = temp;
}
}
printf("Sorted list is : ");
for (i = 0; i < n; i++)
printf("%d ", arr[i]);
printf("\n");
}
|
the_stack_data/179830196.c | #include <string.h>
int memcmp(const void *src1, const void *src2, size_t bytes)
{
const unsigned char *s1, *s2;
int result;
s1 = src1;
s2 = src2;
result = 0;
while((bytes > 0) && (result == 0)) {
result = *s1 - *s2;
bytes--;
s1++;
s2++;
}
return result;
}
|
the_stack_data/53795.c | #include <stdio.h>
int main()
{
int a,b,c;
a=5;
b=7;
c=(a+b)*(a-b);
printf("%d\n",c);
}
|
the_stack_data/156392417.c | /* { dg-do preprocess }*/
/* { dg-options "-std=c11 -pedantic-errors" { target c } } */
/* { dg-options "-std=c++17 -pedantic-errors" { target c++ } } */
#define CALL(F, ...) F (7 __VA_OPT__(,) __VA_ARGS__) /* { dg-error "__VA_OPT__ is not available" } */
|
the_stack_data/68888319.c | /* KallistiOS ##version##
thrd_equal.c
Copyright (C) 2014 Lawrence Sebald
*/
#include <threads.h>
int thrd_equal(thrd_t thr0, thrd_t thr1) {
return thr0 == thr1;
}
|
the_stack_data/72012458.c | #include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
char* __randname(char*);
char* mkdtemp(char* template) {
size_t l = strlen(template);
int retries = 100;
if (l < 6 || memcmp(template + l - 6, "XXXXXX", 6)) {
errno = EINVAL;
return 0;
}
do {
__randname(template + l - 6);
if (!mkdir(template, 0700))
return template;
} while (--retries && errno == EEXIST);
memcpy(template + l - 6, "XXXXXX", 6);
return 0;
}
|
the_stack_data/154232.c | #include <limits.h>
extern void exit (int);
int main (void)
{
void *x = ((void *)((unsigned int)INT_MAX + 2));
void *y = ((void *)((unsigned long)LONG_MAX + 2));
if (x >= ((void *)((unsigned int)INT_MAX + 1))
&& x <= ((void *)((unsigned int)INT_MAX + 6))
&& y >= ((void *)((unsigned long)LONG_MAX + 1))
&& y <= ((void *)((unsigned long)LONG_MAX + 6)))
exit (0);
else
abort ();
}
|
the_stack_data/4684.c | //As condicionais incluem o if com o else opcional, assim:
int f()
{
int c;
if (c) { };
}
|
the_stack_data/1005558.c | #include <stdio.h>
int main(void) {
/**
* 윤년 -> 4년마다, 그렇지만 100년 단위일때는 윤년에 해당하지 않도록 한다
* 윤년 -> 400년 단위일때는 어떤 상황이든간에 윤년으로 설정한다
*/
int year = 2016;
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
printf("%d년은 윤년입니다.\n", year);
} else {
printf("%d년은 윤년이 아닙니다.\n", year);
}
return 0;
} |
the_stack_data/43888322.c | #include <stdio.h>
int main(void)
{
float fahr, celsius;
int lower, upper, step;
lower = 0;
upper = 300;
step = 20;
printf("C F\n\n");
for(celsius = upper; celsius >= lower; celsius = celsius - step)
{
fahr = (9.0/5.0) * celsius + 32.0;
printf("%3.0f %6.1f\n", celsius, fahr);
}
return 0;
}
|
the_stack_data/64189.c | int a[20];
int a[];
int main () { return(0);}
|
the_stack_data/404627.c | #include<stdio.h>
int main()
{
int t,n,x;
int i,j,num;
int n1,n2;
scanf("%d",&t);
for(i=0;i<t;i++)
{
num=0;
n1=0;
n2=0;
scanf("%d",&n);
for(j=0;j<n;j++)
{
scanf("%d",&x);
x=x%3;
if(x==0)
num++;
else if(x==1)
n1++;
else
n2++;
}
if(n1<n2)
{
num+=n1;
num+=(n2-n1)/3;
}
else
{
num+=n2;
num+=(n1-n2)/3;
}
printf("%d\n",num);
}
return 0;
}
|
the_stack_data/1113461.c | // KASAN: slab-out-of-bounds Read in bpf_skb_change_head
// https://syzkaller.appspot.com/bug?id=fd6bf14a1604a952f31023f3903bd6a2d9a9482c
// status:fixed
// autogenerated by syzkaller (https://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <arpa/inet.h>
#include <endian.h>
#include <fcntl.h>
#include <net/if.h>
#include <netinet/in.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
#include <sched.h>
#include <linux/genetlink.h>
#include <linux/if_addr.h>
#include <linux/if_link.h>
#include <linux/in6.h>
#include <linux/neighbour.h>
#include <linux/net.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
#include <linux/veth.h>
struct nlmsg {
char* pos;
int nesting;
struct nlattr* nested[8];
char buf[1024];
};
static struct nlmsg nlmsg;
static void netlink_init(struct nlmsg* nlmsg, int typ, int flags,
const void* data, int size)
{
memset(nlmsg, 0, sizeof(*nlmsg));
struct nlmsghdr* hdr = (struct nlmsghdr*)nlmsg->buf;
hdr->nlmsg_type = typ;
hdr->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | flags;
memcpy(hdr + 1, data, size);
nlmsg->pos = (char*)(hdr + 1) + NLMSG_ALIGN(size);
}
static void netlink_attr(struct nlmsg* nlmsg, int typ, const void* data,
int size)
{
struct nlattr* attr = (struct nlattr*)nlmsg->pos;
attr->nla_len = sizeof(*attr) + size;
attr->nla_type = typ;
memcpy(attr + 1, data, size);
nlmsg->pos += NLMSG_ALIGN(attr->nla_len);
}
static int netlink_send_ext(struct nlmsg* nlmsg, int sock, uint16_t reply_type,
int* reply_len)
{
if (nlmsg->pos > nlmsg->buf + sizeof(nlmsg->buf) || nlmsg->nesting)
exit(1);
struct nlmsghdr* hdr = (struct nlmsghdr*)nlmsg->buf;
hdr->nlmsg_len = nlmsg->pos - nlmsg->buf;
struct sockaddr_nl addr;
memset(&addr, 0, sizeof(addr));
addr.nl_family = AF_NETLINK;
unsigned n = sendto(sock, nlmsg->buf, hdr->nlmsg_len, 0,
(struct sockaddr*)&addr, sizeof(addr));
if (n != hdr->nlmsg_len)
exit(1);
n = recv(sock, nlmsg->buf, sizeof(nlmsg->buf), 0);
if (hdr->nlmsg_type == NLMSG_DONE) {
*reply_len = 0;
return 0;
}
if (n < sizeof(struct nlmsghdr))
exit(1);
if (reply_len && hdr->nlmsg_type == reply_type) {
*reply_len = n;
return 0;
}
if (n < sizeof(struct nlmsghdr) + sizeof(struct nlmsgerr))
exit(1);
if (hdr->nlmsg_type != NLMSG_ERROR)
exit(1);
return -((struct nlmsgerr*)(hdr + 1))->error;
}
static int netlink_send(struct nlmsg* nlmsg, int sock)
{
return netlink_send_ext(nlmsg, sock, 0, NULL);
}
static int netlink_next_msg(struct nlmsg* nlmsg, unsigned int offset,
unsigned int total_len)
{
struct nlmsghdr* hdr = (struct nlmsghdr*)(nlmsg->buf + offset);
if (offset == total_len || offset + hdr->nlmsg_len > total_len)
return -1;
return hdr->nlmsg_len;
}
static void netlink_device_change(struct nlmsg* nlmsg, int sock,
const char* name, bool up, const char* master,
const void* mac, int macsize,
const char* new_name)
{
struct ifinfomsg hdr;
memset(&hdr, 0, sizeof(hdr));
if (up)
hdr.ifi_flags = hdr.ifi_change = IFF_UP;
hdr.ifi_index = if_nametoindex(name);
netlink_init(nlmsg, RTM_NEWLINK, 0, &hdr, sizeof(hdr));
if (new_name)
netlink_attr(nlmsg, IFLA_IFNAME, new_name, strlen(new_name));
if (master) {
int ifindex = if_nametoindex(master);
netlink_attr(nlmsg, IFLA_MASTER, &ifindex, sizeof(ifindex));
}
if (macsize)
netlink_attr(nlmsg, IFLA_ADDRESS, mac, macsize);
int err = netlink_send(nlmsg, sock);
(void)err;
}
const int kInitNetNsFd = 239;
#define DEVLINK_FAMILY_NAME "devlink"
#define DEVLINK_CMD_PORT_GET 5
#define DEVLINK_CMD_RELOAD 37
#define DEVLINK_ATTR_BUS_NAME 1
#define DEVLINK_ATTR_DEV_NAME 2
#define DEVLINK_ATTR_NETDEV_NAME 7
#define DEVLINK_ATTR_NETNS_FD 137
static int netlink_devlink_id_get(struct nlmsg* nlmsg, int sock)
{
struct genlmsghdr genlhdr;
struct nlattr* attr;
int err, n;
uint16_t id = 0;
memset(&genlhdr, 0, sizeof(genlhdr));
genlhdr.cmd = CTRL_CMD_GETFAMILY;
netlink_init(nlmsg, GENL_ID_CTRL, 0, &genlhdr, sizeof(genlhdr));
netlink_attr(nlmsg, CTRL_ATTR_FAMILY_NAME, DEVLINK_FAMILY_NAME,
strlen(DEVLINK_FAMILY_NAME) + 1);
err = netlink_send_ext(nlmsg, sock, GENL_ID_CTRL, &n);
if (err) {
return -1;
}
attr = (struct nlattr*)(nlmsg->buf + NLMSG_HDRLEN +
NLMSG_ALIGN(sizeof(genlhdr)));
for (; (char*)attr < nlmsg->buf + n;
attr = (struct nlattr*)((char*)attr + NLMSG_ALIGN(attr->nla_len))) {
if (attr->nla_type == CTRL_ATTR_FAMILY_ID) {
id = *(uint16_t*)(attr + 1);
break;
}
}
if (!id) {
return -1;
}
recv(sock, nlmsg->buf, sizeof(nlmsg->buf), 0); /* recv ack */
return id;
}
static void netlink_devlink_netns_move(const char* bus_name,
const char* dev_name, int netns_fd)
{
struct genlmsghdr genlhdr;
int sock;
int id;
sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC);
if (sock == -1)
exit(1);
id = netlink_devlink_id_get(&nlmsg, sock);
if (id == -1)
goto error;
memset(&genlhdr, 0, sizeof(genlhdr));
genlhdr.cmd = DEVLINK_CMD_RELOAD;
netlink_init(&nlmsg, id, 0, &genlhdr, sizeof(genlhdr));
netlink_attr(&nlmsg, DEVLINK_ATTR_BUS_NAME, bus_name, strlen(bus_name) + 1);
netlink_attr(&nlmsg, DEVLINK_ATTR_DEV_NAME, dev_name, strlen(dev_name) + 1);
netlink_attr(&nlmsg, DEVLINK_ATTR_NETNS_FD, &netns_fd, sizeof(netns_fd));
netlink_send(&nlmsg, sock);
error:
close(sock);
}
static struct nlmsg nlmsg2;
static void initialize_devlink_ports(const char* bus_name, const char* dev_name,
const char* netdev_prefix)
{
struct genlmsghdr genlhdr;
int len, total_len, id, err, offset;
uint16_t netdev_index;
int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC);
if (sock == -1)
exit(1);
int rtsock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (rtsock == -1)
exit(1);
id = netlink_devlink_id_get(&nlmsg, sock);
if (id == -1)
goto error;
memset(&genlhdr, 0, sizeof(genlhdr));
genlhdr.cmd = DEVLINK_CMD_PORT_GET;
netlink_init(&nlmsg, id, NLM_F_DUMP, &genlhdr, sizeof(genlhdr));
netlink_attr(&nlmsg, DEVLINK_ATTR_BUS_NAME, bus_name, strlen(bus_name) + 1);
netlink_attr(&nlmsg, DEVLINK_ATTR_DEV_NAME, dev_name, strlen(dev_name) + 1);
err = netlink_send_ext(&nlmsg, sock, id, &total_len);
if (err) {
goto error;
}
offset = 0;
netdev_index = 0;
while ((len = netlink_next_msg(&nlmsg, offset, total_len)) != -1) {
struct nlattr* attr = (struct nlattr*)(nlmsg.buf + offset + NLMSG_HDRLEN +
NLMSG_ALIGN(sizeof(genlhdr)));
for (; (char*)attr < nlmsg.buf + offset + len;
attr = (struct nlattr*)((char*)attr + NLMSG_ALIGN(attr->nla_len))) {
if (attr->nla_type == DEVLINK_ATTR_NETDEV_NAME) {
char* port_name;
char netdev_name[IFNAMSIZ];
port_name = (char*)(attr + 1);
snprintf(netdev_name, sizeof(netdev_name), "%s%d", netdev_prefix,
netdev_index);
netlink_device_change(&nlmsg2, rtsock, port_name, true, 0, 0, 0,
netdev_name);
break;
}
}
offset += len;
netdev_index++;
}
error:
close(rtsock);
close(sock);
}
static void initialize_devlink_pci(void)
{
int netns = open("/proc/self/ns/net", O_RDONLY);
if (netns == -1)
exit(1);
int ret = setns(kInitNetNsFd, 0);
if (ret == -1)
exit(1);
netlink_devlink_netns_move("pci", "0000:00:10.0", netns);
ret = setns(netns, 0);
if (ret == -1)
exit(1);
close(netns);
initialize_devlink_ports("pci", "0000:00:10.0", "netpci");
}
#ifndef __NR_bpf
#define __NR_bpf 321
#endif
uint64_t r[1] = {0xffffffffffffffff};
int main(void)
{
syscall(__NR_mmap, 0x20000000ul, 0x1000000ul, 3ul, 0x32ul, -1, 0);
intptr_t res = 0;
*(uint32_t*)0x20000200 = 0xc;
*(uint32_t*)0x20000204 = 0xe;
*(uint64_t*)0x20000208 = 0x20000e80;
memcpy(
(void*)0x20000e80,
"\xb7\x02\x00\x00\x03\x07\x00\x08\xbf\xa3\x00\x00\x00\x00\x00\x00\x07\x01"
"\x00\x00\x00\xfe\xff\xff\x7a\x0a\xf0\xff\xf8\xff\xff\xff\x79\xa4\xf0\xff"
"\x00\x00\x00\x00\xb7\x06\x00\x00\xff\xff\xff\xff\x2d\x64\x05\x00\x00\x00"
"\x00\x00\x65\x04\x04\x00\x01\x00\x00\x00\x04\x04\x00\x00\xf5\x06\x7d\x60"
"\xb7\x03\x00\x00\x00\x00\x00\x00\x6a\x0a\x00\xfe\x18\x00\x00\x00\x85\x00"
"\x00\x00\x2b\x00\x00\x00\xb7\x00\x00\x00\x00\x00\x00\x00\x95\x00\x00\x00"
"\x00\x00\x00\x00\x0d\x7a\x28\x07\x3a\x41\x02\xe4\xae\xb5\x4f\x36\x63\x3e"
"\x27\xc2\x79\x34\x1b\xf4\x89\x90\x3c\xfd\xb4\xc0\x5e\x96\xe3\x04\x6f\x04"
"\xe7\x79\x69\xbe\x06\x34\x0e\xe6\xaf\x0d\x49\x91\x0d\x06\x35\x18\x59\x8e"
"\x7e\x29\x0b\x39\xa6\xf2\xfc\x2a\x5e\x01\x9b\xc6\xb4\x56\x84\xf0\x02\xcf"
"\x57\xbf\x88\x7e\x83\xfb\xb2\x21\x5b\x8a\x34\xe6\xbd\xc4\xdc\x1a\xf6\xd3"
"\xc6\x95\x8d\xa4\xbd\xda\xc6\x02\xe0\x04\x8b\xec\x11\xe8\x74\x60\x2f\x06"
"\x00\x00\x00\x2a\xf2\x1b\x75\x52\xf0\xa0\xcc\x85\xae\x28\x19\x93\xbf\xa2"
"\x13\x9a\x3b\xb7\x55\xc1\xf1\xab\xd1\x96\x40\x07\x00\x00\x00\xe2\x7b\x21"
"\x21\xa5\xf0\x3d\xff\x97\x87\xdf\xd6\xe7\x60\x8e\xb6\x38\xe6\xfc\x4e\x0b"
"\xc6\xbd\x5f\xf3\x59\x28\xa5\xb5\xfa\x72\x30\x28\xeb\x6d\xdd\x35\xea\x79"
"\xb9\x2b\xee\xb5\x22\x65\xa4\xb0\x4b\xa5\x0f\xd4\x6a\x50\x41\x16\xfb\x8e"
"\xf8\x4c\x2b\xe0\x21\xa6\xc9\xda\xf3\xf2\x4a\xd7\xb9\x65\xaf\x8f\x52\x23"
"\x71\xc9\xa4\x3c\x80\xee\x6b\x39\x7b\xea\x24\x7e\x2d\x71\x40\x90\xd4\x3f"
"\xe6\x6b\xbf\x4f\x4f\xfe\x41\x0b\xd7\x01\xd0\x35\xf8\x67\xde\x2a\x20\x69"
"\x50\x33\xd9\x1e\xe2\x38\xc8\x24\xe0\xb7\xa0\xae\xff\xb9\x84\x39\x47\xc3"
"\xbc\x96\xe1\xf9\x5c\x24\x51\x68\xd2\xae\xed\x2e\x00\x46\x3d\x9c\x03\x9b"
"\xfd\xd5\x87\x09\xe8\x98\xc7\xeb\xad\x73\xfc\x48\x67\x3c\x75\xc8\xb5\x0d"
"\xb8\x52\x62\x1a\xd1\x9c\x85\x46\x22\xf7\xc7\xd7\x9e\xc3\xab\x44\x94\x35"
"\x3b\x45\x8c\x71\x80\x21\xf7\x01\x44\x2b\xbc\x64\x56\xbf\x0c\x9f\x6b\x82"
"\x22\x11\xeb\x1a\xa4\x88\xfc\xae\xbb\x10\x93\x82\xc7\xab\x6d\xb9\xb3\x6e"
"\xf2\x4e\x46\x64\x94\xe7\xb8\x54\x9c\xc1\x39\xa7\x4b\x5a\xaa\xf2\x61\xf3"
"\x5e\x83\x47\xea\xab\xe0\x1a\xfe\x21\xd7\xb7\xa9\x58\xe9\xcd\x04\xb5\xbf"
"\xa5\xcf\x78\xdd\x2f\xa9\x58\xdb\xb6\x05\xcd\x1a\x99\x61\x33\x69\x18\x5b"
"\x2b\xcf\xe0\xbf\x0e\x31\xc8\x3f\xdc\xb2\x54\xda\x7c\xd3\x95\x89\x83\xd0"
"\x79\x8b\x45\x5c\x8c\x5a\x5a\x85\x65\xd8\x3d\x28\x43\x78\x95\x92\x9f\xa0"
"\x89\x6c\xf4\x5e\xda\x77\xc4\xfe\xae\x29\xd9\x65\x68\xc4\x87\xa7\x4d\xd4"
"\xf9\xe8\x46\x5f\x09\x81\x8c\x12\xdf\xc9\x3f\xdb\x09\xa1\xd0\x4a\x08\x7d"
"\x3b\xf2\x19\xef\xab\x76\x4d\x3c\xd6\x76\xf1\x01\xd3\xb6\xc9\x17\x7c\x57"
"\x34\x0b\x24\x5f\x15\xaf\x47\x2f\x1b\x83\x70\x81\x96\x9d\xb2\xd5\x8c\xea"
"\xb0\xb4\x32\x00\x5a\x86\xe6\xc4\x50\xae\x42\x41\xc0\x8a\x64\x69\xac\x65"
"\xaf\x64\x73\x7a\xf9\x61\xcc\x90\x13\x2c\xd2\xcc\xb6\xd7\xad\xf6\x38\x46"
"\xaf\x15\x54\xcf\xca\xa4\xeb\x35\x71\x42\xa5\xb5\x25\xa1\x8d\x9d\x88\xd4"
"\x25\x20\xc0\x90\x3b\xc4\x44\xdc\x0e\xec\x4d\x26\xe5\x86\xef\xf7\xc4\x32"
"\xcd\x12\xbe\x4c\x79\x6f\x9e\xbe\x44\x81\xf9\x71\xc5\x2a\x8c\xc7\xb0\xed"
"\xab\x7a\xe8\x72\xc4\x83\x2b\x61\xa5\x49\x63\x18\x5b\xb7\xcd\x1f\xb7\x8f"
"\xf9\xe1\x94\xe1\x7c\x65\xac\xd8\xd0\x15\x44\x3a\x21\x81\x5b\xf5\x6f\x08"
"\xf1\xd2\x29\x3c\xed\x27\x88\x99\xa9\x72\x05\x63\x80\xb4\xf3\x32\xd3\x97"
"\x37\xb1\x49\xe1\x6b\xb0\x98\xc0\xef\x5d\x36\x2c\xde\x82\x50\x9e\xad\x89"
"\x32\x86\x9d\x3d\x9b\x52\x7c\x9e\x53\xc5\xc4\x1f\x4d\x71\x1c\x8b\x68\xa0"
"\xa1\x6c\x01\x8c\xe2\xa2\x48\x32\xcd\xdb\x18\xbe\xc4\x14\xd7\x8f\x88\x6d"
"\x1e\xbf\x73\x00\x38\x4b\x13\xef\xef\xa0\x3a\xd5\x5f\xba\xef\xc0\x26\xea"
"\xa5\x71\xd5\xde\xb4\x49\x5e\xbd\x6f\xc7\xd4\x57\xaf\x00\x8e\x74\x85\x55"
"\x62\xbb\xb4\xf2\x55\xc5\xa6\x81\x9a\xd2\xb6\x07\xda\xd7\x32\x77\xce\x27"
"\x56\xe0\xcc\xfd\xd7\x40\x3d\x13\x93\x8b\x4b\xae\x98\xb9\x8b\x62\x1c\x30"
"\x9b\x18\xdf\x38\xa1\xcd\x77\x9b\xf4\x79\x09\x6c\x09\x85\x1c\x9a\xa5\x3f"
"\x91\x04\x1f\x2e\x17\x65\x21\x20\x94\xff\xb9\x7e\xbf\x97\x2e\x48\x87\x1f"
"\x76\xb5\xe0\xcd\xfd\xa8\x1d\xf2\x8e\x5f\x72\x1f\x8a\x63\xc0\xfb\xd8\xac"
"\x99\x2d\x75\x35\x45\x2f\x7a\xf6\x8f\x5a\xe2\x20\x20\xaf\xd0\xa6\x03\x6d"
"\x51\xcd\xa9\x8f\xef\x44\xb6\x91\x39\x31\x58\x32\xd4\x9f\xef\x81\x19\x8f"
"\x15\xeb\xe3\xa7\x54\x8b\xa4\x64\x51\xd9\x3d\xa0\x3b\x99\xbe\xcd\x85\x85"
"\x1e\x71\x57\xd7\xe2\x3b\x28\x06\x0f\xc4\xfa\x98\xd8\x7d\xbc\x5c\xec\x5a"
"\x4e\x06\x53\x72\x75\xa8\xfb\x1d\x41\x94\x08\x24\x8d\xdc\x98\x11\x3e\x88"
"\x49\x91\x72\x6b\xf0\x54\x01\x00\x00\x00\xa5\xe0\xf6\xbc\x37\x3e\x43\x8d"
"\xf8\x50\x81\x98\xcb\x61\xa4\x64\x06\x84\xd0\x2f\x9f\x97\xce\xde\xe6\x6f"
"\x20\x98\xea\xa9\xee\x8d\xed\xc0\x00\x37\x31\xc5\x11\xef\xcf\xc7\x8b\xd2"
"\x56\x5a\xdf\xa0\x13\x0b\x48\x1b\x2c\xa8\xfe\x13\x22\x1b\x4e\x99\xd9\x4d"
"\xed\x40\x78\x7e\x07\xe6\x26\x4b\xb2\x8e\xab\x38\x3d\x90\xd4\x19\xb1\x7d"
"\x36\xe6\xf7\x4d\x73\xbd\xce\x1f\x7d\x81\x60\xd9\x06\x7f\x63\x5f\xd5\x12"
"\x36\x52\xf6\xfa\xea\x7a\x3a\x6e\xfe\x11\xf1\xdb\x1c\x31\x74\x47\x6b\x47"
"\x63\x07\x3a\xbb\x6b\x3a\x05\x29\x56\x6a\xf5\x1e\xb3\x1a\x1a\x82\xf2\x95"
"\x59\xdb\x29\x38\xcf\xc5\x89\x5c\x61\x52\xb2\xf9\x34\x74\xfb\xfc\xb3\x39"
"\xcb\xa7\xd0\x6e\xc6\x5a\xfb\x9f\xd5\xb4\xfc",
1217);
*(uint64_t*)0x20000210 = 0x20000340;
memcpy((void*)0x20000340, "syzkaller\000", 10);
*(uint32_t*)0x20000218 = 0;
*(uint32_t*)0x2000021c = 0;
*(uint64_t*)0x20000220 = 0;
*(uint32_t*)0x20000228 = 0;
*(uint32_t*)0x2000022c = 0;
*(uint8_t*)0x20000230 = 0;
*(uint8_t*)0x20000231 = 0;
*(uint8_t*)0x20000232 = 0;
*(uint8_t*)0x20000233 = 0;
*(uint8_t*)0x20000234 = 0;
*(uint8_t*)0x20000235 = 0;
*(uint8_t*)0x20000236 = 0;
*(uint8_t*)0x20000237 = 0;
*(uint8_t*)0x20000238 = 0;
*(uint8_t*)0x20000239 = 0;
*(uint8_t*)0x2000023a = 0;
*(uint8_t*)0x2000023b = 0;
*(uint8_t*)0x2000023c = 0;
*(uint8_t*)0x2000023d = 0;
*(uint8_t*)0x2000023e = 0;
*(uint8_t*)0x2000023f = 0;
*(uint32_t*)0x20000240 = 0;
*(uint32_t*)0x20000244 = 0;
*(uint32_t*)0x20000248 = -1;
*(uint32_t*)0x2000024c = 8;
*(uint64_t*)0x20000250 = 0x20000000;
*(uint32_t*)0x20000000 = 0;
*(uint32_t*)0x20000004 = 0;
*(uint32_t*)0x20000258 = 0;
*(uint32_t*)0x2000025c = 0x10;
*(uint64_t*)0x20000260 = 0x20000000;
*(uint32_t*)0x20000000 = 0;
*(uint32_t*)0x20000004 = 0;
*(uint32_t*)0x20000008 = 0;
*(uint32_t*)0x2000000c = 0;
*(uint32_t*)0x20000268 = 0;
res = syscall(__NR_bpf, 5ul, 0x20000200ul, 0x48ul);
if (res != -1)
r[0] = res;
*(uint32_t*)0x200004c0 = r[0];
*(uint32_t*)0x200004c4 = 0;
*(uint32_t*)0x200004c8 = 0xe;
*(uint32_t*)0x200004cc = 0xfffffee4;
*(uint64_t*)0x200004d0 = 0x20000040;
memcpy((void*)0x20000040,
"\x1c\x04\xff\x01\xda\x6d\xa9\x72\x5f\x90\xc5\xa0\x6d\x0f", 14);
*(uint64_t*)0x200004d8 = 0;
*(uint32_t*)0x200004e0 = 0xf0;
*(uint32_t*)0x200004e4 = 0;
*(uint32_t*)0x200004e8 = 0;
*(uint32_t*)0x200004ec = 0;
*(uint64_t*)0x200004f0 = 0x20000000;
*(uint64_t*)0x200004f8 = 0x20000000;
syscall(__NR_bpf, 0xaul, 0x200004c0ul, 0x28ul);
return 0;
}
|
the_stack_data/85747.c | #include <stdio.h>
int array[100][15];
void PRINT(int array[][6], int counter)
{ int n;
for(n=0;n<counter;n++)
array[n][4]=array[n][0] + array[n][2];
array[n][5]=array[n][1] + array[n][3];
array[n][6]=array[n][4] * array[n][5]; // R index
array[n][7]; //intersection
array[n][8];// boundingbox
array[n][10]+= (array[n][4] * array[n][5]);
array[n][9]==array[n][10] - array[n][7]; //Net area
}
int main () {
char param, com, minus;
int x,y,h,w, counter=0, n;
while (scanf("%c", ¶m)!= EOF){
do{
if (param == 'R' || 'r' || 'S'|| 's'|| 'P'||'p'){
if(param == 'R' || param == 'r'){
scanf("%d %d %d %d",&x,&y,&w,&h);
for(n=0;n<counter;n++){
x=array[n][0];
y=array[n][1];
w=array[n][2];
h=array[n][3];}
break;}
else if(param == 'S' || param == 's')
{scanf("%d %d %d",&x,&y,&w);
for(n=0;n<counter;n++){
x=array[n][0];
y=array[n][1];
w=array[n][2];}
break;}
else if(param == 'P' || param == 'p'){
while (scanf(" %c%c",&minus, &com)!= EOF){
if(minus == '-'){
if (com == 'D' || 'd' || 'R'|| 'r'|| 'N'||'n' ||'I' ||'i' ||'B' ||'b' ){
if(com== 'D' ||com == 'd')
{PRINT(array, counter);
printf("-------------\n");
printf("[%d]", counter);
printf("%2d",array[0][0]);
printf("%2d",array[0][1]);
printf("%2d",array[0][4]);
printf("%2d",array[0][5]);
printf("\n-------------\n");
break;}
else if(com== 'R' || com == 'r')
{
PRINT(array, counter);
for(n=0;n<counter;n++)
printf("Area of Rectangle [%d] = %d" ,n, array[n][6]);
break;}
else if(com == 'N' || com == 'n') {
PRINT(array, counter);
for(n=0;n<counter;n++)
printf("Net Rectangle Area = %d",array[n][9]); break;}
else if(com== 'I' || com == 'i')
{printf("Intersection Area = %d",array[n][7] ); break;}
else if(com == 'B' || com == 'b')
{printf("BBC = %d", array[n][8]);break;}
}
if (com != 'D' || 'd' || 'R'|| 'r'|| 'N' ||'n'|| 'i'|| 'I'|| 'b' ||'B');
{printf("Invalid command\n" );
break;}}
if(minus != '-')
{printf("invalid print command\n"); break;}}
break;}}
if(param == 'Q' || param == 'q')
{break;}
if (param != 'R' || 'r' || 'S'|| 's'|| 'P' ||'p');{
printf("Invalid command\n" );
break;}}
while(param =getchar()!= EOF);
getchar();
if(param == 'Q' || param == 'q')
{break;}}
return 0;}
|
the_stack_data/1134327.c | #include <stdio.h>
/* Enunciado - Faça um programa que leia uma data no seguinte formato:
* D/M/A. O programa deve determinar se a data digitada válida ou não.
* Lembre-se que Fevereiro tem 29 dias em anos bissextos e 28 dias em anos não
* bissextos.
*
* Exemplos:
*
* Data: 22/02/2022
* Data valida!
*
* Data: 29/02/2020
* Data valida!
*
* Data: 29/02/2022
* Data invalida!
*
* Data: 31/06/2022
* Data invalida!
*
* Data: 31/13/2022
* Data invalida!
*/
int main (int argc, char *argv[])
{
return 0;
}
|
the_stack_data/65201.c | #include <stdio.h>
struct time{
int hour;
int min;
int sec;
} gtime = {1,2,3}, gtimes[4];
char* array[4] = {"one","two","three"};
int func(short sw, char* str){
printf("first char = %c\n", *str);
if(sw)
return 2;
return 3;
}
int main(){
int lval = 2331, i;
char* lstr = "I like you.";
struct time* pt = >ime;
for(i = 0; i < 4; ++i){
printf("loop %d", i);
gtime.hour += func(i%2,array[i]);
}
return 0;
}
|
the_stack_data/42547.c |
// C++中引用C函数
#include <stdio.h>
void mytest() { printf("mytest in .c file ok\n"); } |
the_stack_data/82950528.c |
/*******
* prefix(s1, s2) check s2 for prefix s1
* char *s1, *s2;
*
* return 0 - !=
* return 1 - ==
*/
prefix(s1, s2)
char *s1, *s2;
{
char c;
while ((c = *s1++) == *s2++)
if (c == '\0')
return(1);
return(c == '\0');
}
|
the_stack_data/32949214.c | #include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
/* Program demonstrira razliku izmedju realnog i efektivnog Id-a. */
void error(char *message);
int main(int argc, char **argv){
/* Proverava se da li fajl moze da se otvori za pisanje
pomocu realnog Id-a. */
if (access("foo", W_OK) < 0)
printf("Ne moze da se pristupi na osnovu realnog Id-a.\n");
else
printf("Moze da se pristupi na osnovu realnog Id-a.\n");
/* Proverava se da li fajl moze da se otvori za pisanje
pomocu efektivnog Id-a. */
if (open("foo", O_WRONLY) < 0)
printf("Ne moze da se pristupi na osnovu efektivnog Id-a.\n");
else
printf("Moze da se pristupi na osnovu efektivnog Id-a.\n");
/* Zavrsava se program. */
exit(EXIT_SUCCESS);
}
void error(char *message){
perror(message);
exit(EXIT_FAILURE);
}
|
the_stack_data/28256.c | /* */
#include <sys/types.h>
#include <ctype.h>
#include <dlfcn.h>
#include <errno.h>
#include <fcntl.h>
#include <grp.h>
#include <langinfo.h>
#include <limits.h>
#include <linux/types.h>
#include <linux/fiemap.h>
#include <linux/fs.h>
#include <linux/magic.h>
#include <locale.h>
#include <memory.h>
#include <paths.h>
#include <poll.h>
#include <pthread.h>
#include <pwd.h>
#include <regex.h>
#include <signal.h>
#include <spawn.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <sys/cdefs.h>
#include <sys/ioctl.h>
#include <sys/param.h>
#include <sys/poll.h>
#include <sys/select.h>
#include <sys/stat.h>
#include <sys/statfs.h>
#include <sys/statvfs.h>
int main(void){return 0;}
|
the_stack_data/76699259.c |
#include <stdio.h>
int main()
{
printf("%s\n", "Hello, world!");
return 0;
}
|
the_stack_data/1217611.c | #define MASK(N) ((1UL << (N)) - 1)
#define BITS(N) ((1UL << ((N) - 1)) + 2)
#define FUNC(N) void f##N(long j) { if ((j & MASK(N)) >= BITS(N)) abort();}
FUNC(3)
FUNC(4)
FUNC(5)
FUNC(6)
FUNC(7)
FUNC(8)
FUNC(9)
FUNC(10)
FUNC(11)
FUNC(12)
FUNC(13)
FUNC(14)
FUNC(15)
FUNC(16)
FUNC(17)
FUNC(18)
FUNC(19)
FUNC(20)
FUNC(21)
FUNC(22)
FUNC(23)
FUNC(24)
FUNC(25)
FUNC(26)
FUNC(27)
FUNC(28)
FUNC(29)
FUNC(30)
FUNC(31)
int main ()
{
f3(0);
f4(0);
f5(0);
f6(0);
f7(0);
f8(0);
f9(0);
f10(0);
f11(0);
f12(0);
f13(0);
f14(0);
f15(0);
f16(0);
f17(0);
f18(0);
f19(0);
f20(0);
f21(0);
f22(0);
f23(0);
f24(0);
f25(0);
f26(0);
f27(0);
f28(0);
f29(0);
f30(0);
f31(0);
exit(0);
}
|
the_stack_data/14199259.c | #include <stdio.h>
#include<string.h>
int main()
{
int flag[10]={0}, fl=1, c, r, i, j, cnt=0, x;
char str[12][12];
scanf("%d %d", &r, &c);
x=r;
for(i=0; i<r; i++)
{
scanf("%s", str[i]);
fl=1;
for(j=0; j<c; j++)
{
if(str[i][j]=='S')
{
fl=0;
flag[j]= 1;
}
}
if(fl)
{
x--;
cnt+=c;
}
}
for(i=0; i<c; i++)
{
if(flag[i]==0) cnt+=x;
}
printf("%d\n", cnt);
return 0;
}
|
the_stack_data/40814.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ygarrot <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/11 14:23:17 by ygarrot #+# #+# */
/* Updated: 2018/05/11 16:25:18 by tcharrie ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putstr_fd(char const *s, int fd)
{
int i;
i = 0;
if (!s)
return ;
while (s[i])
i++;
write(fd, s, i);
}
|
the_stack_data/25139144.c | #define _POSIX_C_SOURCE 200809L
#include "stdlib.h"
#include "math.h"
#include "sys/time.h"
#include "omp.h"
#include <stdio.h>
struct dataobj
{
void *restrict data;
int * size;
int * npsize;
int * dsize;
int * hsize;
int * hofs;
int * oofs;
} ;
struct profiler
{
double section0;
} ;
int Kernel(const float dt, const float h_x, const float h_y, struct dataobj *restrict u_vec, const int time_M, const int time_m, struct profiler * timers, const int x_M, const int x_m, const int xi_ltkn, const int xi_rtkn, const int y_M, const int y_m, const int yi_ltkn, const int yi_rtkn)
{
float (*restrict u)[u_vec->size[1]][u_vec->size[2]] __attribute__ ((aligned (64))) = (float (*)[u_vec->size[1]][u_vec->size[2]]) u_vec->data;
for (int time = time_m, t0 = (time)%(2), t1 = (time + 1)%(2); time <= time_M; time += 1, t0 = (time)%(2), t1 = (time + 1)%(2))
{
struct timeval start_section0, end_section0;
gettimeofday(&start_section0, NULL);
/* Begin section0 */
for (int xi = x_m + xi_ltkn; xi <= x_M - xi_rtkn; xi += 1)
{
for (int yi = y_m + yi_ltkn; yi <= y_M - yi_rtkn; yi += 1)
{
u[t1][xi + 1][yi + 1] = 1.0F*(dt*h_x*u[t0][xi + 1][yi] - dt*h_x*u[t0][xi + 1][yi + 1] + dt*h_y*u[t0][xi][yi + 1] - dt*h_y*u[t0][xi + 1][yi + 1] + h_x*h_y*u[t0][xi + 1][yi + 1])/(h_x*h_y);
}
}
/* End section0 */
gettimeofday(&end_section0, NULL);
timers->section0 += (double)(end_section0.tv_sec-start_section0.tv_sec)+(double)(end_section0.tv_usec-start_section0.tv_usec)/1000000;
}
# pragma omp target
{
if (!omp_is_initial_device())
printf("Hello from accelerator.\n");
else
printf("Hello from host.\n");
}
return 0;
}
|
the_stack_data/184518053.c | #include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
int main() {
int n;
scanf("%d", &n);
int *a = malloc(sizeof(int) * n);
int *prtS = a;
for(int i = 0; i < n; i++){
scanf("%d",prtS+i);
}
int swap = 0;
int *prtH = a;
for (int i=0; i<n;i++){
for (int j=0; j<n-i-1;j++){
if (prtH[j]>prtH[j+1]){
swap++;
int temp = prtH[j];
prtH[j]= prtH[j+1];
prtH[j+1] = temp;
}
}
}
/* int *prtP = a;
printf("===START=\n");
for(int i = 0; i <= n+5; i++)
printf("a[%d]=%d\n",i,prtP[i]);
printf("\n===END=\n");
*/
printf("Array is sorted in %d swaps.\n",swap);
printf("First Element: %d \n",*a);
printf("Last Element: %d \n",a[n-1]);
return 0;
} |
the_stack_data/48576272.c | /*
* module 1
* problem 8
*
* Ask for the **name**, **weight** (in tons) and **height** (in feet) of a dinosaur.
* Show as output it's name with the given **weight** (converted to kilograms)
* and it's **height** (converted to meters). `(1 ton = 1000 kg); (1 feet = 0.3047 m)`.
*/
/* imported libraries */
#include <stdio.h>
/* entry point */
int main(int argc, char *argv[])
{
float peso = 0, altura = 0, ralt = 0;
int rpe = 0;
char nombre[30];
printf("\nIngrese el Nombre del Dinosaurio\n");
scanf("%s", &nombre);
printf("\nIngrese su Estatura en Pies (Ft)\n");
scanf(" %f", &altura);
printf("\nIngrese su Peso en Toneladas (Ton)\n");
scanf("%f", &peso);
/* eats extra \n */
getchar();
rpe = peso * 1000;
ralt = altura * 0.3047;
printf("\n=======================================\nEstimad@ %s\n\nSu Peso es de %d Kilogramos !\nSu Estatura es de %.2f Metros !\n\n\n\n", nombre, rpe, ralt);
getchar();
return 0;
} |
the_stack_data/106329.c | #include <sys/mman.h>
#include "syscall.h"
#ifndef PS4
int __madvise(void *addr, size_t len, int advice)
{
return syscall(SYS_madvise, addr, len, advice);
}
weak_alias(__madvise, madvise);
#else
int madvise(void*, size_t, int);
int __madvise(void* addr, size_t len, int advice)
{
return madvise(addr, len, advice);
}
#endif
|
the_stack_data/31388324.c | /*
Exercise 1-8. Write a program to count blanks, tabs, and newlines.
*/
#include <stdio.h>
/* count blanks, tabs and newlines in input */
int main(void) {
int c, nl;
nl = 0;
while ((c = getchar()) != EOF) {
if (c == ' ' || c == '\n' || c == '\t') {
++nl;
}
}
printf("%d\n", nl);
}
|
the_stack_data/90766171.c | /*
<TAGS>stats</TAGS>
DESCRIPTION:
Calculate summary statistics on an array of numbers (double-precision floating-point)
This is the fastest of the stats family of functions - mean only is calculated
Uses high-precision calculation for large datasets
- here the mean is first calculated by breaking the double-values into integer and fractional parts
- then the individual differences from the mean are calculated
- the sums used for calculating the standard deviation are also similarly adjusted
NOTE: no check for invalid values (NAN or INF)
USES:
Getting the mean of a data set
DEPENDENCIES:
No dependencies
ARGUMENTS:
double *data1: array holding the data
long nn: number of elements in the array
int digits: number of digits precision
RETURN VALUE:
the mean, to [digits] precision
NAN if no input data or digits<0
SAMPLE CALL:
mean= xf_stats1_d(data,nn,3);
*/
#include <math.h>
double xf_stats1_d(double *data1, long nn, int digits) {
long ii,jj,kk,sumjj,sumkk,base=10,precision;
double aa,bb,cc,mean;
if(nn<1) return(NAN);
if(digits<0) return(NAN);
if(nn==1) return(data1[0]);
/* CALCULATE PRECISION MULTIPLIER - POWER OF 10 (BASE^DIGITS) */
precision=1;
for (;;) {
if (digits & 1) precision *= base;
digits >>= 1;
if (!digits) break;
base *= base;
}
/* CALCULATE THE MEAN BY BREAKING THE NUMBERS INTO INTEGER AND FRACTIONAL PARTS */
sumjj= sumkk= 0;
for(ii=0;ii<nn;ii++) {
aa= data1[ii];
bb= modf(aa,&cc); /* get fractional (bb) and integer (cc) parts */
jj= (long)cc; /* integer part */
kk= (long)bb*precision; /* fractional part, multiplied by precision to a long integer */
sumjj+= jj;
sumkk+= kk;
}
/* reconstitute & return an accurate estimate of the mean, to 10 decimal places */
mean= (double)((sumjj + sumkk/precision)/nn);
return(mean);
}
|
the_stack_data/97012057.c | int foo(int a, int b) {
int x, y;
char z;
x = y = z + x - y * z;
x = y = z + x;
z = x / z;
} |
the_stack_data/140765290.c | /*-
* Copyright (c) 1990 The Regents of the University of California.
* Copyright (c) 1994 Chris Provenzano, [email protected]
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. 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.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)rand.c 5.6 (Berkeley) 6/24/91";
#endif /* LIBC_SCCS and not lint */
#include <pthread.h>
#include <sys/types.h>
#include <stdlib.h>
static u_long next = 1;
int rand_r(u_int * next_r)
{
int ret;
(*next_r) = (*next_r) * 1103515245 + 12345;
ret = (*next_r) & RAND_MAX;
return(ret);
}
#undef rand
int rand(void)
{
return ((next = next * 1103515245 + 12345) & RAND_MAX);
}
#undef srand
void srand(unsigned int seed)
{
next = seed;
}
|
the_stack_data/211079948.c |
/* Exercise 1 - Calculations
Write a C program to input marks of two subjects. Calculate and print the average of the two marks. */
#include <stdio.h>
int main() { //start main function
int mark1, mark2; //declare variables
float avg;
printf("enter mark 1 :"); //dsplay enter mark 1
scanf("%d", &mark1); //enter mark from keyboard
printf("enter mark 2:"); //display enter mark 2
scanf("%d", &mark2); //enter mark from keyboard
avg = (mark1 + mark2)/2.0; //calculate average
printf("average is %.2f", avg); //print average
return 0;
} //end of main function
|
the_stack_data/119265.c | /*
* Copyright(C) 2008-2017 National Technology & Engineering Solutions
* of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
* NTESS, the U.S. Government retains certain rights in this software.
*
* 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 NTESS nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/*
* $Id: exdate.c,v 1.19 2008/03/14 13:22:36 gdsjaar Exp $
*/
/*
C DESCRIPTION:
C This routine returns the current date in a character string. The
C format is as follows:
C
C YYYYMMDD
C
C MM is a two digit month
C DD is a two digit day
C YYYY is a four digit year
C
C This is known as the "Compact ISO 8601 format"
C
C FORMAL PARAMETERS:
C STRING CHARACTER String to receive the date
C
************************************************************************
C
*/
#define STRLEN 8
#include <stdio.h> // for sprintf
#include <string.h> // for strncpy
#include <time.h> // for tm, localtime, time, time_t
#if defined(ADDC_)
void exdate_(char *string, long int len)
#else
void exdate(char *string, long int len)
#endif
{
struct tm *t;
time_t tim;
char Temp[STRLEN + 1]; /* Temporary string storage slot. */
tim = time((time_t *)0);
t = localtime(&tim);
t->tm_year += 1900;
sprintf(Temp, "%04d%02d%02d", t->tm_year, t->tm_mon + 1, t->tm_mday);
strncpy(string, Temp, STRLEN);
}
|
the_stack_data/36092.c | /*numPass=9, numTotal=9
Verdict:ACCEPTED, Visibility:1, Input:"5
abcde", ExpOutput:"Good String", Output:"Good String"
Verdict:ACCEPTED, Visibility:1, Input:"8
pqrsabcd", ExpOutput:"Good String", Output:"Good String"
Verdict:ACCEPTED, Visibility:1, Input:"4
azpg", ExpOutput:"Not Good String", Output:"Not Good String"
Verdict:ACCEPTED, Visibility:1, Input:"7
labexam", ExpOutput:"Not Good String", Output:"Not Good String"
Verdict:ACCEPTED, Visibility:0, Input:"8
aaaazzzz", ExpOutput:"Good String", Output:"Good String"
Verdict:ACCEPTED, Visibility:0, Input:"6
abczpq", ExpOutput:"Not Good String", Output:"Not Good String"
Verdict:ACCEPTED, Visibility:0, Input:"6
abcpqz", ExpOutput:"Not Good String", Output:"Not Good String"
Verdict:ACCEPTED, Visibility:0, Input:"8
acegikmo", ExpOutput:"Good String", Output:"Good String"
Verdict:ACCEPTED, Visibility:0, Input:"ab", ExpOutput:"Good String", Output:"Good String"
*/
#include <stdio.h>
#include <stdlib.h>
int main(){
char *str;
int count=0;//counts no. of times condition is true
int len,i;
scanf("%d\n",&len);
str=(char*)malloc((len+1)*sizeof(char));//dynamic allocation
scanf("%s",str);
str[len]='\0';
if(len>1)
{ for(i=1;i<len;i++)
{ if((str[i]-str[i-1])==(str[len-i]-str[len-i-1]))
{
count++;
}
else if((str[i]-str[i-1])==(str[len-i-1]-str[len-i]))
{
count++;
}
}
if(count==len-1)
{printf("Good String");}
else
{printf("Not Good String");}
}
else if(len==1||len==0)
{printf("Good String");}
free(str);//free the space
return 0;
} |
the_stack_data/5447.c | #include <stdio.h>
size_t bitCountNaive(int num);
size_t bitCountBrian(int num);
size_t bitCount64(unsigned int num);
int main(void) {
int numOne = 3892;
printf("Total set bits in %d is %d.\n", numOne, bitCountNaive(numOne));
printf("Total set bits in %d is %d.\n", numOne, bitCountBrian(numOne));
return 0;
}
/* Naive bit counting approach.
* Iterate through the number, right shifting it one at a time. Bitwise AND
* after every iteration with 1, to detect the presence of a set bit on the
* rightmost bit.
*/
size_t bitCountNaive(int num) {
size_t count = 0;
for(size_t i = 0; num; num >>= 1)
count += num & 1;
return count;
}
/* Brian Kernighan's way
* Count the rightmost set bit. The rightmost set bit can be accessed by bitwise
* AND of the given number and the number one less than the given number.
*/
size_t bitCountBrian(int num) {
size_t count = 0;
for(; num; count++)
num &= num - 1;
return count;
}
|
the_stack_data/43888269.c | #include <stdio.h>
#include <stdlib.h>
int main()
{
int den,mesec,godina;
scanf("%d %d %d", &den, &mesec, &godina);
if(mesec >= 1 && mesec <= 12){
if((den >= 1 && den <= 31) && (mesec == 1 || mesec == 3 || mesec == 5 || mesec == 7 || mesec == 8 || mesec == 10 || mesec == 12)){
printf("DA\n");
}
else if ((den>=1 && den<=30) && (mesec==4 || mesec==6 || mesec==9 || mesec==11)){
printf("DA\n");
}
else if((den>=1 && den<=28) && (mesec==2)){
printf("DA\n");
}
else if((mesec == 2) && (den == 29) && (godina % 400 == 0 || (godina % 4 == 0 && godina % 100 != 0))) {
printf("DA\n");
} else {
printf("NE\n");
}
} else {
printf("NE\n");
}
return 0;
}
|
the_stack_data/6387917.c | /*
* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
*
* %sccs.include.redist.c%
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)send.c 8.2 (Berkeley) 02/21/94";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
#include <sys/socket.h>
#include <stddef.h>
ssize_t
send(s, msg, len, flags)
int s, flags;
size_t len;
const void *msg;
{
return (sendto(s, msg, len, flags, NULL, 0));
}
|
the_stack_data/1143962.c | /*
** Copyright 2001, Travis Geiselbrecht. All rights reserved.
** Distributed under the terms of the NewOS License.
*/
/*
* Copyright (c) 2008 Travis Geiselbrecht
*
* 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 <string.h>
#include <sys/types.h>
char *
strcat(char *dest, char const *src)
{
char *tmp = dest;
while (*dest)
dest++;
while ((*dest++ = *src++) != '\0')
;
return tmp;
}
|
the_stack_data/68887244.c | static const char* const cfg =
"H4sIAFc23ksAA31WTXPaMBC991eo01sOTQsNzVXIi9FgfVSSHThpaDCpZyjMpOSQ"
"f18Z27S21vjkee/tl3a98v0dcb+qP2RfHUqyfTuffm/P1fP2cHgnL+WxfN2eyx35"
"+U6eT8d99fL2Wn4myYkcT2dS7qrzR3J3/+HTrtxXx5JwmXEJ5PJcwYUyDFrmChqw"
"znDmekpq2NJTI8iXPiS4tkNs/TgjX68QSDrPYAB2Oj/7NrTWmk0nCNhTLmkBdTrF"
"gwMMnmHg9yHIn4RYOxydDOG60mmMinVcax+86KyFWNcHO90EFU4Q5RRVTmPliBTR"
"0szxAtiwTCUnXivjbOwGo5qwLuHS+SUSOWa64N4ZAJ/Rjcqjxmi3NEATzCNGNUls"
"bGgHlWgaGMeUXPDUw9qBkTTz85xnyX+ZtDyX1tEs84lidpydh5c47gg7sM34/Ibt"
"gB3YWsNu2A7Y1jaBeZ7GpaTaqAUCM1XEqCmYw7QsTqYPtkphC+Q0NUfs+2CrZCoB"
"1tQXebnU15xbxC2odT4P7eaphCQONsp3eYPwYZBoCiZ2XpPOULYaI9kS2ArJSiQP"
"yG7pgdfafuQ0fFFOrUBitTNvILzHjISnUSsoaD1ogiM9Nbl0XIBnOg/RHYS+R6ne"
"1HS9VdaFCcMaHDMDG5+ChHBTISeXhzXWrATkBFGy820l0qVCP3qQ9XSNkGHsLmQU"
"DCf/WaIWyDpqgqNj3TKRI4RpbcIacJzVXxszSG+tDnRoffgRoEKHn4MU2Z23NN2M"
"QH2biPqKyDYhzF9rQkWwzggAAA=="
;const char *on2_codec_build_config(void) {return cfg;}
|
the_stack_data/51699176.c | //MAYANK AGRAWAL 150101033
#include <stdio.h>
#include <stdlib.h>
// Global counter variable
int count=0;
//randomizing array function
void randomizeArray(int arr[], int arraysize){
int i;
//assigning random values to the array and putting a limit of 1000
for(i=0;i<arraysize;i++){
arr[i]=rand()%1000;
}
}
void merge(int arr[], int min, int mid, int max){
//initializing a temporary array to store the changes
int i=min, j=mid+1, tempArray[max-min+1],k=0;
//assigning minimum of the two sorted sub-arrays continually into the temporary array
while(i<=mid && j<=max){
count++;
if(arr[i]<=arr[j]){
tempArray[k++]=arr[i++];
}else{
tempArray[k++]=arr[j++];
}
}
//assigning the rest of the sub-array elements to the temp array
while(i<=mid){
tempArray[k++]=arr[i++];
}
while(j<=max){
tempArray[k++]=arr[j++];
}
//updating original array through the temp array
for(i=min,k=0;i<=max;i++,k++){
arr[i]=tempArray[k];
}
}
//merge sort function
void merge_Sort(int* arr, int min, int max){
if(max>min){
int mid=(min+max)/2;
// Sort first and second halves
merge_Sort(arr, min, mid);
merge_Sort(arr, mid+1, max);
merge(arr, min, mid, max);
}
}
int main(){
int arrsize, i;
printf("Enter the input size: ");
scanf("%d",&arrsize);
int arr[arrsize];
//randomizing the array and printing it
randomizeArray(arr, arrsize);
printf("Random Array:\n");
for(i=0;i<arrsize;i++){
printf("%d ",arr[i]);
}
//applying merge sort to the array by passing pointer to the array
merge_Sort(arr, 0,arrsize-1);
//printing sorted array
printf("\nMerge Sorted Array:\n");
for(i=0;i< arrsize;i++){
printf("%d ",arr[i]);
}
printf("\nNumber of comparisons made between elements of the array: %d\n",count);
return 0;
}
|
the_stack_data/775341.c | /* Exercise 1 - Calculations
Write a C program to input marks of two subjects. Calculate and print the average of the two marks. */
#include <stdio.h>
int main() {
int m1, m2;
float ave;
printf("Enter mark of 1st subject:");
scanf("%d", &m1);
printf("Enter mark of 2nd subject:");
scanf("%d", &m2);
ave = (m1 + m2) / 2.0;
printf("Your Average mark is : %.2f", ave);
return 0;
}
|
the_stack_data/154379.c | struct STy { int X; };
void bar(int *);
void foo(struct STy *S) {
#pragma spf transform replace(S) nostrict
bar (&S->X);
}
|
the_stack_data/72012513.c | /*
Copyright 2014-2016 Intel Corporation
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 <stdbool.h>
#include <stdio.h>
bool isPointerOnInt123456(void* ptr)
{
printf("ptr as int %d", *(int*)ptr);
return *(int*)ptr == 123456;
}
|
the_stack_data/12844.c | // Program 44: Program to find transpose of a matrix
#include <stdio.h>
int main()
{
int a[10][10], transpose[10][10], r, c, i, j;
printf("Enter rows and columns: ");
scanf("%d %d", &r, &c);
// Assigning elements to the matrix
printf("\nEnter matrix elements:\n");
for (i = 0; i < r; ++i)
for (j = 0; j < c; ++j) {
printf("Enter element a%d%d: ", i + 1, j + 1);
scanf("%d", &a[i][j]);
}
// Displaying the matrix a[][]
printf("\nEntered matrix: \n");
for (i = 0; i < r; ++i)
for (j = 0; j < c; ++j) {
printf("%d ", a[i][j]);
if (j == c - 1)
printf("\n");
}
// Finding the transpose of matrix a
for (i = 0; i < r; ++i)
for (j = 0; j < c; ++j) {
transpose[j][i] = a[i][j];
}
// Displaying the transpose of matrix a
printf("\nTranspose of the matrix:\n");
for (i = 0; i < c; ++i)
for (j = 0; j < r; ++j) {
printf("%d ", transpose[i][j]);
if (j == r - 1)
printf("\n");
}
return 0;
} |
the_stack_data/117327750.c | /*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <sys/types.h>
/*
* Setting thie value to 1 enables XPG4 mode for APIs
* which have differing runtime behaviour from XPG3 to XPG4.
* See usr/src/lib/libc/port/gen/xpg4.c for the default value.
*/
int __xpg4 = 1;
|
the_stack_data/165767267.c | #include <stdio.h>
int lcm(int b, int e){
int lcm = b>e?b:e;
while(lcm%b || lcm%e){
lcm++;
}
return lcm;
}
int main(){
printf("Enter two int:");
int b,e;
scanf("%d %d", &b, &e);
printf("LCM: %d\n", lcm(b,e));
} |
the_stack_data/192329957.c | #include <stdio.h>
#include <string.h>
#define LEN 30
int verifica(char s[]);
int main(void)
{
char str[LEN+1];
printf("Inserisci password: ");
scanf("%s", str);
if(verifica(str)) {
printf("Password valida.\n");
}
else {
printf("Password non valida.\n");
}
return 0;
}
int verifica(char s[])
{
int hasAdigit, hasAsymbol, threeconschars;
int i, efflen;
efflen = strlen(s);
hasAdigit = 0;
hasAsymbol = 0;
threeconschars = 0;
for(i=0;s[i]!='\0';i++) {
if(s[i]>='0'&&s[i]<='9') {
hasAdigit = 1;
}
if(!((s[i]>='0'&&s[i]<='9') || (s[i]>='A'&&s[i]<='Z') || (s[i]>='a'&&s[i]<='z'))) {
hasAsymbol = 1;
}
}
for(i=0;i<=efflen-2 && !threeconschars;i++){
if(s[i]==s[i+1]&&s[i]==s[i+2]) {
threeconschars = 1;
}
}
if(hasAdigit && hasAsymbol && efflen >= 8 && !threeconschars)
return 1;
else
return 0;
}
|
the_stack_data/84584.c | // RUN: %clang_cc1 -triple x86_64-apple-macosx10.10.0 -emit-llvm -Oz -o - %s | FileCheck %s
// CHECK: define{{.*}} i32 @foo2(i32 %a) local_unnamed_addr [[ATTRS2:#[0-9]+]] {
// CHECK: define{{.*}} i32 @foo1(i32 %a) local_unnamed_addr [[ATTRS1:#[0-9]+]] {
int foo1(int);
int foo2(int a) {
return foo1(a + 2);
}
__attribute__((optnone))
int foo1(int a) {
return a + 1;
}
// CHECK: attributes [[ATTRS2]] = { {{.*}}optsize{{.*}} }
// CHECK: attributes [[ATTRS1]] = { {{.*}}optnone{{.*}} }
|
the_stack_data/123877.c | /*
* libEtPan! -- a mail stuff library
*
* Copyright (C) 2001, 2005 - DINH Viet Hoa
* 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 libEtPan! project nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS 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 AUTHORS 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.
*/
/*
* $Id: mail_cache_lmdb.c,v 1.20 2018/10/12 13:39:40 lay Exp $
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#ifdef LMDB
#include "mail_cache_db.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <lmdb.h>
#include "libetpan-config.h"
#include "maillock.h"
static struct mail_cache_db * mail_cache_lmdb_new(MDB_env *env)
{
struct mail_cache_db * cache_db;
cache_db = malloc(sizeof(* cache_db));
if (cache_db == NULL)
return NULL;
cache_db->internal_database = env;
return cache_db;
}
static void mail_cache_db_free(struct mail_cache_db * cache_db)
{
free(cache_db);
}
void mail_cache_db_close(struct mail_cache_db * cache_db)
{
MDB_env *env;
env = cache_db->internal_database;
mdb_env_close(env);
mail_cache_db_free(cache_db);
}
int mail_cache_db_open(const char * filename,
struct mail_cache_db ** pcache_db)
{
int r;
struct mail_cache_db * cache_db;
MDB_env *env;
r = mdb_env_create(&env);
if (r != 0)
return -1;
r = mdb_env_set_mapsize(env, 512*1024*1024 /*max mmap and file size*/);
if (r != 0)
return -1;
r = mdb_env_open(env, filename, MDB_NOSUBDIR, 0660);
if (r != 0)
goto close_db;
cache_db = mail_cache_lmdb_new(env);
if (cache_db == NULL)
goto close_db;
* pcache_db = cache_db;
return 0;
close_db:
mdb_env_close(env);
return -1;
}
int mail_cache_db_open_lock(const char * filename,
struct mail_cache_db ** pcache_db)
{
int r;
struct mail_cache_db * cache_db;
r = maillock_write_lock(filename, -1);
if (r < 0)
goto err;
r = mail_cache_db_open(filename, &cache_db);
if (r < 0)
goto unlock;
* pcache_db = cache_db;
return 0;
unlock:
maillock_write_unlock(filename, -1);
err:
return -1;
}
void mail_cache_db_close_unlock(const char * filename,
struct mail_cache_db * cache_db)
{
mail_cache_db_close(cache_db);
maillock_write_unlock(filename, -1);
}
int mail_cache_db_put(struct mail_cache_db * cache_db,
const void * key, size_t key_len, const void * value, size_t value_len)
{
int r;
MDB_env *env;
MDB_txn *txn;
MDB_dbi dbi;
MDB_val mdb_key;
MDB_val mdb_val;
env = cache_db->internal_database;
mdb_key.mv_size = key_len;
mdb_key.mv_data = (void *) key;
mdb_val.mv_size = value_len;
mdb_val.mv_data = (void *) value;
r = mdb_txn_begin(env, NULL, 0, &txn);
if (r != 0)
return -1;
r = mdb_dbi_open(txn, NULL, 0, &dbi);
if (r != 0)
goto error;
r = mdb_put(txn, dbi, &mdb_key, &mdb_val, 0);
if (r != 0)
goto error;
mdb_txn_commit(txn);
return 0;
error:
mdb_txn_abort(txn);
return -1;
}
int mail_cache_db_get(struct mail_cache_db * cache_db,
const void * key, size_t key_len, void ** pvalue, size_t * pvalue_len)
{
int r;
MDB_env *env;
MDB_txn *txn;
MDB_dbi dbi;
MDB_val mdb_key;
MDB_val mdb_val;
env = cache_db->internal_database;
mdb_key.mv_size = key_len;
mdb_key.mv_data = (void *) key;
r = mdb_txn_begin(env, NULL, 0, &txn);
if (r != 0)
return -1;
r = mdb_dbi_open(txn, NULL, 0, &dbi);
if (r != 0)
goto error;
r = mdb_get(txn, dbi, &mdb_key, &mdb_val);
if (r != 0)
goto error;
* pvalue = mdb_val.mv_data;
* pvalue_len = mdb_val.mv_size;
mdb_txn_commit(txn);
return 0;
error:
mdb_txn_abort(txn);
return -1;
}
int mail_cache_db_del(struct mail_cache_db * cache_db,
const void * key, size_t key_len)
{
int r;
MDB_env *env;
MDB_txn *txn;
MDB_dbi dbi;
MDB_val mdb_key;
env = cache_db->internal_database;
mdb_key.mv_size = key_len;
mdb_key.mv_data = (void *) key;
r = mdb_txn_begin(env, NULL, 0, &txn);
if (r != 0)
return -1;
r = mdb_dbi_open(txn, NULL, 0, &dbi);
if (r != 0)
goto error;
r = mdb_del(txn, dbi, &mdb_key, NULL);
if (r != 0)
goto error;
return 0;
error:
mdb_txn_abort(txn);
return -1;
}
int mail_cache_db_clean_up(struct mail_cache_db * cache_db,
chash * exist)
{
int r;
MDB_env *env;
MDB_txn *txn;
MDB_dbi dbi;
MDB_cursor *cursor;
MDB_val mdb_key;
MDB_val mdb_val;
env = cache_db->internal_database;
r = mdb_txn_begin(env, NULL, 0, &txn);
if (r != 0)
return -1;
r = mdb_dbi_open(txn, NULL, 0, &dbi);
if (r != 0)
goto error;
r = mdb_cursor_open(txn, dbi, &cursor);
if (r != 0)
goto error;
r = mdb_cursor_get(cursor, &mdb_key, &mdb_val, MDB_FIRST);
if (r != 0)
goto cursor_error;
while (r == 0) {
chashdatum hash_key;
chashdatum hash_data;
hash_key.data = mdb_key.mv_data;
hash_key.len = (unsigned int) mdb_key.mv_size;
r = chash_get(exist, &hash_key, &hash_data);
if (r < 0) {
r = mdb_cursor_del(cursor, 0);
if (r != 0)
goto cursor_error;
}
r = mdb_cursor_get(cursor, &mdb_key, &mdb_val, MDB_NEXT);
}
mdb_txn_commit(txn);
return 0;
cursor_error:
mdb_cursor_close(cursor);
error:
mdb_txn_abort(txn);
return -1;
}
int mail_cache_db_get_size(struct mail_cache_db * cache_db,
const void * key, size_t key_len, size_t * pvalue_len)
{
int r;
MDB_env *env;
MDB_txn *txn;
MDB_dbi dbi;
MDB_val mdb_key;
MDB_val mdb_val;
env = cache_db->internal_database;
mdb_key.mv_size = key_len;
mdb_key.mv_data = (void *) key;
r = mdb_txn_begin(env, NULL, 0, &txn);
if (r != 0)
return -1;
r = mdb_dbi_open(txn, NULL, 0, &dbi);
if (r != 0)
goto error;
r = mdb_get(txn, dbi, &mdb_key, &mdb_val);
if (r != 0)
goto error;
* pvalue_len = mdb_val.mv_size;
mdb_txn_commit(txn);
return 0;
error:
mdb_txn_abort(txn);
return -1;
}
int mail_cache_db_get_keys(struct mail_cache_db * cache_db,
chash * keys)
{
int r;
MDB_env *env;
MDB_txn *txn;
MDB_dbi dbi;
MDB_cursor *cursor;
MDB_val mdb_key;
MDB_val mdb_val;
env = cache_db->internal_database;
r = mdb_txn_begin(env, NULL, 0, &txn);
if (r != 0)
return -1;
r = mdb_dbi_open(txn, NULL, 0, &dbi);
if (r != 0)
goto error;
r = mdb_cursor_open(txn, dbi, &cursor);
if (r != 0)
goto error;
r = mdb_cursor_get(cursor, &mdb_key, &mdb_val, MDB_FIRST);
if (r != 0)
goto cursor_error;
while (r == 0) {
chashdatum hash_key;
chashdatum hash_data;
hash_key.data = mdb_key.mv_data;
hash_key.len = (unsigned int) mdb_key.mv_size;
hash_data.data = NULL;
hash_data.len = 0;
r = chash_set(keys, &hash_key, &hash_data, NULL);
if (r != 0)
goto cursor_error;
r = mdb_cursor_get(cursor, &mdb_key, &mdb_val, MDB_NEXT);
}
mdb_txn_commit(txn);
return 0;
cursor_error:
mdb_cursor_close(cursor);
error:
mdb_txn_abort(txn);
return -1;
}
#endif
|
the_stack_data/543995.c | /* PR middle-end/48044 */
/* { dg-do compile } */
/* { dg-require-alias "" } */
#define ASMNAME(cname) ASMNAME2 (__USER_LABEL_PREFIX__, cname)
#define ASMNAME2(prefix, cname) STRING (prefix) cname
#define STRING(x) #x
int a __asm__ (ASMNAME ("b")) = 0;
extern int c __asm__ (ASMNAME ("a")) __attribute__ ((alias ("b")));
extern int d __attribute__ ((weak, alias ("a")));
|
the_stack_data/43784.c | // RUN: %llvmgcc %s -S -emit-llvm -o - | llvm-as | llvm-dis | \
// RUN: grep llvm.used | grep foo | grep X
int X __attribute__((used));
int Y;
__attribute__((used)) void foo() {}
|
the_stack_data/14199312.c | /* { dg-do compile { target { *-*-linux* && ia32 } } } */
/* { dg-options "-O2 -fpic -fno-plt -mregparm=3" } */
extern void bar (int, int, int);
void
foo (int a, int b, int c)
{
bar (a, b, c);
bar (a, b, c);
}
/* { dg-final { scan-assembler-not "jmp\[ \t\]*.bar@GOT" } } */
|
the_stack_data/29095.c | void main()
{
char b;
b = 1 || 2 || 3 || 4;
if (!b)
print("b");
print("b #");
printid(b);
} |
the_stack_data/111076998.c | /*
* This is a sample C-program using linux POSIX threads and usage of
* mutexes over global variables.
*/
#include<pthread.h>
#include<stdio.h>
/*
* Maximum number of threads
*/
#define MAX_THREADS 5
int count = 0; // Global variable across threads
pthread_mutex_t count_mutex; // Mutex to guard the global variable
pthread_rwlock_t count_lock; // Read-write lock to guard the global
// variable
/*
* Thread function
*/
void *inc_count(void *t)
{
/* Lock the mutex */
pthread_mutex_lock(&count_mutex);
/* Take the read-write lock */
//pthread_rwlock_wrlock(&count_lock);
/* Increment the global count */
++count;
printf("The value of count is %d\n", count);
/* Release the read-write lock */
//pthread_rwlock_unlock(&count_lock);
/* Un-lock the mutex */
pthread_mutex_unlock(&count_mutex);
}
int main ()
{
int index;
pthread_t threads[MAX_THREADS];
/* Initialize the mutex */
pthread_mutex_init(&count_mutex, NULL);
/* Initialize the read-write lock */
//pthread_rwlock_init(&count_lock, NULL);
/* Create POSIX threads with a thread function */
for (index = 0; index < MAX_THREADS; ++index) {
pthread_create(&threads[index], NULL, inc_count, NULL);
}
/* Wait for the POSIX threads to finish thread function */
for (index = 0; index < MAX_THREADS; ++index) {
pthread_join(threads[index], NULL);
}
return(0);
}
|
the_stack_data/106262.c | /*
Given an array, rotate the array to the right by k steps, where k is non-negative.
From Leetcode : https://leetcode.com/problems/rotate-array/
*/
void reverse(int* nums, int i, int j) {
int le = i;
int ri = j;
while (le < ri) {
int temp = nums[le];
nums[le] = nums[ri];
nums[ri] = temp;
le++;
ri--;
}
}
void rotate(int* nums, int numsSize, int k){
k = k % numsSize;
reverse(nums, 0, numsSize - k - 1);
reverse(nums, numsSize - k, numsSize-1);
reverse(nums, 0, numsSize - 1);
}
|
the_stack_data/48576339.c | /*
*************************************************************************
* Ralink Tech Inc.
* 5F., No.36, Taiyuan St., Jhubei City,
* Hsinchu County 302,
* Taiwan, R.O.C.
*
* (c) Copyright 2002-2010, Ralink Technology, Inc.
*
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
* *
*************************************************************************/
#ifdef RT_CFG80211_SUPPORT
#include "rt_config.h"
#define RT_CFG80211_DEBUG /* debug use */
#define CFG80211CB (pAd->pCfg80211_CB)
#ifdef RT_CFG80211_DEBUG
#define CFG80211DBG(__Flg, __pMsg) DBGPRINT(__Flg, __pMsg)
#else
#define CFG80211DBG(__Flg, __pMsg)
#endif /* RT_CFG80211_DEBUG */
INT CFG80211DRV_IoctlHandle(
IN VOID *pAdSrc,
IN RTMP_IOCTL_INPUT_STRUCT *wrq,
IN INT cmd,
IN USHORT subcmd,
IN VOID *pData,
IN ULONG Data)
{
PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdSrc;
switch(cmd)
{
case CMD_RTPRIV_IOCTL_80211_START:
case CMD_RTPRIV_IOCTL_80211_END:
/* nothing to do */
break;
case CMD_RTPRIV_IOCTL_80211_CB_GET:
*(VOID **)pData = (VOID *)(pAd->pCfg80211_CB);
break;
case CMD_RTPRIV_IOCTL_80211_CB_SET:
pAd->pCfg80211_CB = pData;
break;
case CMD_RTPRIV_IOCTL_80211_CHAN_SET:
if (CFG80211DRV_OpsSetChannel(pAd, pData) != TRUE)
return NDIS_STATUS_FAILURE;
break;
case CMD_RTPRIV_IOCTL_80211_VIF_CHG:
if (CFG80211DRV_OpsChgVirtualInf(pAd, pData, Data) != TRUE)
return NDIS_STATUS_FAILURE;
break;
case CMD_RTPRIV_IOCTL_80211_SCAN:
CFG80211DRV_OpsScan(pAd);
break;
case CMD_RTPRIV_IOCTL_80211_IBSS_JOIN:
CFG80211DRV_OpsJoinIbss(pAd, pData);
break;
case CMD_RTPRIV_IOCTL_80211_STA_LEAVE:
CFG80211DRV_OpsLeave(pAd);
break;
case CMD_RTPRIV_IOCTL_80211_STA_GET:
if (CFG80211DRV_StaGet(pAd, pData) != TRUE)
return NDIS_STATUS_FAILURE;
break;
case CMD_RTPRIV_IOCTL_80211_KEY_ADD:
CFG80211DRV_KeyAdd(pAd, pData);
break;
case CMD_RTPRIV_IOCTL_80211_KEY_DEFAULT_SET:
#ifdef CONFIG_STA_SUPPORT
pAd->StaCfg.DefaultKeyId = Data; /* base 0 */
#endif /* CONFIG_STA_SUPPORT */
break;
case CMD_RTPRIV_IOCTL_80211_CONNECT_TO:
CFG80211DRV_Connect(pAd, pData);
break;
#ifdef RFKILL_HW_SUPPORT
case CMD_RTPRIV_IOCTL_80211_RFKILL:
{
UINT32 data = 0;
BOOLEAN active;
/* Read GPIO pin2 as Hardware controlled radio state */
RTMP_IO_READ32(pAd, GPIO_CTRL_CFG, &data);
active = !!(data & 0x04);
if (!active)
{
RTMPSetLED(pAd, LED_RADIO_OFF);
*(UINT8 *)pData = 0;
}
else
*(UINT8 *)pData = 1;
}
break;
#endif /* RFKILL_HW_SUPPORT */
case CMD_RTPRIV_IOCTL_80211_REG_NOTIFY_TO:
CFG80211DRV_RegNotify(pAd, pData);
break;
case CMD_RTPRIV_IOCTL_80211_UNREGISTER:
CFG80211_UnRegister(pAd, pData);
break;
case CMD_RTPRIV_IOCTL_80211_BANDINFO_GET:
{
CFG80211_BAND *pBandInfo = (CFG80211_BAND *)pData;
CFG80211_BANDINFO_FILL(pAd, pBandInfo);
}
break;
case CMD_RTPRIV_IOCTL_80211_SURVEY_GET:
CFG80211DRV_SurveyGet(pAd, pData);
break;
#ifdef RT_P2P_SPECIFIC_WIRELESS_EVENT
case CMD_RTPRIV_IOCTL_80211_SEND_WIRELESS_EVENT:
CFG80211_SendWirelessEvent(pAd, pData);
break;
#endif /* RT_P2P_SPECIFIC_WIRELESS_EVENT */
default:
return NDIS_STATUS_FAILURE;
}
return NDIS_STATUS_SUCCESS;
}
BOOLEAN CFG80211DRV_OpsSetChannel(
VOID *pAdOrg,
VOID *pData)
{
PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdOrg;
CMD_RTPRIV_IOCTL_80211_CHAN *pChan;
UINT8 ChanId;
UINT8 IfType;
UINT8 ChannelType;
STRING ChStr[5] = { 0 };
#ifdef DOT11_N_SUPPORT
UCHAR BW_Old;
BOOLEAN FlgIsChanged;
#endif /* DOT11_N_SUPPORT */
/* init */
pChan = (CMD_RTPRIV_IOCTL_80211_CHAN *)pData;
ChanId = pChan->ChanId;
IfType = pChan->IfType;
ChannelType = pChan->ChanType;
#ifdef DOT11_N_SUPPORT
if (IfType != RT_CMD_80211_IFTYPE_MONITOR)
{
/* get channel BW */
FlgIsChanged = FALSE;
BW_Old = pAd->CommonCfg.RegTransmitSetting.field.BW;
/* set to new channel BW */
if (ChannelType == RT_CMD_80211_CHANTYPE_HT20)
{
pAd->CommonCfg.RegTransmitSetting.field.BW = BW_20;
FlgIsChanged = TRUE;
}
else if ((ChannelType == RT_CMD_80211_CHANTYPE_HT40MINUS) ||
(ChannelType == RT_CMD_80211_CHANTYPE_HT40PLUS))
{
/* not support NL80211_CHAN_HT40MINUS or NL80211_CHAN_HT40PLUS */
/* i.e. primary channel = 36, secondary channel must be 40 */
pAd->CommonCfg.RegTransmitSetting.field.BW = BW_40;
FlgIsChanged = TRUE;
} /* End of if */
CFG80211DBG(RT_DEBUG_ERROR, ("80211> New BW = %d\n",
pAd->CommonCfg.RegTransmitSetting.field.BW));
/* change HT/non-HT mode (do NOT change wireless mode here) */
if (((ChannelType == RT_CMD_80211_CHANTYPE_NOHT) &&
(pAd->CommonCfg.HT_Disable == 0)) ||
((ChannelType != RT_CMD_80211_CHANTYPE_NOHT) &&
(pAd->CommonCfg.HT_Disable == 1)))
{
if (ChannelType == RT_CMD_80211_CHANTYPE_NOHT)
pAd->CommonCfg.HT_Disable = 1;
else
pAd->CommonCfg.HT_Disable = 0;
/* End of if */
FlgIsChanged = TRUE;
CFG80211DBG(RT_DEBUG_ERROR, ("80211> HT Disable = %d\n",
pAd->CommonCfg.HT_Disable));
} /* End of if */
}
else
{
/* for monitor mode */
FlgIsChanged = TRUE;
pAd->CommonCfg.HT_Disable = 0;
pAd->CommonCfg.RegTransmitSetting.field.BW = BW_40;
} /* End of if */
if (FlgIsChanged == TRUE)
SetCommonHT(pAd);
/* End of if */
#endif /* DOT11_N_SUPPORT */
/* switch to the channel */
sprintf(ChStr, "%d", ChanId);
if (Set_Channel_Proc(pAd, ChStr) == FALSE)
{
CFG80211DBG(RT_DEBUG_ERROR, ("80211> Change channel fail!\n"));
} /* End of if */
#ifdef CONFIG_STA_SUPPORT
#ifdef DOT11_N_SUPPORT
if ((IfType == RT_CMD_80211_IFTYPE_STATION) && (FlgIsChanged == TRUE))
{
/*
1. Station mode;
2. New BW settings is 20MHz but current BW is not 20MHz;
3. New BW settings is 40MHz but current BW is 20MHz;
Re-connect to the AP due to BW 20/40 or HT/non-HT change.
*/
Set_SSID_Proc(pAd, (PSTRING)pAd->CommonCfg.Ssid);
} /* End of if */
#endif /* DOT11_N_SUPPORT */
if (IfType == RT_CMD_80211_IFTYPE_ADHOC)
{
/* update IBSS beacon */
MlmeUpdateTxRates(pAd, FALSE, 0);
MakeIbssBeacon(pAd);
AsicEnableIbssSync(pAd);
Set_SSID_Proc(pAd, (PSTRING)pAd->CommonCfg.Ssid);
} /* End of if */
if (IfType == RT_CMD_80211_IFTYPE_MONITOR)
{
/* reset monitor mode in the new channel */
Set_NetworkType_Proc(pAd, "Monitor");
RTMP_IO_WRITE32(pAd, RX_FILTR_CFG, pChan->MonFilterFlag);
} /* End of if */
#endif /* CONFIG_STA_SUPPORT */
return TRUE;
}
BOOLEAN CFG80211DRV_OpsChgVirtualInf(
VOID *pAdOrg,
VOID *pFlgFilter,
UINT8 IfType)
{
#ifdef CONFIG_STA_SUPPORT
PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdOrg;
UINT32 FlgFilter = *(UINT32 *)pFlgFilter;
/* change type */
if (IfType == RT_CMD_80211_IFTYPE_ADHOC)
Set_NetworkType_Proc(pAd, "Adhoc");
else if (IfType == RT_CMD_80211_IFTYPE_STATION)
Set_NetworkType_Proc(pAd, "Infra");
else if (IfType == RT_CMD_80211_IFTYPE_MONITOR)
{
/* set packet filter */
Set_NetworkType_Proc(pAd, "Monitor");
if (FlgFilter != 0)
{
UINT32 Filter;
RTMP_IO_READ32(pAd, RX_FILTR_CFG, &Filter);
if ((FlgFilter & RT_CMD_80211_FILTER_FCSFAIL) == \
RT_CMD_80211_FILTER_FCSFAIL)
{
Filter = Filter & (~0x01);
}
else
Filter = Filter | 0x01;
/* End of if */
if ((FlgFilter & RT_CMD_80211_FILTER_PLCPFAIL) == \
RT_CMD_80211_FILTER_PLCPFAIL)
{
Filter = Filter & (~0x02);
}
else
Filter = Filter | 0x02;
/* End of if */
if ((FlgFilter & RT_CMD_80211_FILTER_CONTROL) == \
RT_CMD_80211_FILTER_CONTROL)
{
Filter = Filter & (~0xFF00);
}
else
Filter = Filter | 0xFF00;
/* End of if */
if ((FlgFilter & RT_CMD_80211_FILTER_OTHER_BSS) == \
RT_CMD_80211_FILTER_OTHER_BSS)
{
Filter = Filter & (~0x08);
}
else
Filter = Filter | 0x08;
/* End of if */
RTMP_IO_WRITE32(pAd, RX_FILTR_CFG, Filter);
*(UINT32 *)pFlgFilter = Filter;
} /* End of if */
return TRUE; /* not need to set SSID */
} /* End of if */
pAd->StaCfg.bAutoReconnect = TRUE;
CFG80211DBG(RT_DEBUG_ERROR, ("80211> SSID = %s\n", pAd->CommonCfg.Ssid));
Set_SSID_Proc(pAd, (PSTRING)pAd->CommonCfg.Ssid);
#endif /* CONFIG_STA_SUPPORT */
return TRUE;
}
BOOLEAN CFG80211DRV_OpsScan(
VOID *pAdOrg)
{
PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdOrg;
if (pAd->FlgCfg80211Scanning == TRUE)
return FALSE; /* scanning */
/* End of if */
/* do scan */
pAd->FlgCfg80211Scanning = TRUE;
return TRUE;
}
BOOLEAN CFG80211DRV_OpsJoinIbss(
VOID *pAdOrg,
VOID *pData)
{
#ifdef CONFIG_STA_SUPPORT
PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdOrg;
CMD_RTPRIV_IOCTL_80211_IBSS *pIbssInfo;
pIbssInfo = (CMD_RTPRIV_IOCTL_80211_IBSS *)pData;
pAd->StaCfg.bAutoReconnect = TRUE;
pAd->CommonCfg.BeaconPeriod = pIbssInfo->BeaconInterval;
Set_SSID_Proc(pAd, (PSTRING)pIbssInfo->pSsid);
#endif /* CONFIG_STA_SUPPORT */
return TRUE;
}
BOOLEAN CFG80211DRV_OpsLeave(
VOID *pAdOrg)
{
#ifdef CONFIG_STA_SUPPORT
PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdOrg;
pAd->StaCfg.bAutoReconnect = FALSE;
pAd->FlgCfg80211Connecting = FALSE;
LinkDown(pAd, FALSE);
#endif /* CONFIG_STA_SUPPORT */
return TRUE;
}
BOOLEAN CFG80211DRV_StaGet(
VOID *pAdOrg,
VOID *pData)
{
PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdOrg;
CMD_RTPRIV_IOCTL_80211_STA *pIbssInfo;
pIbssInfo = (CMD_RTPRIV_IOCTL_80211_STA *)pData;
#ifdef CONFIG_STA_SUPPORT
{
HTTRANSMIT_SETTING PhyInfo;
ULONG DataRate = 0;
UINT32 RSSI;
/* fill tx rate */
if ((!WMODE_CAP_N(pAd->CommonCfg.PhyMode)) ||
(pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= MODE_OFDM))
{
PhyInfo.word = pAd->StaCfg.HTPhyMode.word;
}
else
PhyInfo.word = pAd->MacTab.Content[BSSID_WCID].HTPhyMode.word;
/* End of if */
getRate(PhyInfo, &DataRate);
if ((PhyInfo.field.MODE == MODE_HTMIX) ||
(PhyInfo.field.MODE == MODE_HTGREENFIELD))
{
if (PhyInfo.field.BW)
pIbssInfo->TxRateFlags |= RT_CMD_80211_TXRATE_BW_40;
/* End of if */
if (PhyInfo.field.ShortGI)
pIbssInfo->TxRateFlags |= RT_CMD_80211_TXRATE_SHORT_GI;
/* End of if */
pIbssInfo->TxRateMCS = PhyInfo.field.MCS;
}
else
{
pIbssInfo->TxRateFlags = RT_CMD_80211_TXRATE_LEGACY;
pIbssInfo->TxRateMCS = DataRate*10; /* unit: 100kbps */
} /* End of if */
/* fill signal */
RSSI = (pAd->StaCfg.RssiSample.AvgRssi0 +
pAd->StaCfg.RssiSample.AvgRssi1 +
pAd->StaCfg.RssiSample.AvgRssi2) / 3;
pIbssInfo->Signal = RSSI;
}
#endif /* CONFIG_STA_SUPPORT */
return TRUE;
}
BOOLEAN CFG80211DRV_KeyAdd(
VOID *pAdOrg,
VOID *pData)
{
#ifdef CONFIG_STA_SUPPORT
PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdOrg;
CMD_RTPRIV_IOCTL_80211_KEY *pKeyInfo;
pKeyInfo = (CMD_RTPRIV_IOCTL_80211_KEY *)pData;
if (pKeyInfo->KeyType == RT_CMD_80211_KEY_WEP)
{
switch(pKeyInfo->KeyId)
{
case 1:
default:
Set_Key1_Proc(pAd, (PSTRING)pKeyInfo->KeyBuf);
break;
case 2:
Set_Key2_Proc(pAd, (PSTRING)pKeyInfo->KeyBuf);
break;
case 3:
Set_Key3_Proc(pAd, (PSTRING)pKeyInfo->KeyBuf);
break;
case 4:
Set_Key4_Proc(pAd, (PSTRING)pKeyInfo->KeyBuf);
break;
} /* End of switch */
}
else
Set_WPAPSK_Proc(pAd, (PSTRING)pKeyInfo->KeyBuf);
#endif /* CONFIG_STA_SUPPORT */
return TRUE;
}
BOOLEAN CFG80211DRV_Connect(
VOID *pAdOrg,
VOID *pData)
{
#ifdef CONFIG_STA_SUPPORT
PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdOrg;
CMD_RTPRIV_IOCTL_80211_CONNECT *pConnInfo;
UCHAR SSID[NDIS_802_11_LENGTH_SSID];
UINT32 SSIDLen;
pConnInfo = (CMD_RTPRIV_IOCTL_80211_CONNECT *)pData;
/* change to infrastructure mode if we are in ADHOC mode */
Set_NetworkType_Proc(pAd, "Infra");
/* set authentication mode */
if (pConnInfo->WpaVer == 2)
{
if (pConnInfo->FlgIs8021x == TRUE)
Set_AuthMode_Proc(pAd, "WPA2");
else
Set_AuthMode_Proc(pAd, "WPA2PSK");
/* End of if */
}
else if (pConnInfo->WpaVer == 1)
{
if (pConnInfo->FlgIs8021x == TRUE)
Set_AuthMode_Proc(pAd, "WPA");
else
Set_AuthMode_Proc(pAd, "WPAPSK");
/* End of if */
}
else if (pConnInfo->FlgIsAuthOpen == FALSE)
Set_AuthMode_Proc(pAd, "SHARED");
else
Set_AuthMode_Proc(pAd, "OPEN");
/* End of if */
CFG80211DBG(RT_DEBUG_ERROR,
("80211> AuthMode = %d\n", pAd->StaCfg.AuthMode));
/* set encryption mode */
if (pConnInfo->PairwiseEncrypType & RT_CMD_80211_CONN_ENCRYPT_CCMP)
Set_EncrypType_Proc(pAd, "AES");
else if (pConnInfo->PairwiseEncrypType & RT_CMD_80211_CONN_ENCRYPT_TKIP)
Set_EncrypType_Proc(pAd, "TKIP");
else if (pConnInfo->PairwiseEncrypType & RT_CMD_80211_CONN_ENCRYPT_WEP)
{
Set_EncrypType_Proc(pAd, "WEP");
}
else if (pConnInfo->GroupwiseEncrypType & RT_CMD_80211_CONN_ENCRYPT_CCMP)
Set_EncrypType_Proc(pAd, "AES");
else if (pConnInfo->GroupwiseEncrypType & RT_CMD_80211_CONN_ENCRYPT_TKIP)
Set_EncrypType_Proc(pAd, "TKIP");
else
Set_EncrypType_Proc(pAd, "NONE");
/* End of if */
CFG80211DBG(RT_DEBUG_ERROR,
("80211> EncrypType = %d\n", pAd->StaCfg.WepStatus));
/* set channel: STATION will auto-scan */
/* set WEP key */
if (pConnInfo->pKey &&
((pConnInfo->GroupwiseEncrypType | pConnInfo->PairwiseEncrypType) &
RT_CMD_80211_CONN_ENCRYPT_WEP))
{
UCHAR KeyBuf[50];
/* reset AuthMode and EncrypType */
Set_AuthMode_Proc(pAd, "SHARED");
Set_EncrypType_Proc(pAd, "WEP");
/* reset key */
#ifdef RT_CFG80211_DEBUG
hex_dump("KeyBuf=", (UINT8 *)pConnInfo->pKey, pConnInfo->KeyLen);
#endif /* RT_CFG80211_DEBUG */
pAd->StaCfg.DefaultKeyId = pConnInfo->KeyIdx; /* base 0 */
if (pConnInfo->KeyLen >= sizeof(KeyBuf))
return FALSE;
/* End of if */
memcpy(KeyBuf, pConnInfo->pKey, pConnInfo->KeyLen);
KeyBuf[pConnInfo->KeyLen] = 0x00;
CFG80211DBG(RT_DEBUG_ERROR,
("80211> pAd->StaCfg.DefaultKeyId = %d\n",
pAd->StaCfg.DefaultKeyId));
switch(pConnInfo->KeyIdx)
{
case 1:
default:
Set_Key1_Proc(pAd, (PSTRING)KeyBuf);
break;
case 2:
Set_Key2_Proc(pAd, (PSTRING)KeyBuf);
break;
case 3:
Set_Key3_Proc(pAd, (PSTRING)KeyBuf);
break;
case 4:
Set_Key4_Proc(pAd, (PSTRING)KeyBuf);
break;
} /* End of switch */
} /* End of if */
/* TODO: We need to provide a command to set BSSID to associate a AP */
/* re-set SSID */
pAd->StaCfg.bAutoReconnect = TRUE;
pAd->FlgCfg80211Connecting = TRUE;
SSIDLen = pConnInfo->SsidLen;
if (SSIDLen > NDIS_802_11_LENGTH_SSID)
SSIDLen = NDIS_802_11_LENGTH_SSID;
/* End of if */
memset(&SSID, 0, sizeof(SSID));
memcpy(SSID, pConnInfo->pSsid, SSIDLen);
Set_SSID_Proc(pAd, (PSTRING)SSID);
CFG80211DBG(RT_DEBUG_ERROR, ("80211> SSID = %s\n", SSID));
#endif /* CONFIG_STA_SUPPORT */
return TRUE;
}
VOID CFG80211DRV_RegNotify(
VOID *pAdOrg,
VOID *pData)
{
PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdOrg;
CMD_RTPRIV_IOCTL_80211_REG_NOTIFY *pRegInfo;
pRegInfo = (CMD_RTPRIV_IOCTL_80211_REG_NOTIFY *)pData;
/* keep Alpha2 and we can re-call the function when interface is up */
pAd->Cfg80211_Alpha2[0] = pRegInfo->Alpha2[0];
pAd->Cfg80211_Alpha2[1] = pRegInfo->Alpha2[1];
/* apply the new regulatory rule */
if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_START_UP))
{
/* interface is up */
CFG80211_RegRuleApply(pAd, pRegInfo->pWiphy, (UCHAR *)pRegInfo->Alpha2);
}
else
{
CFG80211DBG(RT_DEBUG_ERROR, ("crda> interface is down!\n"));
} /* End of if */
}
VOID CFG80211DRV_SurveyGet(
VOID *pAdOrg,
VOID *pData)
{
PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdOrg;
CMD_RTPRIV_IOCTL_80211_SURVEY *pSurveyInfo;
pSurveyInfo = (CMD_RTPRIV_IOCTL_80211_SURVEY *)pData;
pSurveyInfo->pCfg80211 = pAd->pCfg80211_CB;
#ifdef AP_QLOAD_SUPPORT
pSurveyInfo->ChannelTimeBusy = pAd->QloadLatestChannelBusyTimePri;
pSurveyInfo->ChannelTimeExtBusy = pAd->QloadLatestChannelBusyTimeSec;
#endif /* AP_QLOAD_SUPPORT */
}
VOID CFG80211_UnRegister(
IN VOID *pAdOrg,
IN VOID *pNetDev)
{
PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdOrg;
/* sanity check */
if (pAd->pCfg80211_CB == NULL)
return;
/* End of if */
CFG80211OS_UnRegister(pAd->pCfg80211_CB, pNetDev);
pAd->pCfg80211_CB = NULL;
pAd->CommonCfg.HT_Disable = 0;
}
/*
========================================================================
Routine Description:
Parse and handle country region in beacon from associated AP.
Arguments:
pAdCB - WLAN control block pointer
pVIE - Beacon elements
LenVIE - Total length of Beacon elements
Return Value:
NONE
Note:
========================================================================
*/
VOID CFG80211_BeaconCountryRegionParse(
IN VOID *pAdCB,
IN NDIS_802_11_VARIABLE_IEs *pVIE,
IN UINT16 LenVIE)
{
PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdCB;
UCHAR *pElement = (UCHAR *)pVIE;
UINT32 LenEmt;
while(LenVIE > 0)
{
pVIE = (NDIS_802_11_VARIABLE_IEs *)pElement;
if (pVIE->ElementID == IE_COUNTRY)
{
/* send command to do regulation hint only when associated */
RTEnqueueInternalCmd(pAd, CMDTHREAD_REG_HINT_11D,
pVIE->data, pVIE->Length);
break;
} /* End of if */
LenEmt = pVIE->Length + 2;
if (LenVIE <= LenEmt)
break; /* length is not enough */
/* End of if */
pElement += LenEmt;
LenVIE -= LenEmt;
} /* End of while */
} /* End of CFG80211_BeaconCountryRegionParse */
/*
========================================================================
Routine Description:
Hint to the wireless core a regulatory domain from driver.
Arguments:
pAd - WLAN control block pointer
pCountryIe - pointer to the country IE
CountryIeLen - length of the country IE
Return Value:
NONE
Note:
Must call the function in kernel thread.
========================================================================
*/
VOID CFG80211_RegHint(
IN VOID *pAdCB,
IN UCHAR *pCountryIe,
IN ULONG CountryIeLen)
{
PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdCB;
CFG80211OS_RegHint(CFG80211CB, pCountryIe, CountryIeLen);
} /* End of CFG80211_RegHint */
/*
========================================================================
Routine Description:
Hint to the wireless core a regulatory domain from country element.
Arguments:
pAdCB - WLAN control block pointer
pCountryIe - pointer to the country IE
CountryIeLen - length of the country IE
Return Value:
NONE
Note:
Must call the function in kernel thread.
========================================================================
*/
VOID CFG80211_RegHint11D(
IN VOID *pAdCB,
IN UCHAR *pCountryIe,
IN ULONG CountryIeLen)
{
/* no regulatory_hint_11d() in 2.6.32 */
PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdCB;
CFG80211OS_RegHint11D(CFG80211CB, pCountryIe, CountryIeLen);
} /* End of CFG80211_RegHint11D */
/*
========================================================================
Routine Description:
Apply new regulatory rule.
Arguments:
pAdCB - WLAN control block pointer
pWiphy - Wireless hardware description
pAlpha2 - Regulation domain (2B)
Return Value:
NONE
Note:
Can only be called when interface is up.
For general mac80211 device, it will be set to new power by Ops->config()
In rt2x00/, the settings is done in rt2x00lib_config().
========================================================================
*/
VOID CFG80211_RegRuleApply(
IN VOID *pAdCB,
IN VOID *pWiphy,
IN UCHAR *pAlpha2)
{
PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdCB;
VOID *pBand24G, *pBand5G;
UINT32 IdBand, IdChan, IdPwr;
UINT32 ChanNum, ChanId, Power, RecId, DfsType;
BOOLEAN FlgIsRadar;
ULONG IrqFlags;
#ifdef DFS_SUPPORT
RADAR_DETECT_STRUCT *pRadarDetect;
#endif /* DFS_SUPPORT */
CFG80211DBG(RT_DEBUG_ERROR, ("crda> CFG80211_RegRuleApply ==>\n"));
/* init */
pBand24G = NULL;
pBand5G = NULL;
if (pAd == NULL)
return;
RTMP_IRQ_LOCK(&pAd->irq_lock, IrqFlags);
/* zero first */
NdisZeroMemory(pAd->ChannelList,
MAX_NUM_OF_CHANNELS * sizeof(CHANNEL_TX_POWER));
/* 2.4GHZ & 5GHz */
RecId = 0;
#ifdef DFS_SUPPORT
pRadarDetect = &pAd->CommonCfg.RadarDetect;
#endif /* DFS_SUPPORT */
/* find the DfsType */
DfsType = CE;
pBand24G = NULL;
pBand5G = NULL;
if (CFG80211OS_BandInfoGet(CFG80211CB, pWiphy, &pBand24G, &pBand5G) == FALSE)
return;
#ifdef AUTO_CH_SELECT_ENHANCE
#ifdef EXT_BUILD_CHANNEL_LIST
if ((pAlpha2[0] != '0') && (pAlpha2[1] != '0'))
{
UINT32 IdReg;
if (pBand5G != NULL)
{
for(IdReg=0; ; IdReg++)
{
if (ChRegion[IdReg].CountReg[0] == 0x00)
break;
/* End of if */
if ((pAlpha2[0] == ChRegion[IdReg].CountReg[0]) &&
(pAlpha2[1] == ChRegion[IdReg].CountReg[1]))
{
if (pAd->CommonCfg.DfsType != MAX_RD_REGION)
DfsType = pAd->CommonCfg.DfsType;
else
DfsType = ChRegion[IdReg].DfsType;
CFG80211DBG(RT_DEBUG_ERROR,
("crda> find region %c%c, DFS Type %d\n",
pAlpha2[0], pAlpha2[1], DfsType));
break;
} /* End of if */
} /* End of for */
} /* End of if */
} /* End of if */
#endif /* EXT_BUILD_CHANNEL_LIST */
#endif /* AUTO_CH_SELECT_ENHANCE */
for(IdBand=0; IdBand<2; IdBand++)
{
if (((IdBand == 0) && (pBand24G == NULL)) ||
((IdBand == 1) && (pBand5G == NULL)))
{
continue;
} /* End of if */
if (IdBand == 0)
{
CFG80211DBG(RT_DEBUG_ERROR, ("crda> reset chan/power for 2.4GHz\n"));
}
else
{
CFG80211DBG(RT_DEBUG_ERROR, ("crda> reset chan/power for 5GHz\n"));
} /* End of if */
ChanNum = CFG80211OS_ChanNumGet(CFG80211CB, pWiphy, IdBand);
for(IdChan=0; IdChan<ChanNum; IdChan++)
{
if (CFG80211OS_ChanInfoGet(CFG80211CB, pWiphy, IdBand, IdChan,
&ChanId, &Power, &FlgIsRadar) == FALSE)
{
/* the channel is not allowed in the regulatory domain */
/* get next channel information */
continue;
}
if (!WMODE_CAP_2G(pAd->CommonCfg.PhyMode))
{
/* 5G-only mode */
if (ChanId <= CFG80211_NUM_OF_CHAN_2GHZ)
continue;
}
if (!WMODE_CAP_5G(pAd->CommonCfg.PhyMode))
{
/* 2.4G-only mode */
if (ChanId > CFG80211_NUM_OF_CHAN_2GHZ)
continue;
}
for(IdPwr=0; IdPwr<MAX_NUM_OF_CHANNELS; IdPwr++)
{
if (ChanId == pAd->TxPower[IdPwr].Channel)
{
/* init the channel info. */
NdisMoveMemory(&pAd->ChannelList[RecId],
&pAd->TxPower[IdPwr],
sizeof(CHANNEL_TX_POWER));
/* keep channel number */
pAd->ChannelList[RecId].Channel = ChanId;
/* keep maximum tranmission power */
pAd->ChannelList[RecId].MaxTxPwr = Power;
/* keep DFS flag */
if (FlgIsRadar == TRUE)
pAd->ChannelList[RecId].DfsReq = TRUE;
else
pAd->ChannelList[RecId].DfsReq = FALSE;
/* End of if */
/* keep DFS type */
pAd->ChannelList[RecId].RegulatoryDomain = DfsType;
/* re-set DFS info. */
pAd->CommonCfg.RDDurRegion = DfsType;
CFG80211DBG(RT_DEBUG_ERROR,
("Chan %03d:\tpower %d dBm, "
"DFS %d, DFS Type %d\n",
ChanId, Power,
((FlgIsRadar == TRUE)?1:0),
DfsType));
/* change to record next channel info. */
RecId ++;
break;
} /* End of if */
} /* End of for */
} /* End of for */
} /* End of for */
pAd->ChannelListNum = RecId;
RTMP_IRQ_UNLOCK(&pAd->irq_lock, IrqFlags);
CFG80211DBG(RT_DEBUG_ERROR, ("crda> Number of channels = %d\n", RecId));
} /* End of CFG80211_RegRuleApply */
/*
========================================================================
Routine Description:
Inform us that a scan is got.
Arguments:
pAdCB - WLAN control block pointer
Return Value:
NONE
Note:
Call RT_CFG80211_SCANNING_INFORM, not CFG80211_Scaning
========================================================================
*/
VOID CFG80211_Scaning(
IN VOID *pAdCB,
IN UINT32 BssIdx,
IN UINT32 ChanId,
IN UCHAR *pFrame,
IN UINT32 FrameLen,
IN INT32 RSSI)
{
#ifdef CONFIG_STA_SUPPORT
PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdCB;
VOID *pCfg80211_CB = pAd->pCfg80211_CB;
BOOLEAN FlgIsNMode;
UINT8 BW;
CFG80211DBG(RT_DEBUG_ERROR, ("80211> CFG80211_Scaning ==>\n"));
if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
{
DBGPRINT(RT_DEBUG_TRACE, ("80211> Network is down!\n"));
return;
} /* End of if */
/*
In connect function, we also need to report BSS information to cfg80211;
Not only scan function.
*/
if ((pAd->FlgCfg80211Scanning == FALSE) &&
(pAd->FlgCfg80211Connecting == FALSE))
{
return; /* no scan is running */
} /* End of if */
/* init */
/* Note: Can not use local variable to do pChan */
if (WMODE_CAP_N(pAd->CommonCfg.PhyMode))
FlgIsNMode = TRUE;
else
FlgIsNMode = FALSE;
if (pAd->CommonCfg.RegTransmitSetting.field.BW == BW_20)
BW = 0;
else
BW = 1;
CFG80211OS_Scaning(pCfg80211_CB,
ChanId,
pFrame,
FrameLen,
RSSI,
FlgIsNMode,
BW);
#endif /* CONFIG_STA_SUPPORT */
} /* End of CFG80211_Scaning */
/*
========================================================================
Routine Description:
Inform us that scan ends.
Arguments:
pAdCB - WLAN control block pointer
FlgIsAborted - 1: scan is aborted
Return Value:
NONE
Note:
========================================================================
*/
VOID CFG80211_ScanEnd(
IN VOID *pAdCB,
IN BOOLEAN FlgIsAborted)
{
#ifdef CONFIG_STA_SUPPORT
PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdCB;
if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE))
{
DBGPRINT(RT_DEBUG_TRACE, ("80211> Network is down!\n"));
return;
} /* End of if */
if (pAd->FlgCfg80211Scanning == FALSE)
{
DBGPRINT(RT_DEBUG_TRACE, ("80211> No scan is running!\n"));
return; /* no scan is running */
} /* End of if */
if (FlgIsAborted == TRUE)
FlgIsAborted = 1;
else
FlgIsAborted = 0;
/* End of if */
CFG80211OS_ScanEnd(CFG80211CB, FlgIsAborted);
pAd->FlgCfg80211Scanning = FALSE;
#endif /* CONFIG_STA_SUPPORT */
} /* End of CFG80211_ScanEnd */
/*
========================================================================
Routine Description:
Inform CFG80211 about association status.
Arguments:
pAdCB - WLAN control block pointer
pBSSID - the BSSID of the AP
pReqIe - the element list in the association request frame
ReqIeLen - the request element length
pRspIe - the element list in the association response frame
RspIeLen - the response element length
FlgIsSuccess - 1: success; otherwise: fail
Return Value:
None
Note:
========================================================================
*/
VOID CFG80211_ConnectResultInform(
IN VOID *pAdCB,
IN UCHAR *pBSSID,
IN UCHAR *pReqIe,
IN UINT32 ReqIeLen,
IN UCHAR *pRspIe,
IN UINT32 RspIeLen,
IN UCHAR FlgIsSuccess)
{
PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdCB;
CFG80211DBG(RT_DEBUG_ERROR, ("80211> CFG80211_ConnectResultInform ==>\n"));
CFG80211OS_ConnectResultInform(CFG80211CB,
pBSSID,
pReqIe,
ReqIeLen,
pRspIe,
RspIeLen,
FlgIsSuccess);
pAd->FlgCfg80211Connecting = FALSE;
} /* End of CFG80211_ConnectResultInform */
/*
========================================================================
Routine Description:
Re-Initialize wireless channel/PHY in 2.4GHZ and 5GHZ.
Arguments:
pAdCB - WLAN control block pointer
Return Value:
TRUE - re-init successfully
FALSE - re-init fail
Note:
CFG80211_SupBandInit() is called in xx_probe().
But we do not have complete chip information in xx_probe() so we
need to re-init bands in xx_open().
========================================================================
*/
BOOLEAN CFG80211_SupBandReInit(
IN VOID *pAdCB)
{
PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdCB;
CFG80211_BAND BandInfo;
CFG80211DBG(RT_DEBUG_ERROR, ("80211> re-init bands...\n"));
/* re-init bands */
NdisZeroMemory(&BandInfo, sizeof(BandInfo));
CFG80211_BANDINFO_FILL(pAd, &BandInfo);
return CFG80211OS_SupBandReInit(CFG80211CB, &BandInfo);
} /* End of CFG80211_SupBandReInit */
#ifdef RT_P2P_SPECIFIC_WIRELESS_EVENT
INT CFG80211_SendWirelessEvent(
IN VOID *pAdCB,
IN UCHAR *pMacAddr)
{
PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdCB;
P2pSendWirelessEvent(pAd, RT_P2P_CONNECTED, NULL, pMacAddr);
return 0;
}
#endif /* RT_P2P_SPECIFIC_WIRELESS_EVENT */
#endif /* RT_CFG80211_SUPPORT */
/* End of cfg80211drv.c */
|
the_stack_data/121524.c | // RUN: mlir-clang %s %stdinclude --function=set -S | FileCheck %s
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <math.h>
/* Array initialization. */
int set (int b)
{
int res;
if (b)
res = 1;
else
res = 2;
return res;
//path[0][1] = 2;
}
// CHECK: func @set(%arg0: i32) -> i32
// CHCEK-NEXT: %c1_i32 = constant 1 : i32
// CHCEK-NEXT: %c2_i32 = constant 2 : i32
// CHCEK-NEXT: %0 = arith.trunci %arg0 : i32 to i1
// CHCEK-NEXT: %1 = arith.select %0, %c1_i32, %c2_i32 : i32
// CHCEK-NEXT: return %1 : i32
// CHCEK-NEXT: }
|
the_stack_data/184518118.c | /*
Jogo do Tijolo
https://www.urionlinejudge.com.br/judge/pt/problems/view/1436
*/
#include <stdio.h>
int main (void) {
int caso,
casos,
quantidade,
i,
indice,
idade;
scanf("%d", &casos);
for (caso = 1; caso <= casos; caso++) {
scanf("%d", &quantidade);
indice = quantidade / 2;
for (i = 0; i < quantidade; i++) {
if (i == indice) {
scanf("%d", &idade);
}
else {
scanf("%*d");
}
}
printf("Case %d: %d\n", caso, idade);
}
return 0;
}
|
the_stack_data/184519290.c | extern const unsigned char CalendarDateRangePickerVersionString[];
extern const double CalendarDateRangePickerVersionNumber;
const unsigned char CalendarDateRangePickerVersionString[] __attribute__ ((used)) = "@(#)PROGRAM:CalendarDateRangePicker PROJECT:Pods-1" "\n";
const double CalendarDateRangePickerVersionNumber __attribute__ ((used)) = (double)1.;
|
the_stack_data/76699312.c | /* Taxonomy Classification: 0000000300000000000200 */
/*
* WRITE/READ 0 write
* WHICH BOUND 0 upper
* DATA TYPE 0 char
* MEMORY LOCATION 0 stack
* SCOPE 0 same
* CONTAINER 0 no
* POINTER 0 no
* INDEX COMPLEXITY 3 non-linear expr
* ADDRESS COMPLEXITY 0 constant
* LENGTH COMPLEXITY 0 N/A
* ADDRESS ALIAS 0 none
* INDEX ALIAS 0 none
* LOCAL CONTROL FLOW 0 none
* SECONDARY CONTROL FLOW 0 none
* LOOP STRUCTURE 0 no
* LOOP COMPLEXITY 0 N/A
* ASYNCHRONY 0 no
* TAINT 0 no
* RUNTIME ENV. DEPENDENCE 0 no
* MAGNITUDE 2 8 bytes
* CONTINUOUS/DISCRETE 0 discrete
* SIGNEDNESS 0 no
*/
/*
Copyright 2004 M.I.T.
Permission is hereby granted, without written agreement or royalty fee, to use,
copy, modify, and distribute this software and its documentation for any
purpose, provided that the above copyright notice and the following three
paragraphs appear in all copies of this software.
IN NO EVENT SHALL M.I.T. BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE
AND ITS DOCUMENTATION, EVEN IF M.I.T. HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMANGE.
M.I.T. SPECIFICALLY DISCLAIMS ANY WARRANTIES INCLUDING, BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
AND NON-INFRINGEMENT.
THE SOFTWARE IS PROVIDED ON AN "AS-IS" BASIS AND M.I.T. HAS NO OBLIGATION TO
PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*/
int main(int argc, char *argv[])
{
int i;
char buf[10];
i = 18;
/* BAD */
buf[17 % i] = 'A';
return 0;
}
|
the_stack_data/173578546.c | #include <stdio.h>
int main()
{
printf("sizeof(char)=%d\n", (int) sizeof(char));
printf("sizeof(short)=%d\n", (int) sizeof(short));
printf("sizeof(int)=%d\n", (int) sizeof(int));
printf("sizeof(long)=%d\n", (int) sizeof(long));
printf("sizeof(long long)=%d\n", (int) sizeof(long long));
printf("sizeof(unsigned char)=%d\n", (int) sizeof(unsigned char));
printf("sizeof(unsigned short)=%d\n", (int) sizeof(unsigned short));
printf("sizeof(unsigned int)=%d\n", (int) sizeof(unsigned int));
printf("sizeof(unsigned long)=%d\n", (int) sizeof(unsigned long));
printf("sizeof(unsigned long long)=%d\n", (int) sizeof(unsigned long long));
return(0);
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.