file
stringlengths 18
26
| data
stringlengths 3
1.04M
|
---|---|
the_stack_data/70449960.c | #ifdef N64VIDEO_C
static STRICTINLINE void vi_vl_lerp(struct rgba* up, struct rgba down, uint32_t frac)
{
uint32_t r0, g0, b0;
if (!frac)
return;
r0 = up->r;
g0 = up->g;
b0 = up->b;
up->r = ((((down.r - r0) * frac + 16) >> 5) + r0) & 0xff;
up->g = ((((down.g - g0) * frac + 16) >> 5) + g0) & 0xff;
up->b = ((((down.b - b0) * frac + 16) >> 5) + b0) & 0xff;
}
#endif // N64VIDEO_C
|
the_stack_data/9513420.c | // RUN: %libomp-compile && env OMP_NUM_THREADS='3' %libomp-run
// RUN: %libomp-compile && env OMP_NUM_THREADS='1' %libomp-run
// Checked gcc 10.1 still does not support detach clause on task construct.
// UNSUPPORTED: gcc-4, gcc-5, gcc-6, gcc-7, gcc-8, gcc-9, gcc-10
// gcc 11 introduced detach clause, but gomp interface in libomp has no support
// XFAIL: gcc-11, gcc-12
// clang supports detach clause since version 11.
// UNSUPPORTED: clang-10, clang-9, clang-8, clang-7
// icc compiler does not support detach clause.
// UNSUPPORTED: icc
#include <omp.h>
int main()
{
#pragma omp parallel
#pragma omp master
{
omp_event_handle_t event;
#pragma omp task detach(event)
{
omp_fulfill_event(event);
}
#pragma omp taskwait
}
return 0;
}
|
the_stack_data/40294.c | // - rlyeh, public domain
#ifndef MEMORY_H
#define MEMORY_H
#include <string.h>
#include <stdlib.h>
#ifndef REALLOC
#define REALLOC realloc
#endif
#define MALLOC(n) REALLOC(0, n)
#define FREE(p) REALLOC(p, 0)
#define CALLOC(c, n) memset(MALLOC((c)*(n)), 0, (c)*(n))
#define STRDUP(s) strcpy(MALLOC(strlen(s)+1), (s))
#ifndef MSIZE
# if defined _OSX || defined _BSD
# define MSIZE malloc_size
# elif defined _AND
# define MSIZE dlmalloc_usable_size
# elif defined _WIN
# define MSIZE _msize
# else
# define MSIZE malloc_usable_size // glibc
# endif
#endif
#endif
|
the_stack_data/148725.c | /*Write a function “quick_sort” to implement Quick Sort. Pass array
“arr” and size “n” as arguments from main.*/
#include<stdio.h>
void quick_sort(int [], int, int);
int main()
{
int i, size, list[50];
printf("\nEnter the number of elements : ");
scanf("%d", &size);
printf("\nEnter the elements to be sorted : ");
for(i=0; i<size; i++)
scanf("%d", &list[i]);
quick_sort(list, 0, size-1);
printf("\nAfter quick sort : \n");
for(i=0; i<size; i++)
printf("%d\t ", list[i]);
printf("\n");
return 0;
}
void quick_sort(int list[], int low, int high)
{
int pivot, i, j, temp;
if(low < high)
{
pivot = low;
i = low;
j = high;
while(i < j)
{
while(list[i] <= list[pivot] && i <= high)
i++;
while(list[j] > list[pivot] && j >= low)
j--;
if(i < j)
{
temp = list[i];
list[i] = list[j];
list[j] = temp;
}
}
temp = list[j];
list[j] = list[pivot];
list[pivot] = temp;
quick_sort(list, low, j-1);
quick_sort(list, j+1, high);
}
}
|
the_stack_data/153267956.c | /**
* Fibonacci series and even Fibonacci numbers.
* https://projecteuler.net/problem=2
*/
#include <stdio.h>
#define LIMIT 4000000
/**
* Print fibonacci series less than LIMIT.
*
* @param int a
* @param int b
*
* @return void
*/
void print_fibonacci_series(int a, int b)
{
int sum = a + b;
if (sum > LIMIT) {
return;
}
printf("%d ", sum);
print_fibonacci_series(b, sum);
}
/**
* Print N fibonacci series.
*
* @param int n
*
* @return unsigned long
*/
unsigned long num_fibonacci(int n)
{
if (n < 2) {
return (unsigned long) n;
}
return num_fibonacci(n - 1) + num_fibonacci(n - 2);
}
/**
* Get sum of even fibonacci series up to LIMIT.
*
* @param int a
* @param int b
* @param int c
*
* @return unsigned long
*/
unsigned long sum_even_fibonacci(int a, int b, int c)
{
static unsigned long sum = 0;
if (c > LIMIT) {
return 0;
}
sum += c;
a = b + c;
b = c + a;
sum_even_fibonacci(a, b, a + b);
return sum;
}
int main()
{
int limit;
print_fibonacci_series(-1, 1);
printf("\n\nSum of even fibonacci up to %d is %lu", LIMIT, sum_even_fibonacci(1, 1, 2));
printf("\n\nEnter N to print N fibonacci numbers: ");
scanf("%d", &limit);
for (int i = 0; i < limit; i++) {
printf("%lu ", num_fibonacci(i));
}
return 0;
}
|
the_stack_data/87094.c | #include <stdio.h>
struct Node{
char name[20];
struct Node* prev;
struct Node* next;
};
int main(){
struct Node a = {"1"};
struct Node b = {"2", &a};
struct Node c = {"3"};
struct Node d = {"4"};
a.next = &b;
b.next = &c;
c.prev = &b;
c.next = &d;
d.prev = &c;
d.next = NULL;
struct Node *head = &a;
while(head != NULL){
printf("%c \n",*head->name);
head = &(*head->next);
}
return 0;
} |
the_stack_data/32949894.c | #include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
typedef unsigned long u64;
static u64 get_rcx(void)
{
__asm__ __volatile__("push %rcx\n\t"
"movq $5, %rcx\n\t"
"movq %rcx, %rax");/* at&t syntax: movq <src_reg>, <dest_reg> */
__asm__ __volatile__("pop %rcx");
}
int main(void)
{
printf("Hello, inline assembly:\n [RCX] = 0x%lx\n", get_rcx());
exit(0);
}
|
the_stack_data/165764777.c | #ifdef COMPILE_FOR_TEST
#include <assert.h>
#define assume(cond) assert(cond)
#endif
void main(int argc, char* argv[]) {
int x_0_0;//sh_buf.outcnt
int x_0_1;//sh_buf.outcnt
int x_0_2;//sh_buf.outcnt
int x_0_3;//sh_buf.outcnt
int x_0_4;//sh_buf.outcnt
int x_1_0;//sh_buf.outbuf[0]
int x_1_1;//sh_buf.outbuf[0]
int x_2_0;//sh_buf.outbuf[1]
int x_2_1;//sh_buf.outbuf[1]
int x_3_0;//sh_buf.outbuf[2]
int x_3_1;//sh_buf.outbuf[2]
int x_4_0;//sh_buf.outbuf[3]
int x_4_1;//sh_buf.outbuf[3]
int x_5_0;//sh_buf.outbuf[4]
int x_5_1;//sh_buf.outbuf[4]
int x_6_0;//sh_buf.outbuf[5]
int x_7_0;//sh_buf.outbuf[6]
int x_8_0;//sh_buf.outbuf[7]
int x_9_0;//sh_buf.outbuf[8]
int x_10_0;//sh_buf.outbuf[9]
int x_11_0;//LOG_BUFSIZE
int x_11_1;//LOG_BUFSIZE
int x_12_0;//CREST_scheduler::lock_0
int x_12_1;//CREST_scheduler::lock_0
int x_12_2;//CREST_scheduler::lock_0
int x_12_3;//CREST_scheduler::lock_0
int x_12_4;//CREST_scheduler::lock_0
int x_13_0;//t3 T0
int x_14_0;//t2 T0
int x_15_0;//arg T0
int x_16_0;//functioncall::param T0
int x_16_1;//functioncall::param T0
int x_17_0;//buffered T0
int x_18_0;//functioncall::param T0
int x_18_1;//functioncall::param T0
int x_19_0;//functioncall::param T0
int x_19_1;//functioncall::param T0
int x_20_0;//functioncall::param T0
int x_20_1;//functioncall::param T0
int x_20_2;//functioncall::param T0
int x_20_3;//functioncall::param T0
int x_21_0;//functioncall::param T0
int x_21_1;//functioncall::param T0
int x_22_0;//direction T0
int x_23_0;//functioncall::param T0
int x_23_1;//functioncall::param T0
int x_24_0;//functioncall::param T0
int x_24_1;//functioncall::param T0
int x_25_0;//functioncall::param T0
int x_25_1;//functioncall::param T0
int x_26_0;//functioncall::param T0
int x_26_1;//functioncall::param T0
int x_27_0;//functioncall::param T0
int x_27_1;//functioncall::param T0
int x_28_0;//functioncall::param T0
int x_28_1;//functioncall::param T0
int x_29_0;//functioncall::param T0
int x_29_1;//functioncall::param T0
int x_30_0;//functioncall::param T0
int x_30_1;//functioncall::param T0
int x_31_0;//functioncall::param T0
int x_31_1;//functioncall::param T0
int x_32_0;//functioncall::param T0
int x_32_1;//functioncall::param T0
int x_33_0;//functioncall::param T0
int x_33_1;//functioncall::param T0
int x_34_0;//functioncall::param T0
int x_34_1;//functioncall::param T0
int x_35_0;//functioncall::param T1
int x_35_1;//functioncall::param T1
int x_36_0;//functioncall::param T1
int x_36_1;//functioncall::param T1
int x_37_0;//i T1
int x_37_1;//i T1
int x_37_2;//i T1
int x_38_0;//rv T1
int x_39_0;//rv T1
int x_40_0;//blocksize T1
int x_40_1;//blocksize T1
int x_41_0;//functioncall::param T1
int x_41_1;//functioncall::param T1
int x_41_2;//functioncall::param T1
int x_42_0;//apr_thread_mutex_lock::rv T1
int x_42_1;//apr_thread_mutex_lock::rv T1
int x_43_0;//functioncall::param T1
int x_43_1;//functioncall::param T1
int x_44_0;//status T1
int x_44_1;//status T1
int x_45_0;//functioncall::param T1
int x_45_1;//functioncall::param T1
int x_46_0;//functioncall::param T1
int x_46_1;//functioncall::param T1
int x_47_0;//functioncall::param T1
int x_47_1;//functioncall::param T1
int x_48_0;//functioncall::param T1
int x_48_1;//functioncall::param T1
int x_49_0;//functioncall::param T1
int x_49_1;//functioncall::param T1
int x_50_0;//functioncall::param T1
int x_50_1;//functioncall::param T1
int x_51_0;//functioncall::param T1
int x_51_1;//functioncall::param T1
int x_52_0;//functioncall::param T1
int x_52_1;//functioncall::param T1
int x_53_0;//functioncall::param T2
int x_53_1;//functioncall::param T2
int x_54_0;//functioncall::param T2
int x_54_1;//functioncall::param T2
int x_55_0;//i T2
int x_56_0;//rv T2
int x_57_0;//rv T2
int x_58_0;//blocksize T2
int x_58_1;//blocksize T2
int x_59_0;//functioncall::param T2
int x_59_1;//functioncall::param T2
int x_59_2;//functioncall::param T2
int x_60_0;//apr_thread_mutex_lock::rv T2
int x_60_1;//apr_thread_mutex_lock::rv T2
int x_61_0;//functioncall::param T2
int x_61_1;//functioncall::param T2
int x_62_0;//status T2
int x_62_1;//status T2
int x_63_0;//functioncall::param T2
int x_63_1;//functioncall::param T2
int x_64_0;//functioncall::param T2
int x_64_1;//functioncall::param T2
T_0_0_0: x_0_0 = 0;
T_0_1_0: x_1_0 = 0;
T_0_2_0: x_2_0 = 0;
T_0_3_0: x_3_0 = 0;
T_0_4_0: x_4_0 = 0;
T_0_5_0: x_5_0 = 0;
T_0_6_0: x_6_0 = 0;
T_0_7_0: x_7_0 = 0;
T_0_8_0: x_8_0 = 0;
T_0_9_0: x_9_0 = 0;
T_0_10_0: x_10_0 = 0;
T_0_11_0: x_11_0 = 0;
T_0_12_0: x_13_0 = 2139185808;
T_0_13_0: x_14_0 = 2742448736;
T_0_14_0: x_15_0 = 0;
T_0_15_0: x_16_0 = 1738271214;
T_0_16_0: x_16_1 = -1;
T_0_17_0: x_17_0 = 0;
T_0_18_0: x_18_0 = 1606917298;
T_0_19_0: x_18_1 = x_17_0;
T_0_20_0: x_19_0 = 1376151461;
T_0_21_0: x_19_1 = 97;
T_0_22_0: x_20_0 = 1705613057;
T_0_23_0: x_20_1 = 0;
T_0_24_0: x_21_0 = 2093506304;
T_0_25_0: x_21_1 = 0;
T_0_26_0: x_22_0 = -1552523200;
T_0_27_0: x_23_0 = 883189448;
T_0_28_0: x_23_1 = x_22_0;
T_0_29_0: x_24_0 = 646412217;
T_0_30_0: x_24_1 = 0;
T_0_31_0: x_12_0 = -1;
T_0_32_0: x_0_1 = 5;
T_0_33_0: x_1_1 = 72;
T_0_34_0: x_2_1 = 69;
T_0_35_0: x_3_1 = 76;
T_0_36_0: x_4_1 = 76;
T_0_37_0: x_5_1 = 79;
T_0_38_0: x_25_0 = 1854817860;
T_0_39_0: x_25_1 = 83;
T_0_40_0: x_26_0 = 35166865;
T_0_41_0: x_26_1 = 1;
T_0_42_0: x_27_0 = 645172675;
T_0_43_0: x_27_1 = 1;
T_0_44_0: x_28_0 = 938758201;
T_0_45_0: x_28_1 = 1;
T_0_46_0: x_29_0 = 1911566089;
T_0_47_0: x_29_1 = 82;
T_0_48_0: x_30_0 = 639108904;
T_0_49_0: x_30_1 = 90;
T_0_50_0: x_31_0 = 318223030;
T_0_51_0: x_31_1 = 1;
T_0_52_0: x_32_0 = 1763370701;
T_0_53_0: x_32_1 = 1;
T_0_54_0: x_33_0 = 749597655;
T_0_55_0: x_33_1 = 2;
T_0_56_0: x_34_0 = 1535663887;
T_0_57_0: x_34_1 = 2;
T_0_58_0: x_11_1 = 3;
T_2_59_2: x_53_0 = 2066882899;
T_2_60_2: x_53_1 = x_33_1;
T_2_61_2: x_54_0 = 2076883933;
T_2_62_2: x_54_1 = x_34_1;
T_2_63_2: x_55_0 = 0;
T_2_64_2: x_56_0 = 1501860353;
T_1_65_1: x_35_0 = 1364551757;
T_1_66_1: x_35_1 = x_27_1;
T_1_67_1: x_36_0 = 939967476;
T_1_68_1: x_36_1 = x_28_1;
T_1_69_1: x_37_0 = 0;
T_1_70_1: x_38_0 = 1503961601;
T_2_71_2: if (x_0_1 + x_54_1 > x_11_1 && x_0_1 != 0) x_57_0 = -1545455696;
T_2_72_2: if (x_0_1 + x_54_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0) x_58_0 = 11000;
T_2_73_2: if (x_0_1 + x_54_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0) x_59_0 = 2083727616;
T_2_74_2: if (x_0_1 + x_54_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0) x_59_1 = x_0_1;
T_2_75_2: if (x_0_1 + x_54_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && x_0_1 == x_59_1) x_60_0 = 0;
T_1_76_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0) x_39_0 = -1545455696;
T_1_77_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0) x_40_0 = 11000;
T_1_78_1: if (x_0_1 + x_54_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && x_0_1 == x_59_1 && 0 == x_12_0 + 1) x_12_1 = 2;
T_1_79_1: if (x_0_1 + x_54_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && x_0_1 == x_59_1 && 2 == x_12_1) x_60_1 = 0;
T_2_80_2: if (x_0_1 + x_54_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && 2 == x_12_1) x_61_0 = 22821558;
T_2_81_2: if (x_0_1 + x_54_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && 2 == x_12_1) x_61_1 = 0;
T_2_82_2: if (x_0_1 + x_54_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && 0 == x_61_1 && 2 == x_12_1) x_58_1 = x_59_1;
T_2_83_2: if (x_0_1 + x_54_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && 0 == x_61_1 && 2 == x_12_1) x_20_2 = x_20_1 + x_58_1;
T_2_84_2: if (x_0_1 + x_54_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && 0 == x_61_1 && 2 == x_12_1) x_59_2 = -1*x_58_1 + x_59_1;
T_2_85_2: if (x_0_1 + x_54_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && x_59_2 <= 0 && 2 == x_12_1) x_62_0 = 0;
T_2_86_2: if (x_0_1 + x_54_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && x_59_2 <= 0 && 2 == x_12_1) x_12_2 = -1;
T_2_87_2: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0) x_41_0 = 1373050165;
T_2_88_2: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0) x_41_1 = x_0_1;
T_2_89_2: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && x_0_1 == x_41_1) x_42_0 = 0;
T_2_90_2: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && x_0_1 == x_41_1 && 0 == x_12_2 + 1) x_12_3 = 1;
T_1_91_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && x_0_1 == x_41_1 && 1 == x_12_3) x_42_1 = 0;
T_1_92_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && 1 == x_12_3) x_43_0 = 592802761;
T_1_93_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && 1 == x_12_3) x_43_1 = 0;
T_1_94_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && 0 == x_43_1 && 1 == x_12_3) x_40_1 = x_41_1;
T_1_95_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && 0 == x_43_1 && 1 == x_12_3) x_20_3 = x_20_2 + x_40_1;
T_1_96_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && 0 == x_43_1 && 1 == x_12_3) x_41_2 = -1*x_40_1 + x_41_1;
T_1_97_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && x_41_2 <= 0 && 1 == x_12_3) x_44_0 = 0;
T_1_98_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && x_41_2 <= 0 && 1 == x_12_3) x_12_4 = -1;
T_1_99_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && x_41_2 <= 0) x_44_1 = 0;
T_1_100_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0) x_45_0 = 1031766849;
T_1_101_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0) x_45_1 = x_43_1;
T_1_102_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0) x_46_0 = 1694217914;
T_1_103_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0) x_46_1 = x_45_1;
T_1_104_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0) x_0_2 = 0;
T_1_105_1: if (x_36_1 < x_11_1) x_47_0 = 380623755;
T_1_106_1: if (x_36_1 < x_11_1) x_47_1 = 47247431264000;
T_1_107_1: if (x_36_1 < x_11_1) x_48_0 = 52709420;
T_1_108_1: if (x_36_1 < x_11_1) x_48_1 = x_0_2 + x_36_1;
T_1_109_1: if (x_36_1 < x_11_1) x_37_1 = 0;
T_1_110_1: if (x_36_1 < x_11_1 && x_37_1 < x_35_1) x_49_0 = 645049743;
T_1_111_1: if (x_36_1 < x_11_1 && x_37_1 < x_35_1) x_49_1 = 47247431264000;
T_1_112_1: if (x_36_1 < x_11_1) x_37_2 = 1 + x_37_1;
T_1_113_1: if (x_36_1 < x_11_1) x_50_0 = 1179465539;
T_1_114_1: if (x_36_1 < x_11_1) x_50_1 = 47247431264000;
T_1_115_1: if (x_36_1 < x_11_1) x_0_3 = x_0_2 + x_36_1;
T_1_116_1: if (x_36_1 < x_11_1) x_51_0 = 1790980634;
T_1_117_1: if (x_36_1 < x_11_1) x_51_1 = 47247431264000;
T_1_118_1: if (x_0_1 + x_54_1 > x_11_1 && x_0_1 != 0 && x_18_1 != 0 && x_59_2 <= 0) x_62_1 = 0;
T_1_119_1: if (x_0_1 + x_54_1 > x_11_1 && x_0_1 != 0) x_63_0 = 104483393;
T_1_120_1: if (x_0_1 + x_54_1 > x_11_1 && x_0_1 != 0) x_63_1 = x_61_1;
T_1_121_1: if (x_0_1 + x_54_1 > x_11_1 && x_0_1 != 0) x_64_0 = 408133352;
T_1_122_1: if (x_0_1 + x_54_1 > x_11_1 && x_0_1 != 0) x_64_1 = x_63_1;
T_1_123_1: if (x_0_1 + x_54_1 > x_11_1 && x_0_1 != 0) x_0_4 = 0;
T_2_124_2: if (x_36_1 < x_11_1) x_52_0 = 1349110044;
T_2_125_2: if (x_36_1 < x_11_1) x_52_1 = 47247431264000;
T_2_126_2: if (x_36_1 < x_11_1) assert(x_0_4 == x_48_1);
}
|
the_stack_data/99250.c | #include<stdio.h>
int main ()
{
int a = 0, b = 0;
scanf("%d %d", &a, &b);
printf(a < b ? "<" : (a > b ? ">" : "==" ));
return 0;
}
|
the_stack_data/776651.c | #include <stdlib.h>
int main() {
C_STRTOLD(NULL, NULL);
return 0;
}
|
the_stack_data/140765810.c | // PARAM: --set ana.activated[+] "'region'" --set exp.region-offsets true
#include<pthread.h>
#include<stdlib.h>
#include<stdio.h>
struct s {
int datum;
struct s *next;
} *A;
void init (struct s *p, int x) {
p -> datum = x;
p -> next = NULL;
}
void insert(struct s *p, struct s **list) {
p->next = *list;
*list = p;
}
pthread_mutex_t A_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t B_mutex = PTHREAD_MUTEX_INITIALIZER;
void *t_fun(void *arg) {
struct s *p = malloc(sizeof(struct s));
init(p,7);
pthread_mutex_lock(&A_mutex);
insert(p, &A);
pthread_mutex_unlock(&A_mutex);
pthread_mutex_lock(&B_mutex);
p->datum++; // RACE!
pthread_mutex_unlock(&B_mutex);
return NULL;
}
int main () {
pthread_t t1;
struct s *p;
A = malloc(sizeof(struct s));
init(A,3);
pthread_create(&t1, NULL, t_fun, NULL);
p = malloc(sizeof(struct s));
init(p,9);
pthread_mutex_lock(&A_mutex);
insert(p, &A);
pthread_mutex_unlock(&A_mutex);
pthread_mutex_lock(&A_mutex);
p = A;
while (p->next) {
printf("%d\n", p->datum); // RACE!
p = p->next;
}
pthread_mutex_unlock(&A_mutex);
return 0;
}
|
the_stack_data/79716.c | // This file is part of CPAchecker,
// a tool for configurable software verification:
// https://cpachecker.sosy-lab.org
//
// SPDX-FileCopyrightText: 2007-2020 Dirk Beyer <https://www.sosy-lab.org>
//
// SPDX-License-Identifier: Apache-2.0
int main(void) {
int cards[] = {[10 ... 15] = 1, 2, [1 ... 5] = 3, 4};
if (sizeof(cards) != 17*sizeof(int)) {
ERROR: return 1;
}
return 0;
}
|
the_stack_data/6157.c | /*
* C character handling library.
* toupper()
* ANSI 4.3.2.2.
* Convert character to upper case.
*/
#include <ctype.h>
int toupper(c) int c;
{
return (islower(c) ? _toupper(c) : c);
}
|
the_stack_data/3262447.c | #include <stdio.h>
int main()
{
int n,i,j;
printf("Enter n value : ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=0;j<i;j++)
{
printf("%d ", i);
}
printf("\n");
}
return 0;
}
|
the_stack_data/243892564.c | #include <stdio.h>
#include <stdlib.h>
#include <locale.h>
int main(){
setlocale(LC_ALL,"Portuguese");
int Base;
int Lado1;
int Lado2;
while(Base <= 0 || Lado1 <=0|| Lado2 <= 0){
printf("Digite o valor base do triangulo: \n");
scanf("%d", &Base);
printf("Digite o valor Lado1 do triangulo: \n");
scanf("%d", &Lado1);
printf("Digite o valor Lado2 do triangulo: \n");
scanf("%d", &Lado2);
if(Base <= 0 || Lado1 <=0|| Lado2 <= 0){
printf("Isso nao e um triangulo, tente novamente\n");
}
}
if (Base == Lado1 && Lado1 == Lado2 && Lado2 == Base ){
printf("Triangulo equilatero\n");
}
if (Base != Lado1 && Lado1 != Lado2 && Base != Lado2 ){
printf("Triangulo Escaleno\n");
}
if(Base != Lado1 && Lado1 == Lado2 && Lado2 != Base ){
printf("triangulo isosceles\n");
}
else if(Base == Lado1 && Lado1 != Lado2 && Base != Lado2){
printf("triangulo isosceles\n");
}
else if(Base != Lado1 && Lado1 != Lado2 && Base == Lado2){
printf("triangulo isosceles\n");
}
system("pause");
return 0;
}
|
the_stack_data/9141.c | /******************************************************************************
*
* Program: chapter_3_1.c
* Function Title: Main
* Summary: list biggest and smallest integer out of a list of five
*
* Inputs: None
* Outputs: None
*
* Compile Instructions: gcc chapter_3_1.c -o chapter_3_1.exe
* Pseudocode:
* Begin
* Define variables
* Ask for 5 digits
* Scan in 5 digits
* print "Largest integer: "
* If a>b,c,d,e
* Then
* print a
* Else
* If b>a,c,d,e
* Then
* print b
* Else
* If c>a,b,d,e
* Then
* print c
* Else
* If d>a,b,c,e
* Then
* print d
* Else
print e
EndIf
EndIf
EndIf
EndIf
print "Smallest integer: "
If a<b,c,d,e
Then
print a
Else
If b<a,c,d,e
Then
print b
Else
If c<a,b,d,e
Then
print c
Else
If d<a,b,c,e
Then
print d
Else
print e
EndIf
EndIf
EndIf
EndIf
* End
******************************************************************************/
#include <stdio.h>
int main() { //Begin
int a, b, c, d, e; //Define variables
printf("Enter five integers in any order: "); //Ask for 5 digits
scanf("%d %d %d %d %d", &a, &b, &c, &d, &e); //Scan in 5 digits
printf("Largest integer: "); //print "Largest integer: "
if (a > b && a > c && a > d && a > e) //If a>b,c,d,e
{ //Then
printf("%d", a); //print a
}
else //Else
if (b > a && b > c && b > d && b > e) //If b>a,c,d,e
{ //Then
printf("%d", b); //print b
}
else //Else
if (c > a && c > b && c > d && c > e) //If c>a,b,d,e
{ //Then
printf("%d", c); //print c
}
else //Else
if (d > a && d > b && d > c && d > e) //If d>a,b,c,e
{ //Then
printf("%d", d); //print d
}
else //Else
{
printf("%d", e); //print e
} //EndIf
//EndIf
//EndIf
//EndIf
printf("\nSmallest integer: "); //print "Smallest integer: "
if (a < b && a < c && a < d && a < e) //If a<b,c,d,e
{ //Then
printf("%d", a); //print a
}
else //Else
if (b < a && b < c && b < d && b < e) //If b<a,c,d,e
{ //Then
printf("%d", b); //print b
}
else //Else
if (c < a && c < b && c < d && c < e) //If c<a,b,d,e
{ //Then
printf("%d", c); //print c
}
else //Else
if (d < a && d < b && d < c && d < e) //If d<a,b,c,e
{ //Then
printf("%d", d); //print d
}
else //Else
{
printf("%d", e); //print e
//EndIf
//EndIf
} //EndIf
//EndIf
return 0;
} //End
|
the_stack_data/51046.c | /*
Author : Arnob Mahmud
mail : [email protected]
*/
#include <stdio.h>
int main(int argc, char const *argv[])
{
char ch;
printf("Enter an alphabet :\n");
ch = getchar();
if (islower(ch))
{
putchar(toupper(ch));
}
else
{
putchar(tolower(ch));
}
return 0;
}
|
the_stack_data/76700.c | #include <stdio.h>
/* fixitxt version 1.0.0
*
* Copyright 2013 Glenn Randers-Pehrson
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
* and license in png.h
*
* Usage:
*
* fixitxt.exe < bad.png > good.png
*
* Fixes a PNG file written with libpng-1.6.0 or 1.6.1 that has one or more
* uncompressed iTXt chunks. Assumes that the actual length is greater
* than or equal to the value in the length byte, and that the CRC is
* correct for the actual length. This program hunts for the CRC and
* adjusts the length byte accordingly. It is not an error to process a
* PNG file that has no iTXt chunks or one that has valid iTXt chunks;
* such files will simply be copied.
*
* Requires zlib (for crc32 and Z_NULL); build with
*
* gcc -O -o fixitxt fixitxt.c -lz
*/
#define MAX_LENGTH 500000
#define GETBREAK c=getchar(); if (c == EOF) break;
#include <zlib.h>
main()
{
unsigned int i;
unsigned char buf[MAX_LENGTH];
unsigned long crc;
unsigned int c;
/* Skip 8-byte signature */
for (i=8; i; i--)
{
c=GETBREAK;
putchar(c);
}
if (c != EOF)
for (;;)
{
/* Read the length */
unsigned long length;
c=GETBREAK; buf[0] = c;
c=GETBREAK; buf[1] = c;
c=GETBREAK; buf[2] = c;
c=GETBREAK; buf[3] = c;
length=((((unsigned long) buf[0]<<8 + buf[1]<<16) + buf[2] << 8) + buf[3]);
/* Read the chunkname */
c=GETBREAK; buf[4] = c;
c=GETBREAK; buf[5] = c;
c=GETBREAK; buf[6] = c;
c=GETBREAK; buf[7] = c;
/* The iTXt chunk type expressed as integers is (105, 84, 88, 116) */
if (buf[4] == 105 && buf[5] == 84 && buf[6] == 88 && buf[7] == 116)
{
if (length >= MAX_LENGTH-12)
break; /* To do: handle this more gracefully */
/* Initialize the CRC */
crc = crc32(0, Z_NULL, 0);
/* Copy the data bytes */
for (i=8; i < length + 12; i++)
{
c=GETBREAK; buf[i] = c;
}
/* Calculate the CRC */
crc = crc32(crc, buf+4, (uInt)length+4);
for (;;)
{
/* Check the CRC */
if (((crc >> 24) & 0xff) == buf[length+8] &&
((crc >> 16) & 0xff) == buf[length+9] &&
((crc >> 8) & 0xff) == buf[length+10] &&
((crc ) & 0xff) == buf[length+11])
break;
length++;
if (length >= MAX_LENGTH-12)
break;
c=GETBREAK;
buf[length+11]=c;
/* Update the CRC */
crc = crc32(crc, buf+7+length, 1);
}
/* Update length bytes */
buf[0] = (length << 24) & 0xff;
buf[1] = (length << 16) & 0xff;
buf[2] = (length << 8) & 0xff;
buf[3] = (length ) & 0xff;
/* Write the fixed iTXt chunk (length, name, data, crc) */
for (i=0; i<length+12; i++)
putchar(buf[i]);
}
else
{
/* Copy bytes that were already read (length and chunk name) */
for (i=0; i<8; i++)
putchar(buf[i]);
/* Copy data bytes and CRC */
for (i=8; i< length+12; i++)
{
c=GETBREAK;
putchar(c);
}
if (c == EOF)
{
break;
}
/* The IEND chunk type expressed as integers is (73, 69, 78, 68) */
if (buf[4] == 73 && buf[5] == 69 && buf[6] == 78 && buf[7] == 68)
break;
}
if (c == EOF)
break;
if (buf[4] == 73 && buf[5] == 69 && buf[6] == 78 && buf[7] == 68)
break;
}
}
|
the_stack_data/40762944.c | #if defined(DEVICE_MODEL_ENABLED)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if !defined(DEPRECATED_LINKKIT)
#include "iot_import.h"
#include "iot_export.h"
#include "cut.h"
#include "single_config_new.h"
DATA(test_linkkit_single_api_yield)
{
user_example_ctx_t *user_example_ctx;
iotx_linkkit_dev_meta_info_t master_meta_info;
};
SETUP(test_linkkit_single_api_yield)
{
data->user_example_ctx = user_example_get_ctx();
memset(data->user_example_ctx, 0, sizeof(user_example_ctx_t));
cJSON_Hooks cjson_hooks = {(void *)test_malloc, (void *)test_free};
cJSON_InitHooks(&cjson_hooks);
IOT_SetLogLevel(IOT_LOG_DEBUG);
/* Register Callback */
IOT_RegisterCallback(ITE_CONNECT_SUCC, user_connected_event_handler);
IOT_RegisterCallback(ITE_DISCONNECTED, user_disconnected_event_handler);
IOT_RegisterCallback(ITE_RAWDATA_ARRIVED, user_down_raw_data_arrived_event_handler);
IOT_RegisterCallback(ITE_SERVICE_REQUEST, user_service_request_event_handler);
IOT_RegisterCallback(ITE_PROPERTY_SET, user_property_set_event_handler);
IOT_RegisterCallback(ITE_PROPERTY_GET, user_property_get_event_handler);
IOT_RegisterCallback(ITE_REPORT_REPLY, user_report_reply_event_handler);
IOT_RegisterCallback(ITE_INITIALIZE_COMPLETED, user_initialized);
TEST_REPLACE_DEVCERT(&TEST_PRODUCT_KEY, &TEST_PRODUCT_SECRET, &TEST_DEVICE_NAME, &TEST_DEVICE_SECRET);
memset(&data->master_meta_info, 0, sizeof(iotx_linkkit_dev_meta_info_t));
memcpy(data->master_meta_info.product_key, TEST_PRODUCT_KEY, strlen(TEST_PRODUCT_KEY));
memcpy(data->master_meta_info.product_secret, TEST_PRODUCT_SECRET, strlen(TEST_PRODUCT_SECRET));
memcpy(data->master_meta_info.device_name, TEST_DEVICE_NAME, strlen(TEST_DEVICE_NAME));
memcpy(data->master_meta_info.device_secret, TEST_DEVICE_SECRET, strlen(TEST_DEVICE_SECRET));
data->user_example_ctx->master_devid = IOT_Linkkit_Open(IOTX_LINKKIT_DEV_TYPE_MASTER, &data->master_meta_info);
IOT_Linkkit_Connect(data->user_example_ctx->master_devid);
wait_for_connected();
}
TEARDOWN(test_linkkit_single_api_yield)
{
IOT_Linkkit_Close(data->user_example_ctx->master_devid);
}
// 正常调用
CASE2(test_linkkit_single_api_yield, case_01)
{
int count = 10;
while (count--) {
IOT_Linkkit_Yield(100);
}
}
// timeout = 0;
CASE2(test_linkkit_single_api_yield, case_02)
{
IOT_Linkkit_Yield(0);
}
// timeout = -1;
CASE2(test_linkkit_single_api_yield, case_03)
{
IOT_Linkkit_Yield(-1);
}
// 启动前yield
CASE(test_linkkit_single_api_yield, case_04)
{
IOT_Linkkit_Yield(100);
}
SUITE(test_linkkit_single_api_yield) = {
ADD_CASE(test_linkkit_single_api_yield, case_01),
ADD_CASE(test_linkkit_single_api_yield, case_02),
ADD_CASE(test_linkkit_single_api_yield, case_03),
ADD_CASE(test_linkkit_single_api_yield, case_04),
ADD_CASE_NULL
};
#endif /* !defined(DEPRECATED_LINKKIT) */
#endif /* #if defined(DEVICE_MODEL_ENABLED) */
|
the_stack_data/77488.c | #include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <pwd.h>
static void errorexit()
{
perror("sussh");
exit(1);
}
int main(int argc, char** argv)
{
const char* user;
const char* host;
const char* command;
struct passwd* entry;
if (argc < 4){
fprintf(stderr, "usage: sussh user host command\n");
exit(1);
}
user = argv[1];
host = argv[2];
command = argv[3];
if (!(entry = getpwnam(user))){
errorexit();
}
setenv("HOME", entry->pw_dir, 1);
if (setuid(entry->pw_uid) != 0 || seteuid(entry->pw_uid) != 0){
errorexit();
}
execl("/usr/bin/ssh", "ssh", host, command, NULL);
errorexit();
return -1;
}
|
the_stack_data/220456467.c | /*************************************************************************
Admin page for wEMBOSS docker
Author Rafael Hernandez <https://github.com/fikipollo>
*************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <pwd.h>
#include <sys/types.h>
#include <errno.h>
#define NOBODY "wemboss"
char *user;
int userid;
void print_error( char *error_context, char *error_message) {
int cl;
printf("Content-type: text/html\n\n");
printf("error, %s <P>", error_context);
printf("%s", error_message);
exit(1);
}
main(int argc, char *argv[]) {
if (getuid() != getpwnam(NOBODY)->pw_uid) {
print_error("catch:", "Sorry, the owner of this process is not allowed to run admin program, ask server manager! ");
}
/* Identifying the user, he becomes the owner of the process */
fflush(NULL);
execv ("./admin.pl", argv, NULL);
print_error("catch: can't execute admin.pl", "admin.pl");
} /* main */
|
the_stack_data/96246.c |
// C program for insertion sort
#include <math.h>
#include <stdio.h>
/* Function to sort an array using insertion sort*/
void insertionSort(int arr[], int n)
{
int i, key, j;
for (i = 1; i < n; i++) {
key = arr[i];
j = i - 1;
/* Move elements of arr[0..i-1], that are
greater than key, to one position ahead
of their current position */
while (j >= 0 && arr[j] > key) {
arr[j + 1] = arr[j];
j = j - 1;
}
arr[j + 1] = key;
}
}
// A utility function to print an array of size n
void printArray(int arr[], int n)
{
int i;
for (i = 0; i < n; i++)
printf("%d ", arr[i]);
printf("\n");
}
/* Driver program to test insertion sort */
int main()
{
int arr[] = { 12, 11, 13, 5, 6 };
int n = sizeof(arr) / sizeof(arr[0]);
insertionSort(arr, n);
printArray(arr, n);
return 0;
}
|
the_stack_data/59511865.c | // The following code used to crash VeriFast,
// i.e. this is a document-your-commit and anti-regression test.
struct container{
int *y;
};
struct container *a_global_var;
/*@
predicate test_global_not_precise() =
a_global_var |-> _
;
predicate test_global_precise(;) =
a_global_var |-> _
;
@*/ |
the_stack_data/206394000.c | #include <stdio.h>
int main()
{
char *veeps[5] = { "Adams", "Jefferson", "Burr", "Clinton", "Gerry" };
int x;
for(x=0;x<5;x++)
printf("%c\n",*(*(veeps+x)+1));
return(0);
}
|
the_stack_data/167331351.c | // bool
#include <stdbool.h>
int main(void) {
expecti(__bool_true_false_are_defined, 1);
_Bool a = 0;
_Bool b = 1;
_Bool c = 2;
_Bool d = 3;
expecti(a, 0);
expecti(b, 1);
expecti(c, 1);
expecti(d, 1);
a = 3;
b = 2;
c = 1;
d = 0;
expecti(a, 1);
expecti(b, 1);
expecti(c, 1);
expecti(d, 0);
bool a1 = false;
a1 = !a1;
a1 = (a1) ? true : false;
expecti(a1, true);
}
|
the_stack_data/88082.c | #include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <stdlib.h>
#include <semaphore.h>
/*
*/
int queue[200];
int box = 0; // 생산, 소비할 매개체
int r_size = 5000; //명령어의 기본크기는 5000
int q_size = 100; //큐의 기본크기는 100
int request = 0;
int produce = 0;
int consume = 0;
int produce_num[10]; //생산자쓰레드의 번호를 저장할 배열
int consume_num[10]; //소비자쓰레드의 번호를 저장할 배열
//세마포어변수들
sem_t full;
sem_t empty;
sem_t mutex;
int set(int what, int id){
int i = 0;
if(what == 1){ // 생산자 쓰레드
box++;
sem_wait(&empty);
sem_wait(&mutex);
if(request>=r_size){
sem_post(&mutex);
sem_post(&full);
return -1;
}
queue[produce%q_size] = 1;
produce++;
request++;
produce_num[id] += 1;
printf("%6d ", request);
for(i = 0; i<q_size; i++)
printf("%d",queue[i]);
printf("\n");
sem_post(&mutex);
sem_post(&full);
return 0;
}
else{
sem_wait(&full);
sem_wait(&mutex);
if(request>= r_size){
sem_post(&mutex);
sem_post(&empty);
return -1;
}
queue[consume%q_size] = 0;
consume++;
request++;
consume_num[id] += 1;
printf("%6d ", request);
for(i = 0; i<q_size; i++)
printf("%d",queue[i]);
printf("\n");
sem_post(&mutex);
sem_post(&empty);
box--;
return 0;
}
}
void *produce_thread(void *tid){
int id = *((int *)tid);
int i;
while(1){
if(set(1,id)==-1)
pthread_exit(NULL);
}
}
void *consume_thread(void *tid){
int id = *((int *)tid);
int i;
while(1){
if(set(0,id)==-1)
pthread_exit(NULL);
}
}
int main(int argc, char* argv[]){
int i;
int state;
char* q_str = "-q";
char* r_str = "-r";
char* p_str = "-p"; int p_size = 3;
char* c_str = "-c"; int c_size = 3;
int status = 0;
int p_num[10];
int c_num[10];
pthread_t thread_p[10];
pthread_t thread_c[10];
//init setting
for(i = 0; i<argc; i++){
if(strcmp(argv[i],q_str)==0)
q_size = atoi(argv[i+1]);
if(strcmp(argv[i],r_str)==0)
r_size = atoi(argv[i+1]);
if(strcmp(argv[i],p_str)==0)
p_size = atoi(argv[i+1]);
if(strcmp(argv[i],c_str)==0)
c_size = atoi(argv[i+1]);
}
if(q_size<1 || q_size>200){
printf("q_size is not correct\n");
return -1;
}
if(r_size<1 || r_size>50000){
printf("r_size is not correct\n");
return -1;
}
if(p_size<1 || p_size>10){
printf("p_size is not correct\n");
return -1;
}
if(c_size<1 || c_size>10){
printf("c_size is not correct\n");
return -1;
}
for(i = 0; i<p_size; i++)
p_num[i] = i;
for(i = 0; i<c_size; i++)
c_num[i] = i;
if(sem_init(&full,0,0)!=0){
printf("sem_init Error\n");
return 0;
}
if(sem_init(&empty,0,q_size)!=0){
printf("sem_init Error\n");
return 0;
}
if(sem_init(&mutex,0,1)!=0){
printf("sem_init Error\n");
return 0;
}
for(i = 0; i<p_size; i++){
status = pthread_create(&thread_p[i], NULL, produce_thread,(void*) (p_num+i));
if(status != 0)
printf("produce : pthread_creat returned error code : %d\n",status);
}
for(i = 0; i<c_size; i++){
status = pthread_create(&thread_c[i], NULL, consume_thread, (void*) (c_num+i));
if(status != 0)
printf("consume : pthread_creat returned error code : %d\n",status);
}
for(i = 0; i<p_size; i++){
pthread_join(thread_p[i], (void**)&status);
}
for(i = 0; i<c_size; i++){
pthread_join(thread_c[i], (void**)&status);
}
for(i = 0; i<p_size; i++){
printf("producer %d:%d\n",i,produce_num[i]);
}
printf("\n");
for(i = 0; i<c_size; i++){
printf("consumer %d:%d\n",i,consume_num[i]);
}
sem_destroy(&full);
sem_destroy(&empty);
sem_destroy(&mutex);
return 0;
}
|
the_stack_data/287998.c | #include <stdio.h>
int main(){
//Escreva um algoritmo para ler uma temperatura em graus Fahrenheit, calcular e escrever o valor
//correspondente em graus Celsius.
double celsius;
double fahrenheit;
printf("Escreva a temperatura em graus fahrenheit :");
scanf("%lf",&fahrenheit);
celsius=(fahrenheit-32)/1.8;
printf("A temperatura em graus celsius e:%.2lf",celsius);
} |
the_stack_data/648038.c | /* Name: p4-03.c
Purpose: Displays a three-digit number reveresed.
Author: NiceMan1337
Date: 14.03.2022 */
#include <stdio.h>
int main(void)
{
/*declare variable*/
int i, j, x;
/*ask user for input*/
printf("Enter three-digit number: ");
scanf("%1d%1d%1d", &i, &j, &x);
/*print out the result*/
printf("The reversal is: %d%d%d\n", x, j, i);
return 0;
} |
the_stack_data/147733.c | /*numPass=5, numTotal=5
Verdict:ACCEPTED, Visibility:1, Input:"2", ExpOutput:"2 -3 2 ", Output:"2 -3 2 "
Verdict:ACCEPTED, Visibility:1, Input:"20", ExpOutput:"20 15 10 5 0 5 10 15 20 ", Output:"20 15 10 5 0 5 10 15 20 "
Verdict:ACCEPTED, Visibility:1, Input:"4", ExpOutput:"4 -1 4 ", Output:"4 -1 4 "
Verdict:ACCEPTED, Visibility:0, Input:"16", ExpOutput:"16 11 6 1 -4 1 6 11 16 ", Output:"16 11 6 1 -4 1 6 11 16 "
Verdict:ACCEPTED, Visibility:0, Input:"8", ExpOutput:"8 3 -2 3 8 ", Output:"8 3 -2 3 8 "
*/
#include <stdio.h>
int i,j;
int fun_two(j){
printf("%d ",j);
if(j<=0)
return fun_one(j);
else
return fun_two(j-5);
}
int fun_one(i){
printf("%d ",i+5);
if((i+5)!=j)
return fun_one(i+5);
}
int main(){
scanf("%d",&j);
fun_two(j);
return 0;
} |
the_stack_data/307561.c | /*****************************************************************************
* mpegdemux *
*****************************************************************************/
/*****************************************************************************
* File name: mpeg_remux.c *
* Created: 2003-02-02 by Hampa Hug <[email protected]> *
* Last modified: 2003-09-10 by Hampa Hug <[email protected]> *
* Copyright: (C) 2003 by Hampa Hug <[email protected]> *
*****************************************************************************/
/*****************************************************************************
* This program is free software. You can redistribute it and / or modify it *
* under the terms of the GNU General Public License version 2 as published *
* by the Free Software Foundation. *
* *
* 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. *
*****************************************************************************/
/* $Id: mpeg_remux.c 67 2004-01-02 18:20:15Z hampa $ */
// The code has been modified to use file descriptors instead of FILE streams.
// Only functionality needed in MediaTomb remains, all extra features are
// stripped out.
#ifdef HAVE_CONFIG_H
#include "autoconfig.h"
#endif
#ifdef HAVE_LIBDVDNAV
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "buffer.h"
#include "mpeg_parse.h"
#include "mpeg_remux.h"
#include "mpegdemux_internal.h"
static mpeg_buffer_t shdr = { NULL, 0, 0 };
static mpeg_buffer_t pack = { NULL, 0, 0 };
static mpeg_buffer_t packet = { NULL, 0, 0 };
static
int mpeg_remux_system_header (mpeg_demux_t *mpeg)
{
if (mpeg_buf_write_clear (&pack, mpeg->ext)) {
return (1);
}
if (mpeg_buf_read (&shdr, mpeg, mpeg->shdr.size)) {
return (1);
}
if (mpeg_buf_write_clear (&shdr, mpeg->ext)) {
return (1);
}
return (0);
}
static
int mpeg_remux_packet (mpeg_demux_t *mpeg)
{
int r;
unsigned sid, ssid;
sid = mpeg->packet.sid;
ssid = mpeg->packet.ssid;
if (mpeg_stream_excl (sid, ssid)) {
return (0);
}
r = 0;
if (mpeg_buf_read (&packet, mpeg, mpeg->packet.size)) {
fprintf(stderr, "remux: incomplete packet (sid=%02x size=%u/%u)\n",
sid, packet.cnt, mpeg->packet.size
);
if (par_drop) {
mpeg_buf_clear (&packet);
return (1);
}
r = 1;
}
if (mpeg_buf_write_clear (&pack, mpeg->ext)) {
return (1);
}
if (mpeg_buf_write_clear (&packet, mpeg->ext)) {
return (1);
}
return (r);
}
static
int mpeg_remux_pack (mpeg_demux_t *mpeg)
{
if (mpeg_buf_read (&pack, mpeg, mpeg->pack.size)) {
return (1);
}
if (par_empty_pack) {
if (mpeg_buf_write_clear (&pack, mpeg->ext)) {
return (1);
}
}
return (0);
}
static
int mpeg_remux_end (mpeg_demux_t *mpeg)
{
if (mpeg_copy (mpeg, mpeg->ext, 4)) {
return (1);
}
return (0);
}
int mpeg_remux (int inp, int out)
{
int r;
mpeg_demux_t *mpeg;
mpeg = mpegd_open_fd (NULL, inp, 0);
if (mpeg == NULL) {
return (1);
}
mpeg->ext = out;
mpeg->mpeg_system_header = &mpeg_remux_system_header;
mpeg->mpeg_pack = &mpeg_remux_pack;
mpeg->mpeg_packet = &mpeg_remux_packet;
mpeg->mpeg_packet_check = &mpeg_packet_check;
mpeg->mpeg_end = &mpeg_remux_end;
mpeg_buf_init (&shdr);
mpeg_buf_init (&pack);
mpeg_buf_init (&packet);
r = mpegd_parse (mpeg);
mpegd_close (mpeg);
mpeg_buf_free (&shdr);
mpeg_buf_free (&pack);
mpeg_buf_free (&packet);
return (r);
}
#endif//HAVE_LIBDVDNAV
|
the_stack_data/111079245.c | /*BEGIN_LEGAL
Intel Open Source License
Copyright (c) 2002-2012 Intel Corporation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer. Redistributions
in binary form must reproduce the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution. Neither the name of
the Intel Corporation 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 INTEL OR
ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
END_LEGAL */
#include <stdio.h>
#ifdef TARGET_WINDOWS
// declare all functions as exported so pin can find them,
// must be all functions since only way to find end of one function is the begining of the next
// Another way is to compile application with debug info (Zi) - pdb file, but that causes probelms
// in the running of the script
#define EXPORT_SYM __declspec( dllexport )
#else
#define EXPORT_SYM
#endif
#include <stdio.h>
EXPORT_SYM
int one()
{
return 1;
}
EXPORT_SYM
main()
{
int o = one();
printf("Result %d\n", o);
return 0;
}
|
the_stack_data/20450736.c | // REQUIRES: system-linux
// RUN: clang -o %t %s -O2 -mno-sse
// RUN: llvm-mctoll -d -I /usr/include/stdio.h %t
// RUN: clang -o %t1 %t-dis.ll
// RUN: %t1 2>&1 | FileCheck %s
// CHECK: num: 0
// CHECK: num: 1
// CHECK: num: 2
// CHECK: num: 3
// CHECK: num: 1
// CHECK: num: 2
// CHECK: num: 3
// CHECK: num: 4
// CHECK: num: 2
// CHECK: num: 3
// CHECK: num: 4
// CHECK: num: 5
// CHECK: num: 3
// CHECK: num: 4
// CHECK: num: 5
// CHECK: num: 6
#include <stdio.h>
typedef unsigned int ee_u32;
int __attribute__((noinline)) matrix_init(ee_u32 N) {
for (ee_u32 i = 0; i < N; i++) {
for (ee_u32 j = 0; j < 4; j++) {
printf("num: %d\n", i + j);
}
}
return 0;
}
int main() {
ee_u32 N = 4;
matrix_init(N);
return 0;
}
|
the_stack_data/728987.c | /*
* Date: 2014-06-08
* Author: [email protected]
*
*
* This is Example 3.4 from the test suit used in
*
* Termination Proofs for Linear Simple Loops.
* Hong Yi Chen, Shaked Flur, and Supratik Mukhopadhyay.
* SAS 2012.
*
* The test suite is available at the following URL.
* https://tigerbytes2.lsu.edu/users/hchen11/lsl/LSL_benchmark.txt
*
* Comment: terminating, non-linear
*/
typedef enum {false, true} bool;
extern int __VERIFIER_nondet_int(void);
int main() {
int x, y, z;
x = __VERIFIER_nondet_int();
y = __VERIFIER_nondet_int();
z = __VERIFIER_nondet_int();
while (x + y >= 0 && x <= z) {
x = 2*x + y;
y = y + 1;
}
return 0;
}
|
the_stack_data/1016059.c | /* nftw_dir_tree.c
Demonstrate the use of nftw(3). Walk though the directory tree specified
on the command line (or the current working directory if no directory
is specified on the command line), displaying an indented hierarchy
of files in the tree. For each file, display:
* a letter indicating the file type (using the same letters as "ls -l")
* a string indicating the file type, as supplied by nftw()
* the file's i-node number.
*/
#define _XOPEN_SOURCE 600 /* Get nftw() */
#include <ftw.h>
#include <sys/types.h> /* Type definitions used by many programs */
#include <stdio.h> /* Standard I/O functions */
#include <stdlib.h> /* Prototypes of commonly used library functions,
plus EXIT_SUCCESS and EXIT_FAILURE constants */
#include <unistd.h> /* Prototypes for many system calls */
#include <errno.h> /* Declares errno and defines error constants */
#include <string.h> /* Commonly used string-handling functions */
static int /* Callback function called by ftw() */
dirTree(const char *pathname, const struct stat *sbuf, int type, struct FTW *ftwb)
{
printf("Printing %s\n", pathname);
if (type == FTW_NS) { /* Could not stat() file */
printf("?");
} else {
switch (sbuf->st_mode & S_IFMT) { /* Print file type */
case S_IFREG: printf("-"); break;
case S_IFDIR: printf("d"); break;
case S_IFCHR: printf("c"); break;
case S_IFBLK: printf("b"); break;
case S_IFLNK: printf("l"); break;
case S_IFIFO: printf("p"); break;
case S_IFSOCK: printf("s"); break;
default: printf("?"); break; /* Should never happen (on Linux) */
}
}
if (type != FTW_NS)
printf("%7ld ", (long) sbuf->st_ino);
else
printf(" ");
printf(" %*s", 4 * ftwb->level, " "); /* Indent suitably */
printf("%s\n", &pathname[ftwb->base]); /* Print basename */
return 0; /* Tell nftw() to continue */
}
int
main(int argc, char *argv[])
{
int flags = 0;
if (argc != 2) {
printf("%d arguments were given!\n", argc);
for (int i = 0; i < argc; ++i) {
printf("arg[%d] = %s\n", i, argv[i]);
}
fprintf(stderr, "Usage: %s directory-path\n", argv[0]);
exit(EXIT_FAILURE);
}
if (nftw(argv[1], dirTree, 10, flags) == -1) {
perror("nftw");
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
}
|
the_stack_data/153268940.c | #include <ctype.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#ifndef DATE
#define DATE "No date"
#endif
#ifndef HASH
#define HASH "Development version; do not use"
#endif
const char* help = "Strip \\marginpar commands from LaTeX files.\n"
"\n"
"Use:\n"
"\n"
" marginstrip [OPTION]... FILE...\n"
"\n"
"Read from standard input if no FILE is given.\n"
"\n"
"Options:\n"
" -h, --help Print this help and exit\n"
" -v, --version Print version info and exit\n";
void get_control_word(FILE* fh, char* buf, int bufsize)
{
/*
* Get LaTeX control word or symbol from file handle.
* A control word is
* \\[A-Za-z]+
* and a control symbol is
* \\[^A-Za-z]
* The function assumes we've already seen the \\.
*
* Since we only need to know if the control word we have is \marginpar
* or \marginparhere, we only read enough chars from the file to check
* that.
*/
int c = getc(fh);
*buf = c;
int i = 0;
if (isalpha(c)) {
while (isalpha((c = getc(fh)))) {
if (i == bufsize - 2) {
break;
}
*(buf + ++i) = c;
}
ungetc(c, fh);
}
*(buf + ++i) = '\0';
}
bool is_skipped(char* word, int limit)
{
if (strncmp("marginpar", word, limit) == 0) {
return true;
} else if (strncmp("marginparhere", word, limit) == 0) {
return true;
} else {
return false;
}
}
void skip_until_newline(FILE* fh)
{
int c;
while (true) {
c = getc(fh);
if (c == EOF || c == '\n') {
break;
}
}
}
/* Skip until opening { */
void skip_until_open_brace(FILE* fh)
{
int c;
int braces = 0;
while (!braces) {
c = getc(fh);
switch (c) {
case '\\':
getc(fh);
break;
case '{':
braces++;
break;
case EOF:
braces--;
break;
default:
/* Drop c by default */
break;
}
}
}
/* Skip until closing }, assuming we're at an opening { */
void skip_until_close_brace(FILE* fh)
{
int c;
int braces = 1;
while (braces) {
c = getc(fh);
switch (c) {
case '\\':
getc(fh);
break;
case '%':
skip_until_newline(fh);
break;
case '{':
braces++;
break;
case '}':
braces--;
break;
case EOF:
printf("\n");
braces = 0;
break;
default:
/* Drop c by default */
break;
}
}
}
/*
* Skip over the arguments to \marginpar or \marginparhere.
*/
void skip_argument(FILE* fh)
{
skip_until_open_brace(fh);
skip_until_close_brace(fh);
/* Check for comments or \n */
int c = getc(fh);
switch (c) {
case '%':
skip_until_newline(fh);
break;
case '\n':
break;
default:
ungetc(c, fh);
break;
}
}
void print_until_newline(FILE* fh)
{
int c;
while ((c = getc(fh)) != EOF) {
printf("%c", c);
if (c == '\n') {
break;
}
}
}
/*
* TeX control word buffer. The buffer only needs to be able to hold
* 'marginpar' or 'marginparhere', so it is rather small.
*/
#define BUFSIZE 24
void marginstrip(FILE* fh)
{
int c;
char* buf = malloc(BUFSIZE * sizeof(char));
while ((c = getc(fh)) != EOF) {
switch (c) {
case '\\':
get_control_word(fh, buf, BUFSIZE);
if (is_skipped(buf, BUFSIZE)) {
skip_argument(fh);
} else {
printf("\\%s", buf);
}
break;
case '%':
printf("%c", c);
print_until_newline(fh);
break;
default:
printf("%c", c);
break;
}
}
}
int main(int argc, char** argv)
{
int c;
while (true) {
static struct option long_options[] = {
{ "help", no_argument, 0, 'h' },
{ "version", no_argument, 0, 'v' },
{ 0, 0, 0, 0 }
};
/* getopt_long option index */
int option_index = 0;
c = getopt_long(argc, argv, "hv", long_options, &option_index);
/* Detect the end of the options */
if (c == -1) {
break;
}
switch (c) {
case 'h':
printf("%s", help);
exit(EXIT_SUCCESS);
break;
case 'v':
printf("Version %s\nBuilt from Git commit %s\n", DATE, HASH);
exit(EXIT_SUCCESS);
break;
default:
abort();
}
}
if (optind < argc) {
while (optind < argc) {
FILE* fh = fopen(argv[optind], "r");
if (!fh) {
/* TODO: Check errno for better error messages */
fprintf(stderr, "Error: Couldn't open '%s' for reading\n", argv[optind]);
exit(EXIT_FAILURE);
}
marginstrip(fh);
fclose(fh);
optind++;
}
} else {
marginstrip(stdin);
}
exit(EXIT_SUCCESS);
}
|
the_stack_data/175143049.c | #define BITSPERWORD 32
#define SHIFT 5
#define MASK 0x1F
#define N 10000000
int a[1 + N/BITSPERWORD];
void set(int i){
a[i>>SHIFT] |= (1<<(i & MASK));
}
void clr(int i){
a[i>>SHIFT] &= ~(1<<(i & MASK));
}
void test(int i){
return a[i>>SHIFT] & (1<<(i & MASK));
} |
the_stack_data/264205.c | #include <semaphore.h>
int main()
{
sem_t semaphore;
sem_init(&semaphore, 0, 0);
sem_wait(&semaphore);
}
|
the_stack_data/182954027.c | #include <stdio.h>
#include <stdlib.h>
void Diversion(int*hours,int*mins ,int*secs);
int main()
{
int min=0,hours=0,seconds=0;
printf("Please enter number of mins \n");
scanf("%d",&min);
Diversion(&hours,&min,&seconds);
printf("Hours=%d, Minuits=%d, Seconds=%d",hours,min,seconds);
return 0;
}
void Diversion(int*hours, int*mins, int*secs)
{
*hours=*mins/60;
*mins=*mins%60;
int x=*mins%60;
*secs=x/60;
}
|
the_stack_data/25593.c | /*
Given sorted list of words find the precedence of characters in alien language.
*/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#define min(a,b) ((a<b)?a:b)
#define MAX 100
struct listnode {
int dest;
struct listnode *next;
};
struct Adjlist {
struct listnode *head;
};
struct graph {
int V;
struct Adjlist *array;
};
struct graph * create_graph(int V) {
struct graph *G = (struct graph *)malloc(sizeof(struct graph));
G->V = V;
G->array = (struct Adjlist *) malloc(sizeof(struct Adjlist) * V);
for(int i=0; i<V; i++) {
G->array[i].head = NULL;
}
return G;
}
void add_edge( struct graph *G, int src, int dest) {
struct listnode *node = (struct listnode *) malloc(sizeof(struct listnode));
node->dest = dest;
node->next = G->array[src].head;
G->array[src].head = node;
return;
}
struct stack {
int top;
int item[MAX];
};
void initialize(struct stack *S) {
S->top = -1;
for(int i=0; i<MAX; i++) {
S->item[i] = 0;
}
return;
}
void push(struct stack *S, int i) {
S->top++;
S->item[S->top] = i;
return;
}
bool isEmpty(struct stack *S) {
return (S->top == -1);
}
int pop(struct stack *S) {
if(!isEmpty(S)) {
int ret = S->item[S->top];
S->top--;
return ret;
}
}
void dfs(struct graph *G, int i, struct stack *S, bool visited[]) {
visited[i] = true;
struct listnode *node = G->array[i].head;
while(node) {
if(visited[node->dest] == false) {
dfs(G, node->dest, S, visited);
}
node = node->next;
}
push(S, i);
}
void topological(struct graph *G) {
bool visited[G->V];
struct stack S;
initialize(&S);
for(int i=0; i<G->V; i++) {
visited[i] = false;
}
for(int i=0; i<G->V; i++) {
if(visited[i] == false) {
dfs(G, i, &S, visited);
}
}
while(!isEmpty(&S)) {
printf("%c ", 'a' + pop(&S));
}
}
void print_order(char *words[], int len, int chars) {
struct graph *G = create_graph(chars);
for(int i=0; i<len-1; i++) {
for(int j=0; j<min(strlen(words[i]), strlen(words[i+1])); j++) {
if(words[i][j] != words[i+1][j]) {
// printf("Add edge\n");
add_edge(G, words[i][j] - 'a', words[i+1][j] - 'a');
break;
}
}
}
topological(G);
}
void main() {
char *words[] = {"caa", "aaa", "aab"};
int len = sizeof(words)/sizeof(words[0]);
print_order(words, len, 3);
}
|
the_stack_data/182860.c | /*
TITLE.C
Map Source File.
Info:
Section :
Bank : 0
Map size : 20 x 18
Tile set : tiles.gbr
Plane count : 2 planes (16 bits)
Plane order : Planes are continues
Tile offset : 128
Split data : No
This file was generated by GBMB v1.8
*/
#define title_screenWidth 20
#define title_screenHeight 18
#define title_screenBank 0
#define title_screen title_screenPLN0
const unsigned char title_screenPLN0[] =
{
0x8F,0x8F,0x8F,0x8F,0x8F,0x8F,0x8F,0x8F,0x8F,0x8F,
0x8F,0x8F,0x8F,0x8F,0x8F,0x8F,0x8F,0x8F,0x8F,0x8F,
0x8F,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x8F,
0x8F,0x80,0x80,0x80,0x90,0x80,0x90,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x90,0x80,0x8F,
0x8F,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x90,
0x80,0x80,0x80,0x80,0x80,0x90,0x80,0x80,0x80,0x8F,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x81,0x85,0x85,0x8B,0x80,0x81,0x82,0x80,0x80,0x8D,
0x80,0x81,0x85,0x85,0x8B,0x80,0x8A,0x80,0x80,0x8D,
0x86,0x80,0x80,0x80,0x80,0x86,0x86,0x80,0x80,0x86,
0x80,0x86,0x80,0x80,0x80,0x80,0x86,0x80,0x81,0x83,
0x86,0x80,0x80,0x80,0x80,0x86,0x86,0x80,0x80,0x86,
0x80,0x86,0x80,0x80,0x80,0x80,0x84,0x85,0x83,0x80,
0x84,0x85,0x85,0x82,0x80,0x86,0x84,0x85,0x82,0x86,
0x80,0x84,0x85,0x82,0x80,0x80,0x81,0x82,0x80,0x80,
0x80,0x80,0x80,0x86,0x80,0x86,0x80,0x80,0x86,0x86,
0x80,0x81,0x85,0x83,0x80,0x80,0x86,0x86,0x80,0x80,
0x80,0x80,0x80,0x86,0x80,0x86,0x80,0x80,0x86,0x86,
0x80,0x86,0x80,0x80,0x80,0x80,0x86,0x84,0x85,0x82,
0x89,0x85,0x85,0x83,0x80,0x88,0x80,0x80,0x84,0x83,
0x80,0x84,0x85,0x85,0x87,0x80,0x88,0x80,0x80,0x8E,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x8F,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x8F,
0x8F,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x8F,
0x8F,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x8F,
0x8F,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x90,0x90,0x80,0x8F,
0x8F,0x8F,0x8F,0x8F,0x8F,0x8F,0x8F,0x8F,0x8F,0x8F,
0x8F,0x8F,0x8F,0x8F,0x8F,0x8F,0x8F,0x8F,0x8F,0x8F
};
const unsigned char title_screenPLN1[] =
{
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x01,0x00,0x00,0x00,0x02,0x00,0x02,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x01,
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,
0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x01,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x02,0x00,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01
};
/* End of TITLE.C */
|
the_stack_data/622729.c | /* ldap_casa.c
CASA routines for DHCPD... */
/* Copyright (c) 2006 Novell, Inc.
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 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 ISC, ISC DHCP, 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 INTERNET SYSTEMS CONSORTIUM 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 ISC 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.
* This file was written by S Kalyanasundaram <[email protected]>
*/
/*
* Copyright (c) 2004-2010 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1995-2003 by Internet Software Consortium
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* Internet Systems Consortium, Inc.
* 950 Charter Street
* Redwood City, CA 94063
* <[email protected]>
* https://www.isc.org/
*/
#if defined(LDAP_CASA_AUTH)
#include "ldap_casa.h"
#include "dhcpd.h"
int
load_casa (void)
{
if( !(casaIDK = dlopen(MICASA_LIB,RTLD_LAZY)))
return 0;
p_miCASAGetCredential = (CASA_GetCredential_T) dlsym(casaIDK, "miCASAGetCredential");
p_miCASASetCredential = (CASA_SetCredential_T) dlsym(casaIDK, "miCASASetCredential");
p_miCASARemoveCredential = (CASA_RemoveCredential_T) dlsym(casaIDK, "miCASARemoveCredential");
if((p_miCASAGetCredential == NULL) ||
(p_miCASASetCredential == NULL) ||
(p_miCASARemoveCredential == NULL))
{
if(casaIDK)
dlclose(casaIDK);
casaIDK = NULL;
p_miCASAGetCredential = NULL;
p_miCASASetCredential = NULL;
p_miCASARemoveCredential = NULL;
return 0;
}
else
return 1;
}
static void
release_casa(void)
{
if(casaIDK)
{
dlclose(casaIDK);
casaIDK = NULL;
}
p_miCASAGetCredential = NULL;
p_miCASASetCredential = NULL;
p_miCASARemoveCredential = NULL;
}
int
load_uname_pwd_from_miCASA (char **ldap_username, char **ldap_password)
{
int result = 0;
uint32_t credentialtype = SSCS_CRED_TYPE_SERVER_F;
SSCS_BASIC_CREDENTIAL credential;
SSCS_SECRET_ID_T applicationSecretId;
char *tempVar = NULL;
const char applicationName[10] = "dhcp-ldap";
if ( load_casa() )
{
memset(&credential, 0, sizeof(SSCS_BASIC_CREDENTIAL));
memset(&applicationSecretId, 0, sizeof(SSCS_SECRET_ID_T));
applicationSecretId.len = strlen(applicationName) + 1;
memcpy (applicationSecretId.id, applicationName, applicationSecretId.len);
credential.unFlags = USERNAME_TYPE_CN_F;
result = p_miCASAGetCredential (0,
&applicationSecretId,NULL,&credentialtype,
&credential,NULL);
if(credential.unLen)
{
tempVar = dmalloc (credential.unLen + 1, MDL);
if (!tempVar)
log_fatal ("no memory for ldap_username");
memcpy(tempVar , credential.username, credential.unLen);
*ldap_username = tempVar;
tempVar = dmalloc (credential.pwordLen + 1, MDL);
if (!tempVar)
log_fatal ("no memory for ldap_password");
memcpy(tempVar, credential.password, credential.pwordLen);
*ldap_password = tempVar;
#if defined (DEBUG_LDAP)
log_info ("Authentication credential taken from CASA");
#endif
release_casa();
return 1;
}
else
{
release_casa();
return 0;
}
}
else
return 0; //casa libraries not loaded
}
#endif /* LDAP_CASA_AUTH */
|
the_stack_data/68888999.c | // WARNING in __vunmap (2)
// https://syzkaller.appspot.com/bug?id=d98704e1f65e44589b68
// status:0
// autogenerated by syzkaller (https://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <arpa/inet.h>
#include <dirent.h>
#include <endian.h>
#include <errno.h>
#include <fcntl.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <netinet/in.h>
#include <pthread.h>
#include <sched.h>
#include <setjmp.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/epoll.h>
#include <sys/ioctl.h>
#include <sys/mount.h>
#include <sys/prctl.h>
#include <sys/resource.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
#include <linux/capability.h>
#include <linux/futex.h>
#include <linux/genetlink.h>
#include <linux/if_addr.h>
#include <linux/if_ether.h>
#include <linux/if_link.h>
#include <linux/if_tun.h>
#include <linux/in6.h>
#include <linux/ip.h>
#include <linux/neighbour.h>
#include <linux/net.h>
#include <linux/netlink.h>
#include <linux/nl80211.h>
#include <linux/rfkill.h>
#include <linux/rtnetlink.h>
#include <linux/tcp.h>
#include <linux/veth.h>
static unsigned long long procid;
static __thread int skip_segv;
static __thread jmp_buf segv_env;
static void segv_handler(int sig, siginfo_t* info, void* ctx)
{
uintptr_t addr = (uintptr_t)info->si_addr;
const uintptr_t prog_start = 1 << 20;
const uintptr_t prog_end = 100 << 20;
int skip = __atomic_load_n(&skip_segv, __ATOMIC_RELAXED) != 0;
int valid = addr < prog_start || addr > prog_end;
if (skip && valid) {
_longjmp(segv_env, 1);
}
exit(sig);
}
static void install_segv_handler(void)
{
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = SIG_IGN;
syscall(SYS_rt_sigaction, 0x20, &sa, NULL, 8);
syscall(SYS_rt_sigaction, 0x21, &sa, NULL, 8);
memset(&sa, 0, sizeof(sa));
sa.sa_sigaction = segv_handler;
sa.sa_flags = SA_NODEFER | SA_SIGINFO;
sigaction(SIGSEGV, &sa, NULL);
sigaction(SIGBUS, &sa, NULL);
}
#define NONFAILING(...) \
({ \
int ok = 1; \
__atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); \
if (_setjmp(segv_env) == 0) { \
__VA_ARGS__; \
} else \
ok = 0; \
__atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); \
ok; \
})
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 void thread_start(void* (*fn)(void*), void* arg)
{
pthread_t th;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, 128 << 10);
int i = 0;
for (; i < 100; i++) {
if (pthread_create(&th, &attr, fn, arg) == 0) {
pthread_attr_destroy(&attr);
return;
}
if (errno == EAGAIN) {
usleep(50);
continue;
}
break;
}
exit(1);
}
typedef struct {
int state;
} event_t;
static void event_init(event_t* ev)
{
ev->state = 0;
}
static void event_reset(event_t* ev)
{
ev->state = 0;
}
static void event_set(event_t* ev)
{
if (ev->state)
exit(1);
__atomic_store_n(&ev->state, 1, __ATOMIC_RELEASE);
syscall(SYS_futex, &ev->state, FUTEX_WAKE | FUTEX_PRIVATE_FLAG, 1000000);
}
static void event_wait(event_t* ev)
{
while (!__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE))
syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, 0);
}
static int event_isset(event_t* ev)
{
return __atomic_load_n(&ev->state, __ATOMIC_ACQUIRE);
}
static int event_timedwait(event_t* ev, uint64_t timeout)
{
uint64_t start = current_time_ms();
uint64_t now = start;
for (;;) {
uint64_t remain = timeout - (now - start);
struct timespec ts;
ts.tv_sec = remain / 1000;
ts.tv_nsec = (remain % 1000) * 1000 * 1000;
syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, &ts);
if (__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE))
return 1;
now = current_time_ms();
if (now - start > timeout)
return 0;
}
}
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;
}
struct nlmsg {
char* pos;
int nesting;
struct nlattr* nested[8];
char buf[4096];
};
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;
if (size > 0)
memcpy(attr + 1, data, size);
nlmsg->pos += NLMSG_ALIGN(attr->nla_len);
}
static void netlink_nest(struct nlmsg* nlmsg, int typ)
{
struct nlattr* attr = (struct nlattr*)nlmsg->pos;
attr->nla_type = typ;
nlmsg->pos += sizeof(*attr);
nlmsg->nested[nlmsg->nesting++] = attr;
}
static void netlink_done(struct nlmsg* nlmsg)
{
struct nlattr* attr = nlmsg->nested[--nlmsg->nesting];
attr->nla_len = nlmsg->pos - (char*)attr;
}
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 (reply_len)
*reply_len = 0;
if (hdr->nlmsg_type == NLMSG_DONE)
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_query_family_id(struct nlmsg* nlmsg, int sock,
const char* family_name)
{
struct genlmsghdr genlhdr;
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, family_name,
strnlen(family_name, GENL_NAMSIZ - 1) + 1);
int n = 0;
int err = netlink_send_ext(nlmsg, sock, GENL_ID_CTRL, &n);
if (err < 0) {
return -1;
}
uint16_t id = 0;
struct nlattr* 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);
return id;
}
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_add_device_impl(struct nlmsg* nlmsg, const char* type,
const char* name)
{
struct ifinfomsg hdr;
memset(&hdr, 0, sizeof(hdr));
netlink_init(nlmsg, RTM_NEWLINK, NLM_F_EXCL | NLM_F_CREATE, &hdr,
sizeof(hdr));
if (name)
netlink_attr(nlmsg, IFLA_IFNAME, name, strlen(name));
netlink_nest(nlmsg, IFLA_LINKINFO);
netlink_attr(nlmsg, IFLA_INFO_KIND, type, strlen(type));
}
static void netlink_add_device(struct nlmsg* nlmsg, int sock, const char* type,
const char* name)
{
netlink_add_device_impl(nlmsg, type, name);
netlink_done(nlmsg);
int err = netlink_send(nlmsg, sock);
(void)err;
}
static void netlink_add_veth(struct nlmsg* nlmsg, int sock, const char* name,
const char* peer)
{
netlink_add_device_impl(nlmsg, "veth", name);
netlink_nest(nlmsg, IFLA_INFO_DATA);
netlink_nest(nlmsg, VETH_INFO_PEER);
nlmsg->pos += sizeof(struct ifinfomsg);
netlink_attr(nlmsg, IFLA_IFNAME, peer, strlen(peer));
netlink_done(nlmsg);
netlink_done(nlmsg);
netlink_done(nlmsg);
int err = netlink_send(nlmsg, sock);
(void)err;
}
static void netlink_add_hsr(struct nlmsg* nlmsg, int sock, const char* name,
const char* slave1, const char* slave2)
{
netlink_add_device_impl(nlmsg, "hsr", name);
netlink_nest(nlmsg, IFLA_INFO_DATA);
int ifindex1 = if_nametoindex(slave1);
netlink_attr(nlmsg, IFLA_HSR_SLAVE1, &ifindex1, sizeof(ifindex1));
int ifindex2 = if_nametoindex(slave2);
netlink_attr(nlmsg, IFLA_HSR_SLAVE2, &ifindex2, sizeof(ifindex2));
netlink_done(nlmsg);
netlink_done(nlmsg);
int err = netlink_send(nlmsg, sock);
(void)err;
}
static void netlink_add_linked(struct nlmsg* nlmsg, int sock, const char* type,
const char* name, const char* link)
{
netlink_add_device_impl(nlmsg, type, name);
netlink_done(nlmsg);
int ifindex = if_nametoindex(link);
netlink_attr(nlmsg, IFLA_LINK, &ifindex, sizeof(ifindex));
int err = netlink_send(nlmsg, sock);
(void)err;
}
static void netlink_add_vlan(struct nlmsg* nlmsg, int sock, const char* name,
const char* link, uint16_t id, uint16_t proto)
{
netlink_add_device_impl(nlmsg, "vlan", name);
netlink_nest(nlmsg, IFLA_INFO_DATA);
netlink_attr(nlmsg, IFLA_VLAN_ID, &id, sizeof(id));
netlink_attr(nlmsg, IFLA_VLAN_PROTOCOL, &proto, sizeof(proto));
netlink_done(nlmsg);
netlink_done(nlmsg);
int ifindex = if_nametoindex(link);
netlink_attr(nlmsg, IFLA_LINK, &ifindex, sizeof(ifindex));
int err = netlink_send(nlmsg, sock);
(void)err;
}
static void netlink_add_macvlan(struct nlmsg* nlmsg, int sock, const char* name,
const char* link)
{
netlink_add_device_impl(nlmsg, "macvlan", name);
netlink_nest(nlmsg, IFLA_INFO_DATA);
uint32_t mode = MACVLAN_MODE_BRIDGE;
netlink_attr(nlmsg, IFLA_MACVLAN_MODE, &mode, sizeof(mode));
netlink_done(nlmsg);
netlink_done(nlmsg);
int ifindex = if_nametoindex(link);
netlink_attr(nlmsg, IFLA_LINK, &ifindex, sizeof(ifindex));
int err = netlink_send(nlmsg, sock);
(void)err;
}
static void netlink_add_geneve(struct nlmsg* nlmsg, int sock, const char* name,
uint32_t vni, struct in_addr* addr4,
struct in6_addr* addr6)
{
netlink_add_device_impl(nlmsg, "geneve", name);
netlink_nest(nlmsg, IFLA_INFO_DATA);
netlink_attr(nlmsg, IFLA_GENEVE_ID, &vni, sizeof(vni));
if (addr4)
netlink_attr(nlmsg, IFLA_GENEVE_REMOTE, addr4, sizeof(*addr4));
if (addr6)
netlink_attr(nlmsg, IFLA_GENEVE_REMOTE6, addr6, sizeof(*addr6));
netlink_done(nlmsg);
netlink_done(nlmsg);
int err = netlink_send(nlmsg, sock);
(void)err;
}
#define IFLA_IPVLAN_FLAGS 2
#define IPVLAN_MODE_L3S 2
#undef IPVLAN_F_VEPA
#define IPVLAN_F_VEPA 2
static void netlink_add_ipvlan(struct nlmsg* nlmsg, int sock, const char* name,
const char* link, uint16_t mode, uint16_t flags)
{
netlink_add_device_impl(nlmsg, "ipvlan", name);
netlink_nest(nlmsg, IFLA_INFO_DATA);
netlink_attr(nlmsg, IFLA_IPVLAN_MODE, &mode, sizeof(mode));
netlink_attr(nlmsg, IFLA_IPVLAN_FLAGS, &flags, sizeof(flags));
netlink_done(nlmsg);
netlink_done(nlmsg);
int ifindex = if_nametoindex(link);
netlink_attr(nlmsg, IFLA_LINK, &ifindex, sizeof(ifindex));
int err = netlink_send(nlmsg, sock);
(void)err;
}
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;
}
static int netlink_add_addr(struct nlmsg* nlmsg, int sock, const char* dev,
const void* addr, int addrsize)
{
struct ifaddrmsg hdr;
memset(&hdr, 0, sizeof(hdr));
hdr.ifa_family = addrsize == 4 ? AF_INET : AF_INET6;
hdr.ifa_prefixlen = addrsize == 4 ? 24 : 120;
hdr.ifa_scope = RT_SCOPE_UNIVERSE;
hdr.ifa_index = if_nametoindex(dev);
netlink_init(nlmsg, RTM_NEWADDR, NLM_F_CREATE | NLM_F_REPLACE, &hdr,
sizeof(hdr));
netlink_attr(nlmsg, IFA_LOCAL, addr, addrsize);
netlink_attr(nlmsg, IFA_ADDRESS, addr, addrsize);
return netlink_send(nlmsg, sock);
}
static void netlink_add_addr4(struct nlmsg* nlmsg, int sock, const char* dev,
const char* addr)
{
struct in_addr in_addr;
inet_pton(AF_INET, addr, &in_addr);
int err = netlink_add_addr(nlmsg, sock, dev, &in_addr, sizeof(in_addr));
(void)err;
}
static void netlink_add_addr6(struct nlmsg* nlmsg, int sock, const char* dev,
const char* addr)
{
struct in6_addr in6_addr;
inet_pton(AF_INET6, addr, &in6_addr);
int err = netlink_add_addr(nlmsg, sock, dev, &in6_addr, sizeof(in6_addr));
(void)err;
}
static void netlink_add_neigh(struct nlmsg* nlmsg, int sock, const char* name,
const void* addr, int addrsize, const void* mac,
int macsize)
{
struct ndmsg hdr;
memset(&hdr, 0, sizeof(hdr));
hdr.ndm_family = addrsize == 4 ? AF_INET : AF_INET6;
hdr.ndm_ifindex = if_nametoindex(name);
hdr.ndm_state = NUD_PERMANENT;
netlink_init(nlmsg, RTM_NEWNEIGH, NLM_F_EXCL | NLM_F_CREATE, &hdr,
sizeof(hdr));
netlink_attr(nlmsg, NDA_DST, addr, addrsize);
netlink_attr(nlmsg, NDA_LLADDR, mac, macsize);
int err = netlink_send(nlmsg, sock);
(void)err;
}
static struct nlmsg nlmsg;
static int tunfd = -1;
#define TUN_IFACE "syz_tun"
#define LOCAL_MAC 0xaaaaaaaaaaaa
#define REMOTE_MAC 0xaaaaaaaaaabb
#define LOCAL_IPV4 "172.20.20.170"
#define REMOTE_IPV4 "172.20.20.187"
#define LOCAL_IPV6 "fe80::aa"
#define REMOTE_IPV6 "fe80::bb"
#define IFF_NAPI 0x0010
static void initialize_tun(void)
{
tunfd = open("/dev/net/tun", O_RDWR | O_NONBLOCK);
if (tunfd == -1) {
printf("tun: can't open /dev/net/tun: please enable CONFIG_TUN=y\n");
printf("otherwise fuzzing or reproducing might not work as intended\n");
return;
}
const int kTunFd = 240;
if (dup2(tunfd, kTunFd) < 0)
exit(1);
close(tunfd);
tunfd = kTunFd;
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, TUN_IFACE, IFNAMSIZ);
ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
if (ioctl(tunfd, TUNSETIFF, (void*)&ifr) < 0) {
exit(1);
}
char sysctl[64];
sprintf(sysctl, "/proc/sys/net/ipv6/conf/%s/accept_dad", TUN_IFACE);
write_file(sysctl, "0");
sprintf(sysctl, "/proc/sys/net/ipv6/conf/%s/router_solicitations", TUN_IFACE);
write_file(sysctl, "0");
int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (sock == -1)
exit(1);
netlink_add_addr4(&nlmsg, sock, TUN_IFACE, LOCAL_IPV4);
netlink_add_addr6(&nlmsg, sock, TUN_IFACE, LOCAL_IPV6);
uint64_t macaddr = REMOTE_MAC;
struct in_addr in_addr;
inet_pton(AF_INET, REMOTE_IPV4, &in_addr);
netlink_add_neigh(&nlmsg, sock, TUN_IFACE, &in_addr, sizeof(in_addr),
&macaddr, ETH_ALEN);
struct in6_addr in6_addr;
inet_pton(AF_INET6, REMOTE_IPV6, &in6_addr);
netlink_add_neigh(&nlmsg, sock, TUN_IFACE, &in6_addr, sizeof(in6_addr),
&macaddr, ETH_ALEN);
macaddr = LOCAL_MAC;
netlink_device_change(&nlmsg, sock, TUN_IFACE, true, 0, &macaddr, ETH_ALEN,
NULL);
close(sock);
}
#define DEVLINK_FAMILY_NAME "devlink"
#define DEVLINK_CMD_PORT_GET 5
#define DEVLINK_ATTR_BUS_NAME 1
#define DEVLINK_ATTR_DEV_NAME 2
#define DEVLINK_ATTR_NETDEV_NAME 7
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_query_family_id(&nlmsg, sock, DEVLINK_FAMILY_NAME);
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 < 0) {
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);
}
#define WIFI_INITIAL_DEVICE_COUNT 2
#define WIFI_MAC_BASE \
{ \
0x08, 0x02, 0x11, 0x00, 0x00, 0x00 \
}
#define WIFI_IBSS_BSSID \
{ \
0x50, 0x50, 0x50, 0x50, 0x50, 0x50 \
}
#define WIFI_IBSS_SSID \
{ \
0x10, 0x10, 0x10, 0x10, 0x10, 0x10 \
}
#define WIFI_DEFAULT_FREQUENCY 2412
#define WIFI_DEFAULT_SIGNAL 0
#define WIFI_DEFAULT_RX_RATE 1
#define HWSIM_CMD_REGISTER 1
#define HWSIM_CMD_FRAME 2
#define HWSIM_CMD_NEW_RADIO 4
#define HWSIM_ATTR_SUPPORT_P2P_DEVICE 14
#define HWSIM_ATTR_PERM_ADDR 22
#define IF_OPER_UP 6
struct join_ibss_props {
int wiphy_freq;
bool wiphy_freq_fixed;
uint8_t* mac;
uint8_t* ssid;
int ssid_len;
};
static int set_interface_state(const char* interface_name, int on)
{
struct ifreq ifr;
int sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock < 0) {
return -1;
}
memset(&ifr, 0, sizeof(ifr));
strcpy(ifr.ifr_name, interface_name);
int ret = ioctl(sock, SIOCGIFFLAGS, &ifr);
if (ret < 0) {
close(sock);
return -1;
}
if (on)
ifr.ifr_flags |= IFF_UP;
else
ifr.ifr_flags &= ~IFF_UP;
ret = ioctl(sock, SIOCSIFFLAGS, &ifr);
close(sock);
if (ret < 0) {
return -1;
}
return 0;
}
static int nl80211_set_interface(struct nlmsg* nlmsg, int sock,
int nl80211_family, uint32_t ifindex,
uint32_t iftype)
{
struct genlmsghdr genlhdr;
memset(&genlhdr, 0, sizeof(genlhdr));
genlhdr.cmd = NL80211_CMD_SET_INTERFACE;
netlink_init(nlmsg, nl80211_family, 0, &genlhdr, sizeof(genlhdr));
netlink_attr(nlmsg, NL80211_ATTR_IFINDEX, &ifindex, sizeof(ifindex));
netlink_attr(nlmsg, NL80211_ATTR_IFTYPE, &iftype, sizeof(iftype));
int err = netlink_send(nlmsg, sock);
if (err < 0) {
return -1;
}
return 0;
}
static int nl80211_join_ibss(struct nlmsg* nlmsg, int sock, int nl80211_family,
uint32_t ifindex, struct join_ibss_props* props)
{
struct genlmsghdr genlhdr;
memset(&genlhdr, 0, sizeof(genlhdr));
genlhdr.cmd = NL80211_CMD_JOIN_IBSS;
netlink_init(nlmsg, nl80211_family, 0, &genlhdr, sizeof(genlhdr));
netlink_attr(nlmsg, NL80211_ATTR_IFINDEX, &ifindex, sizeof(ifindex));
netlink_attr(nlmsg, NL80211_ATTR_SSID, props->ssid, props->ssid_len);
netlink_attr(nlmsg, NL80211_ATTR_WIPHY_FREQ, &(props->wiphy_freq),
sizeof(props->wiphy_freq));
if (props->mac)
netlink_attr(nlmsg, NL80211_ATTR_MAC, props->mac, ETH_ALEN);
if (props->wiphy_freq_fixed)
netlink_attr(nlmsg, NL80211_ATTR_FREQ_FIXED, NULL, 0);
int err = netlink_send(nlmsg, sock);
if (err < 0) {
return -1;
}
return 0;
}
static int get_ifla_operstate(struct nlmsg* nlmsg, int ifindex)
{
struct ifinfomsg info;
memset(&info, 0, sizeof(info));
info.ifi_family = AF_UNSPEC;
info.ifi_index = ifindex;
int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (sock == -1) {
return -1;
}
netlink_init(nlmsg, RTM_GETLINK, 0, &info, sizeof(info));
int n;
int err = netlink_send_ext(nlmsg, sock, RTM_NEWLINK, &n);
close(sock);
if (err) {
return -1;
}
struct rtattr* attr = IFLA_RTA(NLMSG_DATA(nlmsg->buf));
for (; RTA_OK(attr, n); attr = RTA_NEXT(attr, n)) {
if (attr->rta_type == IFLA_OPERSTATE)
return *((int32_t*)RTA_DATA(attr));
}
return -1;
}
static int await_ifla_operstate(struct nlmsg* nlmsg, char* interface,
int operstate)
{
int ifindex = if_nametoindex(interface);
while (true) {
usleep(1000);
int ret = get_ifla_operstate(nlmsg, ifindex);
if (ret < 0)
return ret;
if (ret == operstate)
return 0;
}
return 0;
}
static int nl80211_setup_ibss_interface(struct nlmsg* nlmsg, int sock,
int nl80211_family_id, char* interface,
struct join_ibss_props* ibss_props)
{
int ifindex = if_nametoindex(interface);
if (ifindex == 0) {
return -1;
}
int ret = nl80211_set_interface(nlmsg, sock, nl80211_family_id, ifindex,
NL80211_IFTYPE_ADHOC);
if (ret < 0) {
return -1;
}
ret = set_interface_state(interface, 1);
if (ret < 0) {
return -1;
}
ret = nl80211_join_ibss(nlmsg, sock, nl80211_family_id, ifindex, ibss_props);
if (ret < 0) {
return -1;
}
return 0;
}
static int hwsim80211_create_device(struct nlmsg* nlmsg, int sock,
int hwsim_family,
uint8_t mac_addr[ETH_ALEN])
{
struct genlmsghdr genlhdr;
memset(&genlhdr, 0, sizeof(genlhdr));
genlhdr.cmd = HWSIM_CMD_NEW_RADIO;
netlink_init(nlmsg, hwsim_family, 0, &genlhdr, sizeof(genlhdr));
netlink_attr(nlmsg, HWSIM_ATTR_SUPPORT_P2P_DEVICE, NULL, 0);
netlink_attr(nlmsg, HWSIM_ATTR_PERM_ADDR, mac_addr, ETH_ALEN);
int err = netlink_send(nlmsg, sock);
if (err < 0) {
return -1;
}
return 0;
}
static void initialize_wifi_devices(void)
{
uint8_t mac_addr[6] = WIFI_MAC_BASE;
int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC);
if (sock < 0) {
return;
}
int hwsim_family_id = netlink_query_family_id(&nlmsg, sock, "MAC80211_HWSIM");
int nl80211_family_id = netlink_query_family_id(&nlmsg, sock, "nl80211");
uint8_t ssid[] = WIFI_IBSS_SSID;
uint8_t bssid[] = WIFI_IBSS_BSSID;
struct join_ibss_props ibss_props = {.wiphy_freq = WIFI_DEFAULT_FREQUENCY,
.wiphy_freq_fixed = true,
.mac = bssid,
.ssid = ssid,
.ssid_len = sizeof(ssid)};
for (int device_id = 0; device_id < WIFI_INITIAL_DEVICE_COUNT; device_id++) {
mac_addr[5] = device_id;
int ret = hwsim80211_create_device(&nlmsg, sock, hwsim_family_id, mac_addr);
if (ret < 0)
exit(1);
char interface[6] = "wlan0";
interface[4] += device_id;
if (nl80211_setup_ibss_interface(&nlmsg, sock, nl80211_family_id, interface,
&ibss_props) < 0)
exit(1);
}
for (int device_id = 0; device_id < WIFI_INITIAL_DEVICE_COUNT; device_id++) {
char interface[6] = "wlan0";
interface[4] += device_id;
int ret = await_ifla_operstate(&nlmsg, interface, IF_OPER_UP);
if (ret < 0)
exit(1);
}
close(sock);
}
#define DEV_IPV4 "172.20.20.%d"
#define DEV_IPV6 "fe80::%02x"
#define DEV_MAC 0x00aaaaaaaaaa
static void netdevsim_add(unsigned int addr, unsigned int port_count)
{
char buf[16];
sprintf(buf, "%u %u", addr, port_count);
if (write_file("/sys/bus/netdevsim/new_device", buf)) {
snprintf(buf, sizeof(buf), "netdevsim%d", addr);
initialize_devlink_ports("netdevsim", buf, "netdevsim");
}
}
#define WG_GENL_NAME "wireguard"
enum wg_cmd {
WG_CMD_GET_DEVICE,
WG_CMD_SET_DEVICE,
};
enum wgdevice_attribute {
WGDEVICE_A_UNSPEC,
WGDEVICE_A_IFINDEX,
WGDEVICE_A_IFNAME,
WGDEVICE_A_PRIVATE_KEY,
WGDEVICE_A_PUBLIC_KEY,
WGDEVICE_A_FLAGS,
WGDEVICE_A_LISTEN_PORT,
WGDEVICE_A_FWMARK,
WGDEVICE_A_PEERS,
};
enum wgpeer_attribute {
WGPEER_A_UNSPEC,
WGPEER_A_PUBLIC_KEY,
WGPEER_A_PRESHARED_KEY,
WGPEER_A_FLAGS,
WGPEER_A_ENDPOINT,
WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
WGPEER_A_LAST_HANDSHAKE_TIME,
WGPEER_A_RX_BYTES,
WGPEER_A_TX_BYTES,
WGPEER_A_ALLOWEDIPS,
WGPEER_A_PROTOCOL_VERSION,
};
enum wgallowedip_attribute {
WGALLOWEDIP_A_UNSPEC,
WGALLOWEDIP_A_FAMILY,
WGALLOWEDIP_A_IPADDR,
WGALLOWEDIP_A_CIDR_MASK,
};
static void netlink_wireguard_setup(void)
{
const char ifname_a[] = "wg0";
const char ifname_b[] = "wg1";
const char ifname_c[] = "wg2";
const char private_a[] =
"\xa0\x5c\xa8\x4f\x6c\x9c\x8e\x38\x53\xe2\xfd\x7a\x70\xae\x0f\xb2\x0f\xa1"
"\x52\x60\x0c\xb0\x08\x45\x17\x4f\x08\x07\x6f\x8d\x78\x43";
const char private_b[] =
"\xb0\x80\x73\xe8\xd4\x4e\x91\xe3\xda\x92\x2c\x22\x43\x82\x44\xbb\x88\x5c"
"\x69\xe2\x69\xc8\xe9\xd8\x35\xb1\x14\x29\x3a\x4d\xdc\x6e";
const char private_c[] =
"\xa0\xcb\x87\x9a\x47\xf5\xbc\x64\x4c\x0e\x69\x3f\xa6\xd0\x31\xc7\x4a\x15"
"\x53\xb6\xe9\x01\xb9\xff\x2f\x51\x8c\x78\x04\x2f\xb5\x42";
const char public_a[] =
"\x97\x5c\x9d\x81\xc9\x83\xc8\x20\x9e\xe7\x81\x25\x4b\x89\x9f\x8e\xd9\x25"
"\xae\x9f\x09\x23\xc2\x3c\x62\xf5\x3c\x57\xcd\xbf\x69\x1c";
const char public_b[] =
"\xd1\x73\x28\x99\xf6\x11\xcd\x89\x94\x03\x4d\x7f\x41\x3d\xc9\x57\x63\x0e"
"\x54\x93\xc2\x85\xac\xa4\x00\x65\xcb\x63\x11\xbe\x69\x6b";
const char public_c[] =
"\xf4\x4d\xa3\x67\xa8\x8e\xe6\x56\x4f\x02\x02\x11\x45\x67\x27\x08\x2f\x5c"
"\xeb\xee\x8b\x1b\xf5\xeb\x73\x37\x34\x1b\x45\x9b\x39\x22";
const uint16_t listen_a = 20001;
const uint16_t listen_b = 20002;
const uint16_t listen_c = 20003;
const uint16_t af_inet = AF_INET;
const uint16_t af_inet6 = AF_INET6;
const struct sockaddr_in endpoint_b_v4 = {
.sin_family = AF_INET,
.sin_port = htons(listen_b),
.sin_addr = {htonl(INADDR_LOOPBACK)}};
const struct sockaddr_in endpoint_c_v4 = {
.sin_family = AF_INET,
.sin_port = htons(listen_c),
.sin_addr = {htonl(INADDR_LOOPBACK)}};
struct sockaddr_in6 endpoint_a_v6 = {.sin6_family = AF_INET6,
.sin6_port = htons(listen_a)};
endpoint_a_v6.sin6_addr = in6addr_loopback;
struct sockaddr_in6 endpoint_c_v6 = {.sin6_family = AF_INET6,
.sin6_port = htons(listen_c)};
endpoint_c_v6.sin6_addr = in6addr_loopback;
const struct in_addr first_half_v4 = {0};
const struct in_addr second_half_v4 = {(uint32_t)htonl(128 << 24)};
const struct in6_addr first_half_v6 = {{{0}}};
const struct in6_addr second_half_v6 = {{{0x80}}};
const uint8_t half_cidr = 1;
const uint16_t persistent_keepalives[] = {1, 3, 7, 9, 14, 19};
struct genlmsghdr genlhdr = {.cmd = WG_CMD_SET_DEVICE, .version = 1};
int sock;
int id, err;
sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC);
if (sock == -1) {
return;
}
id = netlink_query_family_id(&nlmsg, sock, WG_GENL_NAME);
if (id == -1)
goto error;
netlink_init(&nlmsg, id, 0, &genlhdr, sizeof(genlhdr));
netlink_attr(&nlmsg, WGDEVICE_A_IFNAME, ifname_a, strlen(ifname_a) + 1);
netlink_attr(&nlmsg, WGDEVICE_A_PRIVATE_KEY, private_a, 32);
netlink_attr(&nlmsg, WGDEVICE_A_LISTEN_PORT, &listen_a, 2);
netlink_nest(&nlmsg, NLA_F_NESTED | WGDEVICE_A_PEERS);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_b, 32);
netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_b_v4,
sizeof(endpoint_b_v4));
netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
&persistent_keepalives[0], 2);
netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v4,
sizeof(first_half_v4));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v6,
sizeof(first_half_v6));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_c, 32);
netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_c_v6,
sizeof(endpoint_c_v6));
netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
&persistent_keepalives[1], 2);
netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v4,
sizeof(second_half_v4));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v6,
sizeof(second_half_v6));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
err = netlink_send(&nlmsg, sock);
if (err < 0) {
}
netlink_init(&nlmsg, id, 0, &genlhdr, sizeof(genlhdr));
netlink_attr(&nlmsg, WGDEVICE_A_IFNAME, ifname_b, strlen(ifname_b) + 1);
netlink_attr(&nlmsg, WGDEVICE_A_PRIVATE_KEY, private_b, 32);
netlink_attr(&nlmsg, WGDEVICE_A_LISTEN_PORT, &listen_b, 2);
netlink_nest(&nlmsg, NLA_F_NESTED | WGDEVICE_A_PEERS);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_a, 32);
netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_a_v6,
sizeof(endpoint_a_v6));
netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
&persistent_keepalives[2], 2);
netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v4,
sizeof(first_half_v4));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v6,
sizeof(first_half_v6));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_c, 32);
netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_c_v4,
sizeof(endpoint_c_v4));
netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
&persistent_keepalives[3], 2);
netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v4,
sizeof(second_half_v4));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v6,
sizeof(second_half_v6));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
err = netlink_send(&nlmsg, sock);
if (err < 0) {
}
netlink_init(&nlmsg, id, 0, &genlhdr, sizeof(genlhdr));
netlink_attr(&nlmsg, WGDEVICE_A_IFNAME, ifname_c, strlen(ifname_c) + 1);
netlink_attr(&nlmsg, WGDEVICE_A_PRIVATE_KEY, private_c, 32);
netlink_attr(&nlmsg, WGDEVICE_A_LISTEN_PORT, &listen_c, 2);
netlink_nest(&nlmsg, NLA_F_NESTED | WGDEVICE_A_PEERS);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_a, 32);
netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_a_v6,
sizeof(endpoint_a_v6));
netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
&persistent_keepalives[4], 2);
netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v4,
sizeof(first_half_v4));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v6,
sizeof(first_half_v6));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_b, 32);
netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_b_v4,
sizeof(endpoint_b_v4));
netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
&persistent_keepalives[5], 2);
netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v4,
sizeof(second_half_v4));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v6,
sizeof(second_half_v6));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
err = netlink_send(&nlmsg, sock);
if (err < 0) {
}
error:
close(sock);
}
static void initialize_netdevices(void)
{
char netdevsim[16];
sprintf(netdevsim, "netdevsim%d", (int)procid);
struct {
const char* type;
const char* dev;
} devtypes[] = {
{"ip6gretap", "ip6gretap0"}, {"bridge", "bridge0"},
{"vcan", "vcan0"}, {"bond", "bond0"},
{"team", "team0"}, {"dummy", "dummy0"},
{"nlmon", "nlmon0"}, {"caif", "caif0"},
{"batadv", "batadv0"}, {"vxcan", "vxcan1"},
{"netdevsim", netdevsim}, {"veth", 0},
{"xfrm", "xfrm0"}, {"wireguard", "wg0"},
{"wireguard", "wg1"}, {"wireguard", "wg2"},
};
const char* devmasters[] = {"bridge", "bond", "team", "batadv"};
struct {
const char* name;
int macsize;
bool noipv6;
} devices[] = {
{"lo", ETH_ALEN},
{"sit0", 0},
{"bridge0", ETH_ALEN},
{"vcan0", 0, true},
{"tunl0", 0},
{"gre0", 0},
{"gretap0", ETH_ALEN},
{"ip_vti0", 0},
{"ip6_vti0", 0},
{"ip6tnl0", 0},
{"ip6gre0", 0},
{"ip6gretap0", ETH_ALEN},
{"erspan0", ETH_ALEN},
{"bond0", ETH_ALEN},
{"veth0", ETH_ALEN},
{"veth1", ETH_ALEN},
{"team0", ETH_ALEN},
{"veth0_to_bridge", ETH_ALEN},
{"veth1_to_bridge", ETH_ALEN},
{"veth0_to_bond", ETH_ALEN},
{"veth1_to_bond", ETH_ALEN},
{"veth0_to_team", ETH_ALEN},
{"veth1_to_team", ETH_ALEN},
{"veth0_to_hsr", ETH_ALEN},
{"veth1_to_hsr", ETH_ALEN},
{"hsr0", 0},
{"dummy0", ETH_ALEN},
{"nlmon0", 0},
{"vxcan0", 0, true},
{"vxcan1", 0, true},
{"caif0", ETH_ALEN},
{"batadv0", ETH_ALEN},
{netdevsim, ETH_ALEN},
{"xfrm0", ETH_ALEN},
{"veth0_virt_wifi", ETH_ALEN},
{"veth1_virt_wifi", ETH_ALEN},
{"virt_wifi0", ETH_ALEN},
{"veth0_vlan", ETH_ALEN},
{"veth1_vlan", ETH_ALEN},
{"vlan0", ETH_ALEN},
{"vlan1", ETH_ALEN},
{"macvlan0", ETH_ALEN},
{"macvlan1", ETH_ALEN},
{"ipvlan0", ETH_ALEN},
{"ipvlan1", ETH_ALEN},
{"veth0_macvtap", ETH_ALEN},
{"veth1_macvtap", ETH_ALEN},
{"macvtap0", ETH_ALEN},
{"macsec0", ETH_ALEN},
{"veth0_to_batadv", ETH_ALEN},
{"veth1_to_batadv", ETH_ALEN},
{"batadv_slave_0", ETH_ALEN},
{"batadv_slave_1", ETH_ALEN},
{"geneve0", ETH_ALEN},
{"geneve1", ETH_ALEN},
{"wg0", 0},
{"wg1", 0},
{"wg2", 0},
};
int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (sock == -1)
exit(1);
unsigned i;
for (i = 0; i < sizeof(devtypes) / sizeof(devtypes[0]); i++)
netlink_add_device(&nlmsg, sock, devtypes[i].type, devtypes[i].dev);
for (i = 0; i < sizeof(devmasters) / (sizeof(devmasters[0])); i++) {
char master[32], slave0[32], veth0[32], slave1[32], veth1[32];
sprintf(slave0, "%s_slave_0", devmasters[i]);
sprintf(veth0, "veth0_to_%s", devmasters[i]);
netlink_add_veth(&nlmsg, sock, slave0, veth0);
sprintf(slave1, "%s_slave_1", devmasters[i]);
sprintf(veth1, "veth1_to_%s", devmasters[i]);
netlink_add_veth(&nlmsg, sock, slave1, veth1);
sprintf(master, "%s0", devmasters[i]);
netlink_device_change(&nlmsg, sock, slave0, false, master, 0, 0, NULL);
netlink_device_change(&nlmsg, sock, slave1, false, master, 0, 0, NULL);
}
netlink_device_change(&nlmsg, sock, "bridge_slave_0", true, 0, 0, 0, NULL);
netlink_device_change(&nlmsg, sock, "bridge_slave_1", true, 0, 0, 0, NULL);
netlink_add_veth(&nlmsg, sock, "hsr_slave_0", "veth0_to_hsr");
netlink_add_veth(&nlmsg, sock, "hsr_slave_1", "veth1_to_hsr");
netlink_add_hsr(&nlmsg, sock, "hsr0", "hsr_slave_0", "hsr_slave_1");
netlink_device_change(&nlmsg, sock, "hsr_slave_0", true, 0, 0, 0, NULL);
netlink_device_change(&nlmsg, sock, "hsr_slave_1", true, 0, 0, 0, NULL);
netlink_add_veth(&nlmsg, sock, "veth0_virt_wifi", "veth1_virt_wifi");
netlink_add_linked(&nlmsg, sock, "virt_wifi", "virt_wifi0",
"veth1_virt_wifi");
netlink_add_veth(&nlmsg, sock, "veth0_vlan", "veth1_vlan");
netlink_add_vlan(&nlmsg, sock, "vlan0", "veth0_vlan", 0, htons(ETH_P_8021Q));
netlink_add_vlan(&nlmsg, sock, "vlan1", "veth0_vlan", 1, htons(ETH_P_8021AD));
netlink_add_macvlan(&nlmsg, sock, "macvlan0", "veth1_vlan");
netlink_add_macvlan(&nlmsg, sock, "macvlan1", "veth1_vlan");
netlink_add_ipvlan(&nlmsg, sock, "ipvlan0", "veth0_vlan", IPVLAN_MODE_L2, 0);
netlink_add_ipvlan(&nlmsg, sock, "ipvlan1", "veth0_vlan", IPVLAN_MODE_L3S,
IPVLAN_F_VEPA);
netlink_add_veth(&nlmsg, sock, "veth0_macvtap", "veth1_macvtap");
netlink_add_linked(&nlmsg, sock, "macvtap", "macvtap0", "veth0_macvtap");
netlink_add_linked(&nlmsg, sock, "macsec", "macsec0", "veth1_macvtap");
char addr[32];
sprintf(addr, DEV_IPV4, 14 + 10);
struct in_addr geneve_addr4;
if (inet_pton(AF_INET, addr, &geneve_addr4) <= 0)
exit(1);
struct in6_addr geneve_addr6;
if (inet_pton(AF_INET6, "fc00::01", &geneve_addr6) <= 0)
exit(1);
netlink_add_geneve(&nlmsg, sock, "geneve0", 0, &geneve_addr4, 0);
netlink_add_geneve(&nlmsg, sock, "geneve1", 1, 0, &geneve_addr6);
netdevsim_add((int)procid, 4);
netlink_wireguard_setup();
for (i = 0; i < sizeof(devices) / (sizeof(devices[0])); i++) {
char addr[32];
sprintf(addr, DEV_IPV4, i + 10);
netlink_add_addr4(&nlmsg, sock, devices[i].name, addr);
if (!devices[i].noipv6) {
sprintf(addr, DEV_IPV6, i + 10);
netlink_add_addr6(&nlmsg, sock, devices[i].name, addr);
}
uint64_t macaddr = DEV_MAC + ((i + 10ull) << 40);
netlink_device_change(&nlmsg, sock, devices[i].name, true, 0, &macaddr,
devices[i].macsize, NULL);
}
close(sock);
}
static void initialize_netdevices_init(void)
{
int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (sock == -1)
exit(1);
struct {
const char* type;
int macsize;
bool noipv6;
bool noup;
} devtypes[] = {
{"nr", 7, true},
{"rose", 5, true, true},
};
unsigned i;
for (i = 0; i < sizeof(devtypes) / sizeof(devtypes[0]); i++) {
char dev[32], addr[32];
sprintf(dev, "%s%d", devtypes[i].type, (int)procid);
sprintf(addr, "172.30.%d.%d", i, (int)procid + 1);
netlink_add_addr4(&nlmsg, sock, dev, addr);
if (!devtypes[i].noipv6) {
sprintf(addr, "fe88::%02x:%02x", i, (int)procid + 1);
netlink_add_addr6(&nlmsg, sock, dev, addr);
}
int macsize = devtypes[i].macsize;
uint64_t macaddr = 0xbbbbbb +
((unsigned long long)i << (8 * (macsize - 2))) +
(procid << (8 * (macsize - 1)));
netlink_device_change(&nlmsg, sock, dev, !devtypes[i].noup, 0, &macaddr,
macsize, NULL);
}
close(sock);
}
static int read_tun(char* data, int size)
{
if (tunfd < 0)
return -1;
int rv = read(tunfd, data, size);
if (rv < 0) {
if (errno == EAGAIN || errno == EBADFD)
return -1;
exit(1);
}
return rv;
}
static void flush_tun()
{
char data[1000];
while (read_tun(&data[0], sizeof(data)) != -1) {
}
}
#define MAX_FDS 30
#define BTPROTO_HCI 1
#define ACL_LINK 1
#define SCAN_PAGE 2
typedef struct {
uint8_t b[6];
} __attribute__((packed)) bdaddr_t;
#define HCI_COMMAND_PKT 1
#define HCI_EVENT_PKT 4
#define HCI_VENDOR_PKT 0xff
struct hci_command_hdr {
uint16_t opcode;
uint8_t plen;
} __attribute__((packed));
struct hci_event_hdr {
uint8_t evt;
uint8_t plen;
} __attribute__((packed));
#define HCI_EV_CONN_COMPLETE 0x03
struct hci_ev_conn_complete {
uint8_t status;
uint16_t handle;
bdaddr_t bdaddr;
uint8_t link_type;
uint8_t encr_mode;
} __attribute__((packed));
#define HCI_EV_CONN_REQUEST 0x04
struct hci_ev_conn_request {
bdaddr_t bdaddr;
uint8_t dev_class[3];
uint8_t link_type;
} __attribute__((packed));
#define HCI_EV_REMOTE_FEATURES 0x0b
struct hci_ev_remote_features {
uint8_t status;
uint16_t handle;
uint8_t features[8];
} __attribute__((packed));
#define HCI_EV_CMD_COMPLETE 0x0e
struct hci_ev_cmd_complete {
uint8_t ncmd;
uint16_t opcode;
} __attribute__((packed));
#define HCI_OP_WRITE_SCAN_ENABLE 0x0c1a
#define HCI_OP_READ_BUFFER_SIZE 0x1005
struct hci_rp_read_buffer_size {
uint8_t status;
uint16_t acl_mtu;
uint8_t sco_mtu;
uint16_t acl_max_pkt;
uint16_t sco_max_pkt;
} __attribute__((packed));
#define HCI_OP_READ_BD_ADDR 0x1009
struct hci_rp_read_bd_addr {
uint8_t status;
bdaddr_t bdaddr;
} __attribute__((packed));
#define HCI_EV_LE_META 0x3e
struct hci_ev_le_meta {
uint8_t subevent;
} __attribute__((packed));
#define HCI_EV_LE_CONN_COMPLETE 0x01
struct hci_ev_le_conn_complete {
uint8_t status;
uint16_t handle;
uint8_t role;
uint8_t bdaddr_type;
bdaddr_t bdaddr;
uint16_t interval;
uint16_t latency;
uint16_t supervision_timeout;
uint8_t clk_accurancy;
} __attribute__((packed));
struct hci_dev_req {
uint16_t dev_id;
uint32_t dev_opt;
};
struct vhci_vendor_pkt {
uint8_t type;
uint8_t opcode;
uint16_t id;
};
#define HCIDEVUP _IOW('H', 201, int)
#define HCISETSCAN _IOW('H', 221, int)
static int vhci_fd = -1;
static void rfkill_unblock_all()
{
int fd = open("/dev/rfkill", O_WRONLY);
if (fd < 0)
exit(1);
struct rfkill_event event = {0};
event.idx = 0;
event.type = RFKILL_TYPE_ALL;
event.op = RFKILL_OP_CHANGE_ALL;
event.soft = 0;
event.hard = 0;
if (write(fd, &event, sizeof(event)) < 0)
exit(1);
close(fd);
}
static void hci_send_event_packet(int fd, uint8_t evt, void* data,
size_t data_len)
{
struct iovec iv[3];
struct hci_event_hdr hdr;
hdr.evt = evt;
hdr.plen = data_len;
uint8_t type = HCI_EVENT_PKT;
iv[0].iov_base = &type;
iv[0].iov_len = sizeof(type);
iv[1].iov_base = &hdr;
iv[1].iov_len = sizeof(hdr);
iv[2].iov_base = data;
iv[2].iov_len = data_len;
if (writev(fd, iv, sizeof(iv) / sizeof(struct iovec)) < 0)
exit(1);
}
static void hci_send_event_cmd_complete(int fd, uint16_t opcode, void* data,
size_t data_len)
{
struct iovec iv[4];
struct hci_event_hdr hdr;
hdr.evt = HCI_EV_CMD_COMPLETE;
hdr.plen = sizeof(struct hci_ev_cmd_complete) + data_len;
struct hci_ev_cmd_complete evt_hdr;
evt_hdr.ncmd = 1;
evt_hdr.opcode = opcode;
uint8_t type = HCI_EVENT_PKT;
iv[0].iov_base = &type;
iv[0].iov_len = sizeof(type);
iv[1].iov_base = &hdr;
iv[1].iov_len = sizeof(hdr);
iv[2].iov_base = &evt_hdr;
iv[2].iov_len = sizeof(evt_hdr);
iv[3].iov_base = data;
iv[3].iov_len = data_len;
if (writev(fd, iv, sizeof(iv) / sizeof(struct iovec)) < 0)
exit(1);
}
static bool process_command_pkt(int fd, char* buf, ssize_t buf_size)
{
struct hci_command_hdr* hdr = (struct hci_command_hdr*)buf;
if (buf_size < (ssize_t)sizeof(struct hci_command_hdr) ||
hdr->plen != buf_size - sizeof(struct hci_command_hdr)) {
exit(1);
}
switch (hdr->opcode) {
case HCI_OP_WRITE_SCAN_ENABLE: {
uint8_t status = 0;
hci_send_event_cmd_complete(fd, hdr->opcode, &status, sizeof(status));
return true;
}
case HCI_OP_READ_BD_ADDR: {
struct hci_rp_read_bd_addr rp = {0};
rp.status = 0;
memset(&rp.bdaddr, 0xaa, 6);
hci_send_event_cmd_complete(fd, hdr->opcode, &rp, sizeof(rp));
return false;
}
case HCI_OP_READ_BUFFER_SIZE: {
struct hci_rp_read_buffer_size rp = {0};
rp.status = 0;
rp.acl_mtu = 1021;
rp.sco_mtu = 96;
rp.acl_max_pkt = 4;
rp.sco_max_pkt = 6;
hci_send_event_cmd_complete(fd, hdr->opcode, &rp, sizeof(rp));
return false;
}
}
char dummy[0xf9] = {0};
hci_send_event_cmd_complete(fd, hdr->opcode, dummy, sizeof(dummy));
return false;
}
static void* event_thread(void* arg)
{
while (1) {
char buf[1024] = {0};
ssize_t buf_size = read(vhci_fd, buf, sizeof(buf));
if (buf_size < 0)
exit(1);
if (buf_size > 0 && buf[0] == HCI_COMMAND_PKT) {
if (process_command_pkt(vhci_fd, buf + 1, buf_size - 1))
break;
}
}
return NULL;
}
#define HCI_HANDLE_1 200
#define HCI_HANDLE_2 201
static void initialize_vhci()
{
int hci_sock = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
if (hci_sock < 0)
exit(1);
vhci_fd = open("/dev/vhci", O_RDWR);
if (vhci_fd == -1)
exit(1);
const int kVhciFd = 241;
if (dup2(vhci_fd, kVhciFd) < 0)
exit(1);
close(vhci_fd);
vhci_fd = kVhciFd;
struct vhci_vendor_pkt vendor_pkt;
if (read(vhci_fd, &vendor_pkt, sizeof(vendor_pkt)) != sizeof(vendor_pkt))
exit(1);
if (vendor_pkt.type != HCI_VENDOR_PKT)
exit(1);
pthread_t th;
if (pthread_create(&th, NULL, event_thread, NULL))
exit(1);
int ret = ioctl(hci_sock, HCIDEVUP, vendor_pkt.id);
if (ret) {
if (errno == ERFKILL) {
rfkill_unblock_all();
ret = ioctl(hci_sock, HCIDEVUP, vendor_pkt.id);
}
if (ret && errno != EALREADY)
exit(1);
}
struct hci_dev_req dr = {0};
dr.dev_id = vendor_pkt.id;
dr.dev_opt = SCAN_PAGE;
if (ioctl(hci_sock, HCISETSCAN, &dr))
exit(1);
struct hci_ev_conn_request request;
memset(&request, 0, sizeof(request));
memset(&request.bdaddr, 0xaa, 6);
*(uint8_t*)&request.bdaddr.b[5] = 0x10;
request.link_type = ACL_LINK;
hci_send_event_packet(vhci_fd, HCI_EV_CONN_REQUEST, &request,
sizeof(request));
struct hci_ev_conn_complete complete;
memset(&complete, 0, sizeof(complete));
complete.status = 0;
complete.handle = HCI_HANDLE_1;
memset(&complete.bdaddr, 0xaa, 6);
*(uint8_t*)&complete.bdaddr.b[5] = 0x10;
complete.link_type = ACL_LINK;
complete.encr_mode = 0;
hci_send_event_packet(vhci_fd, HCI_EV_CONN_COMPLETE, &complete,
sizeof(complete));
struct hci_ev_remote_features features;
memset(&features, 0, sizeof(features));
features.status = 0;
features.handle = HCI_HANDLE_1;
hci_send_event_packet(vhci_fd, HCI_EV_REMOTE_FEATURES, &features,
sizeof(features));
struct {
struct hci_ev_le_meta le_meta;
struct hci_ev_le_conn_complete le_conn;
} le_conn;
memset(&le_conn, 0, sizeof(le_conn));
le_conn.le_meta.subevent = HCI_EV_LE_CONN_COMPLETE;
memset(&le_conn.le_conn.bdaddr, 0xaa, 6);
*(uint8_t*)&le_conn.le_conn.bdaddr.b[5] = 0x11;
le_conn.le_conn.role = 1;
le_conn.le_conn.handle = HCI_HANDLE_2;
hci_send_event_packet(vhci_fd, HCI_EV_LE_META, &le_conn, sizeof(le_conn));
pthread_join(th, NULL);
close(hci_sock);
}
#define XT_TABLE_SIZE 1536
#define XT_MAX_ENTRIES 10
struct xt_counters {
uint64_t pcnt, bcnt;
};
struct ipt_getinfo {
char name[32];
unsigned int valid_hooks;
unsigned int hook_entry[5];
unsigned int underflow[5];
unsigned int num_entries;
unsigned int size;
};
struct ipt_get_entries {
char name[32];
unsigned int size;
uint64_t entrytable[XT_TABLE_SIZE / sizeof(uint64_t)];
};
struct ipt_replace {
char name[32];
unsigned int valid_hooks;
unsigned int num_entries;
unsigned int size;
unsigned int hook_entry[5];
unsigned int underflow[5];
unsigned int num_counters;
struct xt_counters* counters;
uint64_t entrytable[XT_TABLE_SIZE / sizeof(uint64_t)];
};
struct ipt_table_desc {
const char* name;
struct ipt_getinfo info;
struct ipt_replace replace;
};
static struct ipt_table_desc ipv4_tables[] = {
{.name = "filter"}, {.name = "nat"}, {.name = "mangle"},
{.name = "raw"}, {.name = "security"},
};
static struct ipt_table_desc ipv6_tables[] = {
{.name = "filter"}, {.name = "nat"}, {.name = "mangle"},
{.name = "raw"}, {.name = "security"},
};
#define IPT_BASE_CTL 64
#define IPT_SO_SET_REPLACE (IPT_BASE_CTL)
#define IPT_SO_GET_INFO (IPT_BASE_CTL)
#define IPT_SO_GET_ENTRIES (IPT_BASE_CTL + 1)
struct arpt_getinfo {
char name[32];
unsigned int valid_hooks;
unsigned int hook_entry[3];
unsigned int underflow[3];
unsigned int num_entries;
unsigned int size;
};
struct arpt_get_entries {
char name[32];
unsigned int size;
uint64_t entrytable[XT_TABLE_SIZE / sizeof(uint64_t)];
};
struct arpt_replace {
char name[32];
unsigned int valid_hooks;
unsigned int num_entries;
unsigned int size;
unsigned int hook_entry[3];
unsigned int underflow[3];
unsigned int num_counters;
struct xt_counters* counters;
uint64_t entrytable[XT_TABLE_SIZE / sizeof(uint64_t)];
};
struct arpt_table_desc {
const char* name;
struct arpt_getinfo info;
struct arpt_replace replace;
};
static struct arpt_table_desc arpt_tables[] = {
{.name = "filter"},
};
#define ARPT_BASE_CTL 96
#define ARPT_SO_SET_REPLACE (ARPT_BASE_CTL)
#define ARPT_SO_GET_INFO (ARPT_BASE_CTL)
#define ARPT_SO_GET_ENTRIES (ARPT_BASE_CTL + 1)
static void checkpoint_iptables(struct ipt_table_desc* tables, int num_tables,
int family, int level)
{
int fd = socket(family, SOCK_STREAM, IPPROTO_TCP);
if (fd == -1) {
switch (errno) {
case EAFNOSUPPORT:
case ENOPROTOOPT:
return;
}
exit(1);
}
for (int i = 0; i < num_tables; i++) {
struct ipt_table_desc* table = &tables[i];
strcpy(table->info.name, table->name);
strcpy(table->replace.name, table->name);
socklen_t optlen = sizeof(table->info);
if (getsockopt(fd, level, IPT_SO_GET_INFO, &table->info, &optlen)) {
switch (errno) {
case EPERM:
case ENOENT:
case ENOPROTOOPT:
continue;
}
exit(1);
}
if (table->info.size > sizeof(table->replace.entrytable))
exit(1);
if (table->info.num_entries > XT_MAX_ENTRIES)
exit(1);
struct ipt_get_entries entries;
memset(&entries, 0, sizeof(entries));
strcpy(entries.name, table->name);
entries.size = table->info.size;
optlen = sizeof(entries) - sizeof(entries.entrytable) + table->info.size;
if (getsockopt(fd, level, IPT_SO_GET_ENTRIES, &entries, &optlen))
exit(1);
table->replace.valid_hooks = table->info.valid_hooks;
table->replace.num_entries = table->info.num_entries;
table->replace.size = table->info.size;
memcpy(table->replace.hook_entry, table->info.hook_entry,
sizeof(table->replace.hook_entry));
memcpy(table->replace.underflow, table->info.underflow,
sizeof(table->replace.underflow));
memcpy(table->replace.entrytable, entries.entrytable, table->info.size);
}
close(fd);
}
static void reset_iptables(struct ipt_table_desc* tables, int num_tables,
int family, int level)
{
int fd = socket(family, SOCK_STREAM, IPPROTO_TCP);
if (fd == -1) {
switch (errno) {
case EAFNOSUPPORT:
case ENOPROTOOPT:
return;
}
exit(1);
}
for (int i = 0; i < num_tables; i++) {
struct ipt_table_desc* table = &tables[i];
if (table->info.valid_hooks == 0)
continue;
struct ipt_getinfo info;
memset(&info, 0, sizeof(info));
strcpy(info.name, table->name);
socklen_t optlen = sizeof(info);
if (getsockopt(fd, level, IPT_SO_GET_INFO, &info, &optlen))
exit(1);
if (memcmp(&table->info, &info, sizeof(table->info)) == 0) {
struct ipt_get_entries entries;
memset(&entries, 0, sizeof(entries));
strcpy(entries.name, table->name);
entries.size = table->info.size;
optlen = sizeof(entries) - sizeof(entries.entrytable) + entries.size;
if (getsockopt(fd, level, IPT_SO_GET_ENTRIES, &entries, &optlen))
exit(1);
if (memcmp(table->replace.entrytable, entries.entrytable,
table->info.size) == 0)
continue;
}
struct xt_counters counters[XT_MAX_ENTRIES];
table->replace.num_counters = info.num_entries;
table->replace.counters = counters;
optlen = sizeof(table->replace) - sizeof(table->replace.entrytable) +
table->replace.size;
if (setsockopt(fd, level, IPT_SO_SET_REPLACE, &table->replace, optlen))
exit(1);
}
close(fd);
}
static void checkpoint_arptables(void)
{
int fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (fd == -1) {
switch (errno) {
case EAFNOSUPPORT:
case ENOPROTOOPT:
return;
}
exit(1);
}
for (unsigned i = 0; i < sizeof(arpt_tables) / sizeof(arpt_tables[0]); i++) {
struct arpt_table_desc* table = &arpt_tables[i];
strcpy(table->info.name, table->name);
strcpy(table->replace.name, table->name);
socklen_t optlen = sizeof(table->info);
if (getsockopt(fd, SOL_IP, ARPT_SO_GET_INFO, &table->info, &optlen)) {
switch (errno) {
case EPERM:
case ENOENT:
case ENOPROTOOPT:
continue;
}
exit(1);
}
if (table->info.size > sizeof(table->replace.entrytable))
exit(1);
if (table->info.num_entries > XT_MAX_ENTRIES)
exit(1);
struct arpt_get_entries entries;
memset(&entries, 0, sizeof(entries));
strcpy(entries.name, table->name);
entries.size = table->info.size;
optlen = sizeof(entries) - sizeof(entries.entrytable) + table->info.size;
if (getsockopt(fd, SOL_IP, ARPT_SO_GET_ENTRIES, &entries, &optlen))
exit(1);
table->replace.valid_hooks = table->info.valid_hooks;
table->replace.num_entries = table->info.num_entries;
table->replace.size = table->info.size;
memcpy(table->replace.hook_entry, table->info.hook_entry,
sizeof(table->replace.hook_entry));
memcpy(table->replace.underflow, table->info.underflow,
sizeof(table->replace.underflow));
memcpy(table->replace.entrytable, entries.entrytable, table->info.size);
}
close(fd);
}
static void reset_arptables()
{
int fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (fd == -1) {
switch (errno) {
case EAFNOSUPPORT:
case ENOPROTOOPT:
return;
}
exit(1);
}
for (unsigned i = 0; i < sizeof(arpt_tables) / sizeof(arpt_tables[0]); i++) {
struct arpt_table_desc* table = &arpt_tables[i];
if (table->info.valid_hooks == 0)
continue;
struct arpt_getinfo info;
memset(&info, 0, sizeof(info));
strcpy(info.name, table->name);
socklen_t optlen = sizeof(info);
if (getsockopt(fd, SOL_IP, ARPT_SO_GET_INFO, &info, &optlen))
exit(1);
if (memcmp(&table->info, &info, sizeof(table->info)) == 0) {
struct arpt_get_entries entries;
memset(&entries, 0, sizeof(entries));
strcpy(entries.name, table->name);
entries.size = table->info.size;
optlen = sizeof(entries) - sizeof(entries.entrytable) + entries.size;
if (getsockopt(fd, SOL_IP, ARPT_SO_GET_ENTRIES, &entries, &optlen))
exit(1);
if (memcmp(table->replace.entrytable, entries.entrytable,
table->info.size) == 0)
continue;
} else {
}
struct xt_counters counters[XT_MAX_ENTRIES];
table->replace.num_counters = info.num_entries;
table->replace.counters = counters;
optlen = sizeof(table->replace) - sizeof(table->replace.entrytable) +
table->replace.size;
if (setsockopt(fd, SOL_IP, ARPT_SO_SET_REPLACE, &table->replace, optlen))
exit(1);
}
close(fd);
}
#define NF_BR_NUMHOOKS 6
#define EBT_TABLE_MAXNAMELEN 32
#define EBT_CHAIN_MAXNAMELEN 32
#define EBT_BASE_CTL 128
#define EBT_SO_SET_ENTRIES (EBT_BASE_CTL)
#define EBT_SO_GET_INFO (EBT_BASE_CTL)
#define EBT_SO_GET_ENTRIES (EBT_SO_GET_INFO + 1)
#define EBT_SO_GET_INIT_INFO (EBT_SO_GET_ENTRIES + 1)
#define EBT_SO_GET_INIT_ENTRIES (EBT_SO_GET_INIT_INFO + 1)
struct ebt_replace {
char name[EBT_TABLE_MAXNAMELEN];
unsigned int valid_hooks;
unsigned int nentries;
unsigned int entries_size;
struct ebt_entries* hook_entry[NF_BR_NUMHOOKS];
unsigned int num_counters;
struct ebt_counter* counters;
char* entries;
};
struct ebt_entries {
unsigned int distinguisher;
char name[EBT_CHAIN_MAXNAMELEN];
unsigned int counter_offset;
int policy;
unsigned int nentries;
char data[0] __attribute__((aligned(__alignof__(struct ebt_replace))));
};
struct ebt_table_desc {
const char* name;
struct ebt_replace replace;
char entrytable[XT_TABLE_SIZE];
};
static struct ebt_table_desc ebt_tables[] = {
{.name = "filter"},
{.name = "nat"},
{.name = "broute"},
};
static void checkpoint_ebtables(void)
{
int fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (fd == -1) {
switch (errno) {
case EAFNOSUPPORT:
case ENOPROTOOPT:
return;
}
exit(1);
}
for (size_t i = 0; i < sizeof(ebt_tables) / sizeof(ebt_tables[0]); i++) {
struct ebt_table_desc* table = &ebt_tables[i];
strcpy(table->replace.name, table->name);
socklen_t optlen = sizeof(table->replace);
if (getsockopt(fd, SOL_IP, EBT_SO_GET_INIT_INFO, &table->replace,
&optlen)) {
switch (errno) {
case EPERM:
case ENOENT:
case ENOPROTOOPT:
continue;
}
exit(1);
}
if (table->replace.entries_size > sizeof(table->entrytable))
exit(1);
table->replace.num_counters = 0;
table->replace.entries = table->entrytable;
optlen = sizeof(table->replace) + table->replace.entries_size;
if (getsockopt(fd, SOL_IP, EBT_SO_GET_INIT_ENTRIES, &table->replace,
&optlen))
exit(1);
}
close(fd);
}
static void reset_ebtables()
{
int fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (fd == -1) {
switch (errno) {
case EAFNOSUPPORT:
case ENOPROTOOPT:
return;
}
exit(1);
}
for (unsigned i = 0; i < sizeof(ebt_tables) / sizeof(ebt_tables[0]); i++) {
struct ebt_table_desc* table = &ebt_tables[i];
if (table->replace.valid_hooks == 0)
continue;
struct ebt_replace replace;
memset(&replace, 0, sizeof(replace));
strcpy(replace.name, table->name);
socklen_t optlen = sizeof(replace);
if (getsockopt(fd, SOL_IP, EBT_SO_GET_INFO, &replace, &optlen))
exit(1);
replace.num_counters = 0;
table->replace.entries = 0;
for (unsigned h = 0; h < NF_BR_NUMHOOKS; h++)
table->replace.hook_entry[h] = 0;
if (memcmp(&table->replace, &replace, sizeof(table->replace)) == 0) {
char entrytable[XT_TABLE_SIZE];
memset(&entrytable, 0, sizeof(entrytable));
replace.entries = entrytable;
optlen = sizeof(replace) + replace.entries_size;
if (getsockopt(fd, SOL_IP, EBT_SO_GET_ENTRIES, &replace, &optlen))
exit(1);
if (memcmp(table->entrytable, entrytable, replace.entries_size) == 0)
continue;
}
for (unsigned j = 0, h = 0; h < NF_BR_NUMHOOKS; h++) {
if (table->replace.valid_hooks & (1 << h)) {
table->replace.hook_entry[h] =
(struct ebt_entries*)table->entrytable + j;
j++;
}
}
table->replace.entries = table->entrytable;
optlen = sizeof(table->replace) + table->replace.entries_size;
if (setsockopt(fd, SOL_IP, EBT_SO_SET_ENTRIES, &table->replace, optlen))
exit(1);
}
close(fd);
}
static void checkpoint_net_namespace(void)
{
checkpoint_ebtables();
checkpoint_arptables();
checkpoint_iptables(ipv4_tables, sizeof(ipv4_tables) / sizeof(ipv4_tables[0]),
AF_INET, SOL_IP);
checkpoint_iptables(ipv6_tables, sizeof(ipv6_tables) / sizeof(ipv6_tables[0]),
AF_INET6, SOL_IPV6);
}
static void reset_net_namespace(void)
{
reset_ebtables();
reset_arptables();
reset_iptables(ipv4_tables, sizeof(ipv4_tables) / sizeof(ipv4_tables[0]),
AF_INET, SOL_IP);
reset_iptables(ipv6_tables, sizeof(ipv6_tables) / sizeof(ipv6_tables[0]),
AF_INET6, SOL_IPV6);
}
static void setup_cgroups()
{
if (mkdir("/syzcgroup", 0777)) {
}
if (mkdir("/syzcgroup/unified", 0777)) {
}
if (mount("none", "/syzcgroup/unified", "cgroup2", 0, NULL)) {
}
if (chmod("/syzcgroup/unified", 0777)) {
}
write_file("/syzcgroup/unified/cgroup.subtree_control",
"+cpu +memory +io +pids +rdma");
if (mkdir("/syzcgroup/cpu", 0777)) {
}
if (mount("none", "/syzcgroup/cpu", "cgroup", 0,
"cpuset,cpuacct,perf_event,hugetlb")) {
}
write_file("/syzcgroup/cpu/cgroup.clone_children", "1");
write_file("/syzcgroup/cpu/cpuset.memory_pressure_enabled", "1");
if (chmod("/syzcgroup/cpu", 0777)) {
}
if (mkdir("/syzcgroup/net", 0777)) {
}
if (mount("none", "/syzcgroup/net", "cgroup", 0,
"net_cls,net_prio,devices,freezer")) {
}
if (chmod("/syzcgroup/net", 0777)) {
}
}
static void setup_cgroups_loop()
{
int pid = getpid();
char file[128];
char cgroupdir[64];
snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/unified/syz%llu", procid);
if (mkdir(cgroupdir, 0777)) {
}
snprintf(file, sizeof(file), "%s/pids.max", cgroupdir);
write_file(file, "32");
snprintf(file, sizeof(file), "%s/memory.low", cgroupdir);
write_file(file, "%d", 298 << 20);
snprintf(file, sizeof(file), "%s/memory.high", cgroupdir);
write_file(file, "%d", 299 << 20);
snprintf(file, sizeof(file), "%s/memory.max", cgroupdir);
write_file(file, "%d", 300 << 20);
snprintf(file, sizeof(file), "%s/cgroup.procs", cgroupdir);
write_file(file, "%d", pid);
snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/cpu/syz%llu", procid);
if (mkdir(cgroupdir, 0777)) {
}
snprintf(file, sizeof(file), "%s/cgroup.procs", cgroupdir);
write_file(file, "%d", pid);
snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/net/syz%llu", procid);
if (mkdir(cgroupdir, 0777)) {
}
snprintf(file, sizeof(file), "%s/cgroup.procs", cgroupdir);
write_file(file, "%d", pid);
}
static void setup_cgroups_test()
{
char cgroupdir[64];
snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/unified/syz%llu", procid);
if (symlink(cgroupdir, "./cgroup")) {
}
snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/cpu/syz%llu", procid);
if (symlink(cgroupdir, "./cgroup.cpu")) {
}
snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/net/syz%llu", procid);
if (symlink(cgroupdir, "./cgroup.net")) {
}
}
static void setup_common()
{
if (mount(0, "/sys/fs/fuse/connections", "fusectl", 0, 0)) {
}
setup_cgroups();
}
static void loop();
static void sandbox_common()
{
prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
setpgrp();
setsid();
struct rlimit rlim;
rlim.rlim_cur = rlim.rlim_max = (200 << 20);
setrlimit(RLIMIT_AS, &rlim);
rlim.rlim_cur = rlim.rlim_max = 32 << 20;
setrlimit(RLIMIT_MEMLOCK, &rlim);
rlim.rlim_cur = rlim.rlim_max = 136 << 20;
setrlimit(RLIMIT_FSIZE, &rlim);
rlim.rlim_cur = rlim.rlim_max = 1 << 20;
setrlimit(RLIMIT_STACK, &rlim);
rlim.rlim_cur = rlim.rlim_max = 0;
setrlimit(RLIMIT_CORE, &rlim);
rlim.rlim_cur = rlim.rlim_max = 256;
setrlimit(RLIMIT_NOFILE, &rlim);
if (unshare(CLONE_NEWNS)) {
}
if (mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL)) {
}
if (unshare(CLONE_NEWIPC)) {
}
if (unshare(0x02000000)) {
}
if (unshare(CLONE_NEWUTS)) {
}
if (unshare(CLONE_SYSVSEM)) {
}
typedef struct {
const char* name;
const char* value;
} sysctl_t;
static const sysctl_t sysctls[] = {
{"/proc/sys/kernel/shmmax", "16777216"},
{"/proc/sys/kernel/shmall", "536870912"},
{"/proc/sys/kernel/shmmni", "1024"},
{"/proc/sys/kernel/msgmax", "8192"},
{"/proc/sys/kernel/msgmni", "1024"},
{"/proc/sys/kernel/msgmnb", "1024"},
{"/proc/sys/kernel/sem", "1024 1048576 500 1024"},
};
unsigned i;
for (i = 0; i < sizeof(sysctls) / sizeof(sysctls[0]); i++)
write_file(sysctls[i].name, sysctls[i].value);
}
static int wait_for_loop(int pid)
{
if (pid < 0)
exit(1);
int status = 0;
while (waitpid(-1, &status, __WALL) != pid) {
}
return WEXITSTATUS(status);
}
static void drop_caps(void)
{
struct __user_cap_header_struct cap_hdr = {};
struct __user_cap_data_struct cap_data[2] = {};
cap_hdr.version = _LINUX_CAPABILITY_VERSION_3;
cap_hdr.pid = getpid();
if (syscall(SYS_capget, &cap_hdr, &cap_data))
exit(1);
const int drop = (1 << CAP_SYS_PTRACE) | (1 << CAP_SYS_NICE);
cap_data[0].effective &= ~drop;
cap_data[0].permitted &= ~drop;
cap_data[0].inheritable &= ~drop;
if (syscall(SYS_capset, &cap_hdr, &cap_data))
exit(1);
}
static int do_sandbox_none(void)
{
if (unshare(CLONE_NEWPID)) {
}
int pid = fork();
if (pid != 0)
return wait_for_loop(pid);
setup_common();
initialize_vhci();
sandbox_common();
drop_caps();
initialize_netdevices_init();
if (unshare(CLONE_NEWNET)) {
}
initialize_tun();
initialize_netdevices();
initialize_wifi_devices();
loop();
exit(1);
}
#define FS_IOC_SETFLAGS _IOW('f', 2, long)
static void remove_dir(const char* dir)
{
int iter = 0;
DIR* dp = 0;
retry:
while (umount2(dir, MNT_DETACH) == 0) {
}
dp = opendir(dir);
if (dp == NULL) {
if (errno == EMFILE) {
exit(1);
}
exit(1);
}
struct dirent* ep = 0;
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);
for (int 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 void kill_and_wait(int pid, int* status)
{
kill(-pid, SIGKILL);
kill(pid, SIGKILL);
for (int 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_loop()
{
setup_cgroups_loop();
checkpoint_net_namespace();
}
static void reset_loop()
{
reset_net_namespace();
}
static void setup_test()
{
prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
setpgrp();
setup_cgroups_test();
write_file("/proc/self/oom_score_adj", "1000");
flush_tun();
}
static void close_fds()
{
for (int fd = 3; fd < MAX_FDS; fd++)
close(fd);
}
static void setup_binfmt_misc()
{
if (mount(0, "/proc/sys/fs/binfmt_misc", "binfmt_misc", 0, 0)) {
}
write_file("/proc/sys/fs/binfmt_misc/register", ":syz0:M:0:\x01::./file0:");
write_file("/proc/sys/fs/binfmt_misc/register",
":syz1:M:1:\x02::./file0:POC");
}
struct thread_t {
int created, call;
event_t ready, done;
};
static struct thread_t threads[16];
static void execute_call(int call);
static int running;
static void* thr(void* arg)
{
struct thread_t* th = (struct thread_t*)arg;
for (;;) {
event_wait(&th->ready);
event_reset(&th->ready);
execute_call(th->call);
__atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED);
event_set(&th->done);
}
return 0;
}
static void execute_one(void)
{
int i, call, thread;
int collide = 0;
again:
for (call = 0; call < 3; call++) {
for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0]));
thread++) {
struct thread_t* th = &threads[thread];
if (!th->created) {
th->created = 1;
event_init(&th->ready);
event_init(&th->done);
event_set(&th->done);
thread_start(thr, th);
}
if (!event_isset(&th->done))
continue;
event_reset(&th->done);
th->call = call;
__atomic_fetch_add(&running, 1, __ATOMIC_RELAXED);
event_set(&th->ready);
if (collide && (call % 2) == 0)
break;
event_timedwait(&th->done, 45);
break;
}
}
for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++)
sleep_ms(1);
close_fds();
if (!collide) {
collide = 1;
goto again;
}
}
static void execute_one(void);
#define WAIT_FLAGS __WALL
static void loop(void)
{
setup_loop();
int iter = 0;
for (;; iter++) {
char cwdbuf[32];
sprintf(cwdbuf, "./%d", iter);
if (mkdir(cwdbuf, 0777))
exit(1);
reset_loop();
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[1] = {0xffffffffffffffff};
void execute_call(int call)
{
intptr_t res = 0;
switch (call) {
case 0:
NONFAILING(memcpy((void*)0x20000140, "/dev/kvm\000", 9));
syscall(__NR_openat, 0xffffffffffffff9cul, 0x20000140ul, 0ul, 0ul);
break;
case 1:
res = syscall(__NR_socket, 0x10ul, 3ul, 6);
if (res != -1)
r[0] = res;
break;
case 2:
NONFAILING(*(uint64_t*)0x20000100 = 0);
NONFAILING(*(uint32_t*)0x20000108 = 0);
NONFAILING(*(uint64_t*)0x20000110 = 0x20000080);
NONFAILING(*(uint64_t*)0x20000080 = 0x200001c0);
NONFAILING(*(uint32_t*)0x200001c0 = 0x144);
NONFAILING(*(uint16_t*)0x200001c4 = 0x10);
NONFAILING(*(uint16_t*)0x200001c6 = 0x501);
NONFAILING(*(uint32_t*)0x200001c8 = 0);
NONFAILING(*(uint32_t*)0x200001cc = 0);
NONFAILING(*(uint8_t*)0x200001d0 = 0xfe);
NONFAILING(*(uint8_t*)0x200001d1 = 0x80);
NONFAILING(*(uint8_t*)0x200001d2 = 0);
NONFAILING(*(uint8_t*)0x200001d3 = 0);
NONFAILING(*(uint8_t*)0x200001d4 = 0);
NONFAILING(*(uint8_t*)0x200001d5 = 0);
NONFAILING(*(uint8_t*)0x200001d6 = 0);
NONFAILING(*(uint8_t*)0x200001d7 = 0);
NONFAILING(*(uint8_t*)0x200001d8 = 0);
NONFAILING(*(uint8_t*)0x200001d9 = 0);
NONFAILING(*(uint8_t*)0x200001da = 0);
NONFAILING(*(uint8_t*)0x200001db = 0);
NONFAILING(*(uint8_t*)0x200001dc = 0);
NONFAILING(*(uint8_t*)0x200001dd = 0);
NONFAILING(*(uint8_t*)0x200001de = 0);
NONFAILING(*(uint8_t*)0x200001df = 0xbb);
NONFAILING(*(uint8_t*)0x200001e0 = 0);
NONFAILING(*(uint8_t*)0x200001e1 = 0);
NONFAILING(*(uint8_t*)0x200001e2 = 0);
NONFAILING(*(uint8_t*)0x200001e3 = 0);
NONFAILING(*(uint8_t*)0x200001e4 = 0);
NONFAILING(*(uint8_t*)0x200001e5 = 0);
NONFAILING(*(uint8_t*)0x200001e6 = 0);
NONFAILING(*(uint8_t*)0x200001e7 = 0);
NONFAILING(*(uint8_t*)0x200001e8 = 0);
NONFAILING(*(uint8_t*)0x200001e9 = 0);
NONFAILING(*(uint8_t*)0x200001ea = 0);
NONFAILING(*(uint8_t*)0x200001eb = 0);
NONFAILING(*(uint8_t*)0x200001ec = 0);
NONFAILING(*(uint8_t*)0x200001ed = 0);
NONFAILING(*(uint8_t*)0x200001ee = 0);
NONFAILING(*(uint8_t*)0x200001ef = 0);
NONFAILING(*(uint16_t*)0x200001f0 = htobe16(0));
NONFAILING(*(uint16_t*)0x200001f2 = htobe16(0));
NONFAILING(*(uint16_t*)0x200001f4 = htobe16(0));
NONFAILING(*(uint16_t*)0x200001f6 = htobe16(0));
NONFAILING(*(uint16_t*)0x200001f8 = 0);
NONFAILING(*(uint8_t*)0x200001fa = 0);
NONFAILING(*(uint8_t*)0x200001fb = 0);
NONFAILING(*(uint8_t*)0x200001fc = 0);
NONFAILING(*(uint32_t*)0x20000200 = 0);
NONFAILING(*(uint32_t*)0x20000204 = 0);
NONFAILING(*(uint8_t*)0x20000208 = 0xac);
NONFAILING(*(uint8_t*)0x20000209 = 0x14);
NONFAILING(*(uint8_t*)0x2000020a = 0x14);
NONFAILING(*(uint8_t*)0x2000020b = 0xaa);
NONFAILING(*(uint32_t*)0x20000218 = htobe32(0));
NONFAILING(*(uint8_t*)0x2000021c = 0x6c);
NONFAILING(*(uint8_t*)0x20000220 = 0xfc);
NONFAILING(*(uint8_t*)0x20000221 = 2);
NONFAILING(*(uint8_t*)0x20000222 = 0);
NONFAILING(*(uint8_t*)0x20000223 = 0);
NONFAILING(*(uint8_t*)0x20000224 = 0);
NONFAILING(*(uint8_t*)0x20000225 = 0);
NONFAILING(*(uint8_t*)0x20000226 = 0);
NONFAILING(*(uint8_t*)0x20000227 = 0);
NONFAILING(*(uint8_t*)0x20000228 = 0);
NONFAILING(*(uint8_t*)0x20000229 = 0);
NONFAILING(*(uint8_t*)0x2000022a = 0);
NONFAILING(*(uint8_t*)0x2000022b = 0);
NONFAILING(*(uint8_t*)0x2000022c = 0);
NONFAILING(*(uint8_t*)0x2000022d = 0);
NONFAILING(*(uint8_t*)0x2000022e = 0);
NONFAILING(*(uint8_t*)0x2000022f = 0);
NONFAILING(*(uint64_t*)0x20000230 = 0);
NONFAILING(*(uint64_t*)0x20000238 = 0);
NONFAILING(*(uint64_t*)0x20000240 = 0);
NONFAILING(*(uint64_t*)0x20000248 = 0);
NONFAILING(*(uint64_t*)0x20000250 = 0);
NONFAILING(*(uint64_t*)0x20000258 = 0);
NONFAILING(*(uint64_t*)0x20000260 = 0);
NONFAILING(*(uint64_t*)0x20000268 = 0);
NONFAILING(*(uint64_t*)0x20000270 = 0);
NONFAILING(*(uint64_t*)0x20000278 = 0);
NONFAILING(*(uint64_t*)0x20000280 = 0);
NONFAILING(*(uint64_t*)0x20000288 = 0);
NONFAILING(*(uint32_t*)0x20000290 = 0);
NONFAILING(*(uint32_t*)0x20000294 = 0);
NONFAILING(*(uint32_t*)0x20000298 = 0);
NONFAILING(*(uint32_t*)0x2000029c = 0);
NONFAILING(*(uint32_t*)0x200002a0 = 0);
NONFAILING(*(uint16_t*)0x200002a4 = 2);
NONFAILING(*(uint8_t*)0x200002a6 = 0);
NONFAILING(*(uint8_t*)0x200002a7 = 0);
NONFAILING(*(uint8_t*)0x200002a8 = 0);
NONFAILING(*(uint16_t*)0x200002b0 = 0x48);
NONFAILING(*(uint16_t*)0x200002b2 = 3);
NONFAILING(
memcpy((void*)0x200002b4,
"deflate\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
"\000\000\000\000\000\000\000\000\000\000\000\000\000",
64));
NONFAILING(*(uint32_t*)0x200002f4 = 0);
NONFAILING(*(uint16_t*)0x200002f8 = 0xc);
NONFAILING(*(uint16_t*)0x200002fa = 0x1c);
NONFAILING(*(uint32_t*)0x200002fc = 0);
NONFAILING(*(uint8_t*)0x20000300 = 0);
NONFAILING(*(uint64_t*)0x20000088 = 0x144);
NONFAILING(*(uint64_t*)0x20000118 = 1);
NONFAILING(*(uint64_t*)0x20000120 = 0);
NONFAILING(*(uint64_t*)0x20000128 = 0);
NONFAILING(*(uint32_t*)0x20000130 = 0);
syscall(__NR_sendmsg, r[0], 0x20000100ul, 0ul);
break;
}
}
int main(void)
{
syscall(__NR_mmap, 0x1ffff000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul);
syscall(__NR_mmap, 0x20000000ul, 0x1000000ul, 7ul, 0x32ul, -1, 0ul);
syscall(__NR_mmap, 0x21000000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul);
setup_binfmt_misc();
install_segv_handler();
for (procid = 0; procid < 6; procid++) {
if (fork() == 0) {
use_temporary_dir();
do_sandbox_none();
}
}
sleep(1000000);
return 0;
}
|
the_stack_data/132952657.c | #include <stdio.h>
main()
{
printf("The value of EOF is :%d",EOF);
//The value of EOF is :-1
}
|
the_stack_data/115628.c | #include <wchar.h>
#include <assert.h>
int main()
{
assert(""[0]==0);
assert("\033\\"[0]==27);
assert("\033\\"[1]=='\\');
assert("\xcZ\\"[0]==12);
assert("\xcZ\\"[1]=='Z');
assert("\""[0]=='"');
assert("\%"[0]=='%');
assert("\n"[0]==10);
// spliced to avoid hex ambiguity
assert("\x5" "five"[0]==0x5);
// spliced accoss multiple lines
const char some_string[]=
"\x5"
#pragma whatnot
"five";
assert(some_string[0]==0x5);
// wide strings
assert(L"abc"[0]=='a');
assert(L"abc"[1]=='b');
assert(L"abc"[3]==0);
assert(L"\x1234"[0]==0x1234);
// spliced wide strings
assert(sizeof(L"1" "2")==sizeof(wchar_t)*3);
// the following is a C11 UTF-8 string literal
const char euro_sign[]=u8"\x20ac";
assert((unsigned char)euro_sign[0]==0xe2);
assert((unsigned char)euro_sign[1]==0x82);
assert((unsigned char)euro_sign[2]==0xac);
assert(euro_sign[3]==0);
assert(sizeof(euro_sign)==4);
// the following is C++ and C99
const wchar_t wide_amount[]=L"\u20AC123,00"; //€123,00
assert(wide_amount[0]==0x20ac);
assert(wide_amount[1]=='1');
// C11 unicode string literals
assert(sizeof(u8""[0])==sizeof(char));
assert(sizeof(u""[0])==2);
assert(sizeof(U""[0])==4);
// generic wide string, OS-dependent
assert(sizeof(L""[0])==sizeof(wchar_t));
}
|
the_stack_data/594104.c |
#if 1
void foobar0 ( int size, int array[*] );
#endif
#if 1
// void foobar1 ( int size, int array[*] );
void foobar1 ( int size, int array[size] )
{
}
#endif
#if 1
// void foobar2 ( int size, int array[size] );
// void foobar2 ( int size, int array[size] );
void foobar2 ( int size, int array[size+1] )
{
}
#endif
#if 1
int global_size = 42;
void foobar3 ( int size, int array[size*12] );
void foobar3 ( int size, int array[size+global_size+42] )
{
}
#endif
|
the_stack_data/59513536.c | // general protection fault in ubifs_mount
// https://syzkaller.appspot.com/bug?id=47292b6ab8e8bd1d10f7339c0bd667f4712a7a64
// status:fixed
// autogenerated by syzkaller (https://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <endian.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
int main(void)
{
syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0);
memcpy((void*)0x20fb6000, "", 1);
memcpy((void*)0x20d78000, ".", 1);
memcpy((void*)0x20000040, "ubifs", 6);
syscall(__NR_mount, 0x20fb6000, 0x20d78000, 0x20000040, 0, 0);
*(uint16_t*)0x200000c0 = 1;
*(uint16_t*)0x200000c2 = 0;
*(uint16_t*)0x200000c4 = 0x17fe;
syscall(__NR_semop, 0, 0x200000c0, 0x2aaaaaaaaaaaae02);
return 0;
}
|
the_stack_data/170451978.c | /*
* convert integer to float
*/
void dvfloa(int n, int *x, int incx, double *y, int incy)
{
while (n--) {
*y = (double) *x;
x += incx;
y += incy;
}
return;
}
void svfloa(int n, int *x, int incx, float *y, int incy)
{
while (n--) {
*y = (float) *x;
x += incx;
y += incy;
}
return;
}
|
the_stack_data/220454934.c | #include <stdio.h>
int a[1000];
int main(){
int t, q;
scanf("%d", &t);
for(q=1;q<=t;q++) {
int n;
scanf("%d", &n);
int i;
for(i=0;i<n;i++)
scanf("%d", a+i);
int maxd = 0;
int ans1 = 0;
for (i=1;i<n;i++){
int d = a[i-1]-a[i];
if (d > maxd)
maxd = d;
if (a[i]<a[i-1])
ans1 += a[i-1]-a[i];
}
int ans2=0;
for (i=0;i<n-1;i++) {
if (a[i] < maxd)
ans2+=a[i];
else
ans2+=maxd;
}
printf("Case #%d: %d %d\n", q, ans1, ans2);
}
}
|
the_stack_data/89201463.c | #include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
static void clup_f1(void *p)
{
printf("clup_f1: %s\n", p);
}
static void *func(void *arg)
{
puts("Thread is working.");
pthread_cleanup_push(clup_f1, "aaa");
pthread_cleanup_push(clup_f1, "bbb");
pthread_cleanup_push(clup_f1, "ccc");
puts("Thread is over.");
// return NULL;
while (1) pause();
pthread_exit(NULL);
pthread_cleanup_pop(0);
pthread_cleanup_pop(0);
pthread_cleanup_pop(0);
}
int
main()
{
pthread_t tid;
int errcode;
puts("Begin.");
errcode = pthread_create(&tid, NULL, func, NULL);
if (errcode) {
fprintf(stderr, "pthread_create(): %s\n", strerror(errcode));
exit(1);
}
puts("OK.");
sleep(5);
pthread_cancel(tid);
pthread_join(tid, NULL);
return 0;
}
|
the_stack_data/34512515.c | /**
561. Array Partition I [E]
Ref: https://leetcode.com/problems/array-partition-i/
Given an array of 2n integers, your task is to group these integers into
n pairs of integer, say (a1, b1), (a2, b2), ..., (an, bn) which makes
sum of min(ai, bi) for all i from 1 to n as large as possible.
Example 1:
Input: [1,4,3,2]
Output: 4
Explanation: n is 2, and the maximum sum of pairs is 4 = min(1, 2) + min(3, 4).
Note:
n is a positive integer, which is in the range of [1, 10000].
All the integers in the array will be in the range of [-10000, 10000].
*/
int compare(const void *a, const void *b)
{
int *n1 = (int *)a;
int *n2 = (int *)b;
return (*n1-*n2);
}
int arrayPairSum(int* nums, int numsSize)
{
qsort(nums, numsSize, sizeof(int), compare);
int sum = 0;
int head = 0;
int tail = numsSize-2;
while (head <= tail)
{
/* Head and tail at the same location */
if (head == tail)
{
sum += nums[head];
break;
}
sum = sum + nums[head] + nums[tail];
head += 2;
tail -= 2;
}
return sum;
}
|
the_stack_data/14628.c | #ifndef lint
#ifndef NOID
static char elsieid[] = "@(#)logwtmp.c 7.7";
/* As received from UCB, with include reordering and OLD_TIME condition. */
#endif /* !defined NOID */
#endif /* !defined lint */
/*
* Copyright (c) 1988 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANT[A]BILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef lint
#ifdef LIBC_SCCS
static char sccsid[] = "@(#)logwtmp.c 5.2 (Berkeley) 9/20/88";
#endif /* defined LIBC_SCCS */
#endif /* !defined lint */
#include <sys/types.h>
#include <time.h>
#include <utmp.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#ifdef OLD_TIME
char dummy_to_keep_linker_happy;
#endif /* defined OLD_TIME */
#ifndef OLD_TIME
#include <sys/file.h>
#include <sys/time.h>
#include <sys/stat.h>
#define WTMPFILE "/usr/adm/wtmp"
void logwtmp( char *line, char *name, char *host)
{
struct utmp ut;
struct stat buf;
int fd;
if ((fd = open(WTMPFILE, O_WRONLY|O_APPEND, 0)) < 0)
return;
if (!fstat(fd, &buf)) {
(void)strncpy(ut.ut_line, line, sizeof(ut.ut_line));
(void)strncpy(ut.ut_name, name, sizeof(ut.ut_name));
(void)strncpy(ut.ut_host, host, sizeof(ut.ut_host));
(void)time(&ut.ut_time);
if (write(fd, (char *)&ut, sizeof(struct utmp)) !=
sizeof(struct utmp))
(void)ftruncate(fd, buf.st_size);
}
(void)close(fd);
}
#endif /* !defined OLD_TIME */
|
the_stack_data/1183686.c | /* Expect error message when shutting down a device that has never been
initialized. */
/* { dg-do run } */
#include <stdio.h>
#include <openacc.h>
int
main (int argc, char **argv)
{
fprintf (stderr, "CheCKpOInT\n");
acc_shutdown (acc_device_default);
return 0;
}
/* { dg-output "CheCKpOInT(\n|\r\n|\r).*" } */
/* { dg-output "no device initialized" } */
/* { dg-shouldfail "" } */
|
the_stack_data/192330677.c | #include<stdio.h>
int secmax,secpos;
int maxpos(int n,int *a)
{
int i,max=0,pos=0;
secmax=secpos=-1;
for(i=0;i<n;i++)
{
if(a[i]>max)
{
max=a[i];
secpos=pos;
pos=i;
}
}
return pos;
}
void fun()
{
int n,i,flag=0;
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++) scanf("%d",a+i);
i=0;
while(n>0)
{
n=maxpos(n,a);
if(n!=0)
{
n=secpos;
}
else
{
i++;
break;
}
i+=2;
}
if(i&1) printf("BOB\n");
else printf("ANDY\n");
}
int main(int argc, char const *argv[]) {
int n;
scanf("%d",&n);
while(n--) fun();
return 0;
}
|
the_stack_data/145451736.c | const unsigned char Pods_TodayWidgetVersionString[] __attribute__ ((used)) = "@(#)PROGRAM:Pods_TodayWidget PROJECT:Pods-1" "\n"; const double Pods_TodayWidgetVersionNumber __attribute__ ((used)) = (double)1.;
|
the_stack_data/223938.c | #include<stdio.h>
int main()
{
char operator;
double n1,n2;
printf("Enter an operator(+,-,*,/):");
scanf("%c",&operator);
printf("\n Enter two operands:");
scanf("%lf %lf", &n1,&n2);
switch(operator)
{
case '+':
printf("%.1lf+%.1lf=%.1lf",n1,n2,n1+n2);
break;
case '-':
printf("%.1lf-%.1lf=%.1lf",n1,n2,n1-n2);
break;
case '*':
printf("%.1lf*%.1lf=%.1lf",n1,n2,n1*n2);
break;
case '/':
printf("%.1lf/%.1lf=%.1lf",n1,n2,n1/n2);
break;
default:
printf("Error! operator is not correct");
}
return 0;
}
|
the_stack_data/83860.c | /* Copyright 2011-2021 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
void solibfunction(void)
{
}
|
the_stack_data/162642593.c | #include <stdio.h>
#include <stdlib.h>
void print_nums(int *nums, int size)
{
if (size < 1) {
printf("[]");
return;
}
int i;
printf("[%d", nums[0]);
for (i = 1; i < size; i++) {
printf(", %d", nums[i]);
}
printf("]");
}
int *gray_code(int n, int *return_size)
{
if (n < 0) {
return NULL;
}
int i, count = 1 << n;
int *codes = malloc(count * sizeof(int));
for (i = 0; i < count; i++) {
codes[i] = (i >> 1) ^ i;
}
*return_size = count;
return codes;
}
int main(int argc, char **argv)
{
int inputs[] = { 2, 0 };
int i, return_size, len = sizeof(inputs) / sizeof(int);
for (i = 0; i < len; i++) {
int n = inputs[i];
printf("\n Input: %d\n", n);
int *codes = gray_code(n, &return_size);
printf(" Output: ");
print_nums(codes, return_size);
printf("\n");
free(codes);
}
return EXIT_SUCCESS;
}
|
the_stack_data/92327679.c | #include <stdio.h>
int square(const int i)
{
return i * i;
}
int main(void)
{
int x;
scanf("%d", &x);
printf("Square of %d is %d\n", x, square(x));
return 0;
}
|
the_stack_data/51701127.c | /*
* Test program for trace action commands
*/
static char gdb_char_test;
static short gdb_short_test;
static long gdb_long_test;
static char gdb_arr_test[25];
static struct GDB_STRUCT_TEST
{
char c;
short s;
long l;
int bfield : 11; /* collect bitfield */
char arr[25];
struct GDB_STRUCT_TEST *next;
} gdb_struct1_test, gdb_struct2_test, *gdb_structp_test, **gdb_structpp_test;
static union GDB_UNION_TEST
{
char c;
short s;
long l;
int bfield : 11; /* collect bitfield */
char arr[4];
union GDB_UNION_TEST *next;
} gdb_union1_test;
void gdb_recursion_test (int, int, int, int, int, int, int);
void gdb_recursion_test (int depth,
int q1,
int q2,
int q3,
int q4,
int q5,
int q6)
{ /* gdb_recursion_test line 0 */
int q = q1; /* gdbtestline 1 */
q1 = q2; /* gdbtestline 2 */
q2 = q3; /* gdbtestline 3 */
q3 = q4; /* gdbtestline 4 */
q4 = q5; /* gdbtestline 5 */
q5 = q6; /* gdbtestline 6 */
q6 = q; /* gdbtestline 7 */
if (depth--) /* gdbtestline 8 */
gdb_recursion_test (depth, q1, q2, q3, q4, q5, q6); /* gdbtestline 9 */
}
unsigned long gdb_c_test( unsigned long *parm )
{
char *p = "gdb_c_test";
char *ridiculously_long_variable_name_with_equally_long_string_assignment;
register long local_reg = 7;
static unsigned long local_static, local_static_sizeof;
long local_long;
unsigned long *stack_ptr;
unsigned long end_of_stack;
ridiculously_long_variable_name_with_equally_long_string_assignment =
"ridiculously long variable name with equally long string assignment";
local_static = 9;
local_static_sizeof = sizeof (struct GDB_STRUCT_TEST);
local_long = local_reg + 1;
stack_ptr = (unsigned long *) &local_long;
end_of_stack =
(unsigned long) &stack_ptr + sizeof(stack_ptr) + sizeof(end_of_stack) - 1;
gdb_char_test = gdb_struct1_test.c = (char) ((long) parm[1] & 0xff);
gdb_short_test = gdb_struct1_test.s = (short) ((long) parm[2] & 0xffff);
gdb_long_test = gdb_struct1_test.l = (long) ((long) parm[3] & 0xffffffff);
gdb_union1_test.l = (long) parm[4];
gdb_arr_test[0] = gdb_struct1_test.arr[0] = (char) ((long) parm[1] & 0xff);
gdb_arr_test[1] = gdb_struct1_test.arr[1] = (char) ((long) parm[2] & 0xff);
gdb_arr_test[2] = gdb_struct1_test.arr[2] = (char) ((long) parm[3] & 0xff);
gdb_arr_test[3] = gdb_struct1_test.arr[3] = (char) ((long) parm[4] & 0xff);
gdb_arr_test[4] = gdb_struct1_test.arr[4] = (char) ((long) parm[5] & 0xff);
gdb_arr_test[5] = gdb_struct1_test.arr[5] = (char) ((long) parm[6] & 0xff);
gdb_struct1_test.bfield = 144;
gdb_struct1_test.next = &gdb_struct2_test;
gdb_structp_test = &gdb_struct1_test;
gdb_structpp_test = &gdb_structp_test;
gdb_recursion_test (3, (long) parm[1], (long) parm[2], (long) parm[3],
(long) parm[4], (long) parm[5], (long) parm[6]);
gdb_char_test = gdb_short_test = gdb_long_test = 0;
gdb_structp_test = (void *) 0;
gdb_structpp_test = (void *) 0;
memset ((char *) &gdb_struct1_test, 0, sizeof (gdb_struct1_test));
memset ((char *) &gdb_struct2_test, 0, sizeof (gdb_struct2_test));
local_static_sizeof = 0;
local_static = 0;
return ( (unsigned long) 0 );
}
static void gdb_asm_test (void)
{
}
static void begin () /* called before anything else */
{
}
static void end () /* called after everything else */
{
}
int
main (argc, argv, envp)
int argc;
char *argv[], **envp;
{
int i;
unsigned long myparms[10];
#ifdef usestubs
set_debug_traps ();
breakpoint ();
#endif
begin ();
for (i = 0; i < sizeof (myparms) / sizeof (myparms[0]); i++)
myparms[i] = i;
gdb_c_test (&myparms[0]);
end ();
return 0;
}
|
the_stack_data/124593.c |
/*
* Copyright (C) ychen
* Copyright (C) Jiuzhou, Inc.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#include <sys/un.h>
#define UNIX_DOMAIN "/tmp/UNIX.domain"
int main(void)
{
int lsn_fd, apt_fd;
int i, ret;
struct sockaddr_un srv_addr;
struct sockaddr_un clt_addr;
socklen_t clt_len;
char recv_buf[1024];
char send_buf[1024]; //create socket to bind local IP and PORT
lsn_fd = socket(PF_UNIX, SOCK_STREAM, 0);
if(lsn_fd < 0)
{
perror("can't create communication socket!");
return 1;
}
//create local IP and PORT
srv_addr.sun_family = AF_UNIX;
strncpy(srv_addr.sun_path, UNIX_DOMAIN, sizeof(srv_addr.sun_path) - 1);
unlink(UNIX_DOMAIN);
//bind sockfd and sockaddr
ret = bind(lsn_fd, (struct sockaddr*)&srv_addr, sizeof(srv_addr));
if(ret == -1)
{
perror("can't bind local sockaddr!");
close(lsn_fd); unlink(UNIX_DOMAIN);
return 1;
}
//listen lsn_fd, try listen 1
ret = listen(lsn_fd, 1);if(ret == -1)
{
perror("can't listen client connect request");
close(lsn_fd);
unlink(UNIX_DOMAIN);
return 1;
}
clt_len = sizeof(clt_addr);
while(1)
{
apt_fd = accept(lsn_fd, (struct sockaddr*)&clt_addr, &clt_len);
if(apt_fd < 0)
{
perror("can't listen client connect request");
close(lsn_fd);
unlink(UNIX_DOMAIN);
return 1;
}
printf("received a connection\n");
printf("send message to client\n");
memset(send_buf, 0, 1024);
strcpy(send_buf, "Hello, you have connected to server succeed");
int snd_num = write(apt_fd, send_buf, 1024);
if(snd_num != 1024)
{
perror("send messge to client failed\n");
close(apt_fd);
close(lsn_fd);
unlink(UNIX_DOMAIN);
return 1;
} //read and printf client info
printf("============info=================\n");
for(i = 0; i < 4; i++)
{
memset(recv_buf, 0, 1024);
int rcv_num = read(apt_fd, recv_buf, sizeof(recv_buf));
printf("Message from client (%d) :%s\n", rcv_num, recv_buf);
}
}
close(apt_fd);
close(lsn_fd);
unlink(UNIX_DOMAIN);
return 0;
}
|
the_stack_data/107952819.c | #include <stdio.h>
#include <assert.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <sys/stat.h>
static uint32_t checksum(const uint8_t *src, int size)
{
uint32_t sum = 0;
int i;
for( i = 0; i < size; i++ ) {
sum += *src++;
}
return sum;
}
int main( int argc, char **argv)
{
if( argc < 3 ) {
fprintf(stderr, "chk <infile.bin> <outfile.bin>\n");
return 1;
}
struct stat st;
stat(argv[1], &st);
uint32_t src_size = st.st_size;
FILE *src = fopen(argv[1], "rb");
printf("infile: %s size %d\n", argv[1], src_size);
if( !src ) {
fprintf(stderr, "cannot open infile!\n");
exit(1);
}
if( !src_size > 262144 ) {
fprintf(stderr, "file too big!\n");
exit(1);
}
// file must be at least 65k
uint32_t out_size = src_size > 65536 ? src_size : 65536;
uint8_t data[262144];
memset(data, 0, out_size );
fread(data, src_size , 1, src);
uint32_t chk = checksum(data, out_size);
uint32_t cafe = 0xEFACEFAC;
uint32_t null = 0x0;
printf("checksum: %08X\n", chk );
fclose(src);
FILE *dst = fopen(argv[2], "wb");
if( !dst ) {
fprintf(stderr, "cannot open outfile!\n");
exit(1);
}
printf("outfile: %s size %d\n", argv[2], out_size);
fwrite(&out_size, 4, 1, dst);
fwrite(&chk, 4, 1, dst);
fwrite(&cafe, 4, 1, dst);
fwrite(&null, 4, 1, dst);
fwrite(data, out_size, 1, dst);
fclose(dst);
return 0;
}
|
the_stack_data/90762305.c | #include <stdio.h>
void duck_print_array(void* addr){
float *ptr=addr;
int i=0;
for(i=0;i<8;i++){
printf("######=%f\n",*ptr);
ptr++;
}
}
void* duck_malloc(size_t n){
void* ptr=malloc(n);
return ptr;
}
void duck_free(void* ptr){
if(ptr!=NULL){
free(ptr);
}
}
void duck_print_value(void* ptr){
}
|
the_stack_data/81533.c | #define _OP(a,b) a##b
#define OP(a,b) _OP(a,b)
#define TYPE int
#define SUFF i
TYPE OP(ref,SUFF)(TYPE *ptr, int index)
{
return *(ptr+index);
}
TYPE OP(add,SUFF)(TYPE lhs, TYPE rhs0, TYPE rhs1)
{
return lhs=rhs0+rhs1;
}
TYPE OP(addr,SUFF)(TYPE lhs, TYPE *rhs)
{
return lhs=lhs+*rhs;
}
TYPE OP(sub,SUFF)(TYPE lhs, TYPE rhs)
{
return lhs=lhs-rhs;
}
TYPE OP(subr,SUFF)(TYPE lhs, TYPE *rhs)
{
return lhs=lhs-*rhs;
}
TYPE OP(lshift,SUFF)(TYPE lhs, TYPE rhs)
{
return lhs=lhs<<rhs;
}
TYPE OP(rshift,SUFF)(TYPE lhs, TYPE rhs)
{
return lhs=lhs>>rhs;
}
TYPE OP(prshift,SUFF)(TYPE *lhs, TYPE rhs)
{
return *lhs=*lhs>>rhs;
}
TYPE OP(mul,SUFF)(TYPE lhs, TYPE rhs)
{
return lhs=lhs*rhs;
}
TYPE OP(div,SUFF)(TYPE lhs, TYPE rhs)
{
return lhs=lhs/rhs;
}
TYPE OP(mulr,SUFF)(TYPE lhs, TYPE *rhs)
{
return lhs=lhs**rhs;
}
TYPE OP(set,SUFF)(TYPE lhs, TYPE rhs)
{
return lhs=rhs;
}
TYPE OP(pset,SUFF)(TYPE *lhs, TYPE rhs)
{
return *lhs=rhs;
}
TYPE OP(setp,SUFF)(TYPE lhs, TYPE *rhs)
{
return lhs=*rhs;
}
TYPE OP(psetp,SUFF)(TYPE *lhs, TYPE *rhs)
{
return *lhs=*rhs;
}
TYPE* OP(padd,SUFF)(TYPE *lhs, TYPE *rhs, int val)
{
return lhs=rhs+val;
}
TYPE* OP(psub,SUFF)(TYPE *lhs, int rhs)
{
return lhs=lhs-rhs;
}
|
the_stack_data/242329950.c | #include <stdio.h>
int main() {
int x;
x = 10;
int y = x / 2;
printf("x is: %i\ny is: %i\n",x,y);
return 0;
}
|
the_stack_data/640601.c | #include<stdio.h>
#include<stdlib.h>
/*Modify program for different values of size and NT based on your machine configuration- cpu cores and memory size */
#define size 10000
#define NT 8
int arr[size];
int flag[size];//to set flag[i]==1 if arr[i] is maximum
int main(int argc, char *argv[]){
srand(atoi(argv[1]));//Seed for random number command line integer value
//generates random number
for(int i=0;i<size;i++) arr[i]=rand()%1048576;
//initialize flag[i]=1 for 0<=i<=size
for(int i=0;i<size;i++) flag[i]=1;
#pragma omp parallel for num_threads(NT)
for(int i=0;i<size;i++)
for(int j=0;j<size;j++)
//if arr[i] is not maximum set flag[i]=0
if(arr[i]<arr[j])flag[i]=0;
//print maximum element arr[i] for which flag[i] still 1.
for(int i=0;i<size;i++)if(flag[i]==1)printf("arr[%d]= %d\n",i,arr[i]);
}
/*Run executable-path <integer-seed-value>
*example:
./a.out 3 */
|
the_stack_data/115766113.c | #include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#define N (1024)
double a[N][N];
double b[N][N];
double c[N][N];
int main()
{
int k, i, j, ii, jj;
double somma;
float time1, time2, ttime1, ttime2, dub_time;
ttime1 = clock();
time1 = clock();
for (j = 0; j < N; j++)
{
for (i = 0; i < N; i++)
{
a[j][i] = ((double)rand())/((double)RAND_MAX);
b[j][i] = ((double)rand())/((double)RAND_MAX);
c[j][i] = 0.0L;
}
}
time2 = clock();
dub_time = (time2 - time1)/(double) CLOCKS_PER_SEC;
printf("Time to initialize %f s.\n", dub_time);
time1 = clock();
for (i=0; i<N; i++)
{
for (k=0; k<N; k++)
{
for (j=0; j<N; j +=8)
{
c[i][j] = c[i][j] + a[i][k] * b[k][j];
c[i][j+1] = c[i][j+1] + a[i][k] * b[k][j+1];
c[i][j+2] = c[i][j+2] + a[i][k] * b[k][j+2];
c[i][j+3] = c[i][j+3] + a[i][k] * b[k][j+3];
c[i][j+4] = c[i][j+4] + a[i][k] * b[k][j+4];
c[i][j+5] = c[i][j+5] + a[i][k] * b[k][j+5];
c[i][j+6] = c[i][j+6] + a[i][k] * b[k][j+6];
c[i][j+7] = c[i][j+7] + a[i][k] * b[k][j+7];
}
}
}
time2 = clock();
dub_time = (time2 - time1)/(double) CLOCKS_PER_SEC;
printf("Time %f s.\n", dub_time);
ttime2 = clock();
dub_time = (ttime2 - ttime1)/(double) CLOCKS_PER_SEC;
printf("Total timee %f s.\n\n", dub_time);
printf("Mflops ----------------> %f \n",
2.0*N*N*N/(1000*1000*dub_time));
somma = 0.0L;
for (i = 0; i < N; i++)
for (j = 0; j < N; j++)
somma = somma + c[i][j];
printf("Check -------------> %f \n", somma);
return EXIT_SUCCESS;
}
|
the_stack_data/509426.c | // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE.md file.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/wait.h>
FILE* fopen$UNIX2003(const char* filename, const char* mode) {
return fopen(filename, mode);
}
size_t fwrite$UNIX2003(const void* a, size_t b, size_t c, FILE* d) {
return fwrite(a, b, c, d);
}
int fputs$UNIX2003(const char* restrict str, FILE* restrict stream) {
return fputs(str, stream);
}
pid_t waitpid$UNIX2003(pid_t pid, int* status, int options) {
return waitpid(pid, status, options);
}
char* strerror$UNIX2003(int errnum) {
return strerror(errnum);
}
|
the_stack_data/122015531.c | #include <stdio.h>
#include<stdlib.h>
struct tree
{
int data;
struct tree *left;
struct tree *right;
};
int c;
struct tree *root=NULL;
void insert(struct tree *t,int key)
{
struct tree *r=NULL;
while(t)
{
r=t;
if(key==t->data)
return;
if(key>t->data)
t=t->right;
else
t=t->left;
}
struct tree *p=( struct tree *)malloc(sizeof( struct tree));
p->data=key;
p->left=p->right=NULL;
if(p->data>r->data)
r->right=p;
else
r->left=p;
}
void create(int n)
{
int x;
for(int i=0;i<n;i++)
{
printf("\nEnter Data of Node %d : ",i+1);
scanf("%d",&x);
insert(root,x);
}
printf("\n");
}
void inorder(struct tree *t)
{
if(t)
{
inorder(t->left);
printf("%d ",t->data);
inorder(t->right);
}
}
struct tree *nMaximum(struct tree *t)
{
while(t->right)
t=t->right;
return t;
}
struct tree *delete(struct tree *t,int key)
{
struct tree *temp;
if(!t)
return t;
if(key<t->data)
t->left=delete(t->left,key);
else if(key>t->data)
t->right=delete(t->right,key);
else
{
if(t->left==NULL)
{
temp=t->right;
free(t);
return temp;
}
else if(t->right==NULL)
{
temp=t->left;
free(t);
return temp;
}
temp=nMaximum(t->left);
t->data=temp->data;
t->left=delete(t->left,temp->data);
}
return t;
}
int search(struct tree *t)
{
printf("\n Enter element to be Searched : ");
int x;
scanf("%d",&x);
if(!t)
return 0;
while(t)
{
if(x==t->data)
return 1;
else if(x<t->data)
t=t->left;
else
t=t->right;
}
return 0;
}
int main()
{
int n;
root=( struct tree *)malloc(sizeof( struct tree ));
printf("Enter Root Node Data : ");
scanf("%d",&root->data);
root->left=root->right=NULL;
printf("\nEnter No Of Nodes In BST: ");
scanf("%d",&n);
create(n);
inorder(root);
printf("\n");
if(search(root))
printf("\nElement is present in BST ! \n");
else
printf("\nElement is not present in BST ! \n");
printf("Enter element for deletion: ");
int a;
scanf("%d",&a);
delete(root,a);
inorder(root);
return 0;
}
|
the_stack_data/211080265.c | #include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#define SIZE 100
int num_threads;
int *array;
int *thread_result;
void *sum(void *arg) {
int id = *(int*)arg;
int nums_to_sum = SIZE / num_threads;
int start = nums_to_sum * id;
int end = start + nums_to_sum;
if (id == num_threads - 1) {
end = SIZE;
}
int sum = 0;
for (int i = start; i < end; i++) {
sum += array[i];
}
thread_result[id] = sum;
printf("Hilo %i ha terminado con resultado: %i\n", id, sum);
pthread_exit(0);
}
int main(int argc, char **argv) {
if (argc != 2) {
printf("Dame el numero de hilos\n");
exit(-1);
}
num_threads = atoi(argv[1]);
array = malloc(sizeof(int) * SIZE);
thread_result = malloc(sizeof(int) * num_threads);
for (int i = 0; i < SIZE; i++) {
array[i] = i + 1;
}
pthread_t threads[num_threads];
int thread_ids[num_threads];
int total = 0;
for (int i = 0; i < num_threads; i++) {
thread_ids[i] = i;
pthread_create(&threads[i], NULL, sum, (void*)&thread_ids[i]);
}
for (int i = 0; i < num_threads; i++) {
pthread_join(threads[i], NULL);
total += thread_result[i];
}
printf("Total = %i\n", total);
free(array);
free(thread_result);
}
|
the_stack_data/61075.c | /* char.c -- 统计字符个数 */
#include <stdio.h>
int main(void)
{
char ch;
int count = 0;
while ((ch = getchar()) != EOF) {
count++;
putchar(ch);
}
printf("count is %d\n", count);
printf("\n---------------------------------------------\n");
return 0;
} |
the_stack_data/46733.c | #include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>
/*
ADVANCED DATA STRUCTURE & ALGORITHM
ASSIGNMENT -6
SIDDHARTH PANDEY
S20190010163
*/
// use gcc file.c -lm for compilation due to inclusion of math library
int coin_denomination(int number_of_coins[], int z, int value)
{
int i, j, k;
int a[value + 1];
a[0] = 0;
for (i = 1; i <= value; i++)
{
a[i] = INT_MAX;
}
for (int k = 1; k <= value; k++)
{
for (int j = 0; j < z; j++)
if (number_of_coins[j] <= k)
{
int x = a[k - number_of_coins[j]];
if (x != INT_MAX && x + 1 < a[k])
a[k] = x + 1;
}
}
return a[value];
}
void print_the_path(int a[], int k)
{
if (k == 0)
{
return;
}
print_the_path(a, a[k]);
printf("%d ", k);
}
int planner(int a[], int n)
{
int op[n], i, j, k;
op[0] = 0;
op[1] = 0;
int penalty[n];
penalty[0] = 0;
penalty[1] = pow(200 - a[1], 2);
for (i = 2; i < n; i++)
{
op[i] = -1;
penalty[i] = -1;
}
for (i = 2; i <= n - 1; i++)
{
for (j = 0; j < i; j++)
{
int x = (int)(penalty[j] + pow(200 - (a[i] - a[j]), 2));
if (penalty[i] == -1 || x < penalty[i])
{
penalty[i] = x;
op[i] = j;
}
}
}
for (k = 0; k < n; k++)
{
printf("Hotel: %d, penalty: %d, path : ", a[k], penalty[k]);
print_the_path(op, k);
printf("\n");
}
}
int main()
{
FILE *file;
char string[100];
printf("Enter the name of the file \n");
scanf("%s", string);
file = fopen(string, "r");
int n;
fscanf(file, "%d", &n);
int a[n];
for (int j = 0; j < n; j++)
{
fscanf(file, "%d", &a[j]);
}
int r, p;
time_t t1, t2;
fscanf(file, "%d", &p);
for (int k = 0; k < p; k++)
{
fscanf(file, "%d", &r);
t1 = clock();
printf("Minimum Coin Required is %d\n", coin_denomination(a, n, r));
t2 = clock();
printf("Running time: %f seconds \n", (double)(t2 - t1) / CLOCKS_PER_SEC);
}
fclose(file);
FILE *file1;
char string1[100];
printf("Enter the name of the file \n");
scanf("%s", string1);
file1 = fopen(string1, "r");
int n1;
fscanf(file, "%d", &n1);
int b[n1];
for (int j = 0; j < n1; j++)
{
fscanf(file1, "%d", &b[j]);
}
printf("%d", planner(b, n1));
printf("\n");
fclose(file1);
return 0;
}
// File Input-1
/*
4
1 5 6 9
4
11
3
4
6
*/
// File Input-2
/*
6
10
20
35
60
78
90
*/
// Sample Output File
/*
Enter the name of the file
a6.txt
Minimum Coin Required is 2
Running time: 0.000048 seconds
Minimum Coin Required is 3
Running time: 0.000009 seconds
Minimum Coin Required is 4
Running time: 0.000012 seconds
Minimum Coin Required is 1
Running time: 0.000012 seconds
Enter the name of the file
a.txt
Hotel: 10, penalty: 0, path :
Hotel: 20, penalty: 32400, path : 1
Hotel: 35, penalty: 30625, path : 2
Hotel: 60, penalty: 22500, path : 3
Hotel: 78, penalty: 17424, path : 4
Hotel: 90, penalty: 14400, path : 5
6
*/ |
the_stack_data/187643214.c | /*
DickSort Developed by Alexandro 2020
*/
#include <stdio.h>
#include <stdlib.h>
/* Swap Values case Array[i] > Array[i+1] */
void Swap(int *V, int s){
int i, aux;
for(i = 0; i < s-1; i++) {
if(*(V+i) > *(V+i+1)){
aux = *(V+i);
*(V+i) = *(V+i+1);
*(V+i+1) = aux;
}
}
}
/* Verify if Array[i] > Array[i+1] and return stop value to Sort function */
int Verify(int *V, int s){
while(--s >= 1){
if(*(V+s) < *(V+s-1))
return 0;
}
return 1;
}
/* Recursive, if Verify Still false, Swap values */
int Sort(int *V, int s){
if(Verify(V, s) != 1){
Swap(V, s);
Sort(V, s);
}
}
int main(){
int i, *V, s = 50;
V = malloc(s* sizeof(int));
for(i = 0; i < s; i++){
*(V+i) = rand()%100;
}
printf("Unordered:\n");
for(i = 0; i < s; i++)
printf("%d ", *(V+i));
Sort(V, s);/* 50 is Array size */
printf("\nOrdered:\n");
for(i = 0; i < s; i++)
printf("%d ", *(V+i));
}
|
the_stack_data/329796.c |
#include <stdio.h>
void scilab_rt_contour_i2d2i2i0d0d0s0i2d2d0_(int in00, int in01, int matrixin0[in00][in01],
int in10, int in11, double matrixin1[in10][in11],
int in20, int in21, int matrixin2[in20][in21],
int scalarin0,
double scalarin1,
double scalarin2,
char* scalarin3,
int in30, int in31, int matrixin3[in30][in31],
int in40, int in41, double matrixin4[in40][in41],
double scalarin4)
{
int i;
int j;
int val0 = 0;
double val1 = 0;
int val2 = 0;
int val3 = 0;
double val4 = 0;
for (i = 0; i < in00; ++i) {
for (j = 0; j < in01; ++j) {
val0 += matrixin0[i][j];
}
}
printf("%d", val0);
for (i = 0; i < in10; ++i) {
for (j = 0; j < in11; ++j) {
val1 += matrixin1[i][j];
}
}
printf("%f", val1);
for (i = 0; i < in20; ++i) {
for (j = 0; j < in21; ++j) {
val2 += matrixin2[i][j];
}
}
printf("%d", val2);
printf("%d", scalarin0);
printf("%f", scalarin1);
printf("%f", scalarin2);
printf("%s", scalarin3);
for (i = 0; i < in30; ++i) {
for (j = 0; j < in31; ++j) {
val3 += matrixin3[i][j];
}
}
printf("%d", val3);
for (i = 0; i < in40; ++i) {
for (j = 0; j < in41; ++j) {
val4 += matrixin4[i][j];
}
}
printf("%f", val4);
printf("%f", scalarin4);
}
|
the_stack_data/154831329.c |
/*--------------------------------------------------------------------*/
/*--- Handlers for syscalls on minor variants of Linux kernels. ---*/
/*--- syswrap-linux-variants.c ---*/
/*--------------------------------------------------------------------*/
/*
This file is part of Valgrind, a dynamic binary instrumentation
framework.
Copyright (C) 2000-2015 Julian Seward
[email protected]
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; 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.
The GNU General Public License is contained in the file COPYING.
*/
#if defined(VGO_linux)
/* The files syswrap-generic.c, syswrap-linux.c, syswrap-*-linux.c,
and associated vki*.h header files, constitute Valgrind's model of how a
vanilla Linux kernel behaves with respect to syscalls.
On a few occasions, it is useful to run with a kernel that has some
(minor) extensions to the vanilla model, either due to running on a
hacked kernel, or using a vanilla kernel which has incorporated a
custom kernel module. Rather than clutter the standard model, all
such variant handlers are placed in here.
Unlike the C files for the standard model, this file should also
contain all constants/types needed for said wrappers. The vki*.h
headers should not be polluted with non-vanilla info. */
#include "pub_core_basics.h"
#include "pub_core_vki.h"
#include "pub_core_threadstate.h"
#include "pub_core_aspacemgr.h"
#include "pub_core_debuginfo.h" // VG_(di_notify_*)
#include "pub_core_transtab.h" // VG_(discard_translations)
#include "pub_core_debuglog.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
#include "pub_core_libcfile.h"
#include "pub_core_libcprint.h"
#include "pub_core_libcproc.h"
#include "pub_core_mallocfree.h"
#include "pub_core_tooliface.h"
#include "pub_core_options.h"
#include "pub_core_scheduler.h"
#include "pub_core_signals.h"
#include "pub_core_syscall.h"
#include "priv_types_n_macros.h"
#include "priv_syswrap-linux-variants.h"
/* ---------------------------------------------------------------
BProc wrappers
------------------------------------------------------------ */
/* Return 0 means hand to kernel, non-0 means fail w/ that value. */
Int ML_(linux_variant_PRE_sys_bproc)( UWord arg1, UWord arg2,
UWord arg3, UWord arg4,
UWord arg5, UWord arg6 )
{
return 0;
}
void ML_(linux_variant_POST_sys_bproc)( UWord arg1, UWord arg2,
UWord arg3, UWord arg4,
UWord arg5, UWord arg6 )
{
}
#endif // defined(VGO_linux)
/*--------------------------------------------------------------------*/
/*--- end ---*/
/*--------------------------------------------------------------------*/
|
the_stack_data/168894175.c | // sample compile command: "gcc -fopenmp -c Fig_6.4_wrongPrivate.c" to generate *.o object file
#include <stdio.h>
void wrong()
{
int tmp = 0;
#pragma omp parallel for private(tmp)
for (int j = 0; j < 1000; j++)
tmp += j;
printf("%d\n", tmp); //tmp is 0 here
}
|
the_stack_data/95450984.c | #include <stdio.h>
/* print Fahrenheit-Celsius table
for fahr = 0, 20, ..., 300; floating-point version */
int main()
{
float fahr, celsius;
int lower, upper, step;
lower = 0; /* lower limit of temperature table */
upper = 300; /* upper limit */
step = 20; /* step size */
fahr = lower;
while (fahr <= upper) {
celsius = (5.0/9.0) * (fahr-32.0);
printf("%3.0f %6.1f\n", fahr, celsius);
fahr = fahr + step;
}
return 0;
}
|
the_stack_data/215769088.c | /*******************************************************************************
*
* Copyright (C) 2014-2018 Wave Computing, Inc.
*
* 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 copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************/
/*
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#include <stdio.h>
/* Write a word (int) */
int putw (int w, FILE *fp)
{
if (fwrite ((const char*) &w, sizeof (w), 1, fp) != 1)
return EOF;
return 0;
}/* putw */
|
the_stack_data/150046.c | #include <stdio.h>
/**
* main - Prints the add of the even-valued
* fibonacci numbers.
*
* Return: Always 0.
*/
int main(void)
{
long int n1, n2, fn, afn;
n1 = 1;
n2 = 2;
fn = afn = 0;
while (fn <= 4000000)
{
fn = n1 + n2;
n1 = n2;
n2 = fn;
if ((n1 % 2) == 0)
{
afn += n1;
}
}
printf("%ld\n", afn);
return (0);
}
|
the_stack_data/54826327.c | /* { dg-do compile } */
/* { dg-options "-O3 -mavx -mtune=generic -dp" } */
/* { dg-additional-options "-mabi=sysv" { target x86_64-*-mingw* } } */
typedef double EXPRESS[5];
void Parse_Rel_Factor (EXPRESS Express,int *Terms);
void Parse_Vector ()
{
EXPRESS Express;
int Terms;
for (Terms = 0; Terms < 5; Terms++)
Express[Terms] = 1.0;
Parse_Rel_Factor(Express,&Terms);
}
/* { dg-final { scan-assembler-times "avx_vzeroupper" 1 } } */
|
the_stack_data/76701343.c | #include <stdio.h>
int main(void) {
int n = 20, m = 10;
printf("O endereço de n é 0x%p\n", &n);
printf("O valor de n é %d\n", n);
printf("O endereço de m é 0x%p\n", &m);
printf("O valor de m é %d\n", m);
return 0;
}
|
the_stack_data/215768300.c | #define ll long long
#define ull unsigned long long
#include <stdio.h>
#include <stdlib.h>
int main()
{
while(1)
printf("%lli\n", (ull)arc4random() * (ll)arc4random());
/*By multiplying two (2) thirty-two-bit calls to arc4random,
a sixty-four-bit number is produced.*/
}
|
the_stack_data/1778.c | #include <math.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <complex.h>
#ifdef complex
#undef complex
#endif
#ifdef I
#undef I
#endif
#if defined(_WIN64)
typedef long long BLASLONG;
typedef unsigned long long BLASULONG;
#else
typedef long BLASLONG;
typedef unsigned long BLASULONG;
#endif
#ifdef LAPACK_ILP64
typedef BLASLONG blasint;
#if defined(_WIN64)
#define blasabs(x) llabs(x)
#else
#define blasabs(x) labs(x)
#endif
#else
typedef int blasint;
#define blasabs(x) abs(x)
#endif
typedef blasint integer;
typedef unsigned int uinteger;
typedef char *address;
typedef short int shortint;
typedef float real;
typedef double doublereal;
typedef struct { real r, i; } complex;
typedef struct { doublereal r, i; } doublecomplex;
#ifdef _MSC_VER
static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
#else
static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
#endif
#define pCf(z) (*_pCf(z))
#define pCd(z) (*_pCd(z))
typedef int logical;
typedef short int shortlogical;
typedef char logical1;
typedef char integer1;
#define TRUE_ (1)
#define FALSE_ (0)
/* Extern is for use with -E */
#ifndef Extern
#define Extern extern
#endif
/* I/O stuff */
typedef int flag;
typedef int ftnlen;
typedef int ftnint;
/*external read, write*/
typedef struct
{ flag cierr;
ftnint ciunit;
flag ciend;
char *cifmt;
ftnint cirec;
} cilist;
/*internal read, write*/
typedef struct
{ flag icierr;
char *iciunit;
flag iciend;
char *icifmt;
ftnint icirlen;
ftnint icirnum;
} icilist;
/*open*/
typedef struct
{ flag oerr;
ftnint ounit;
char *ofnm;
ftnlen ofnmlen;
char *osta;
char *oacc;
char *ofm;
ftnint orl;
char *oblnk;
} olist;
/*close*/
typedef struct
{ flag cerr;
ftnint cunit;
char *csta;
} cllist;
/*rewind, backspace, endfile*/
typedef struct
{ flag aerr;
ftnint aunit;
} alist;
/* inquire */
typedef struct
{ flag inerr;
ftnint inunit;
char *infile;
ftnlen infilen;
ftnint *inex; /*parameters in standard's order*/
ftnint *inopen;
ftnint *innum;
ftnint *innamed;
char *inname;
ftnlen innamlen;
char *inacc;
ftnlen inacclen;
char *inseq;
ftnlen inseqlen;
char *indir;
ftnlen indirlen;
char *infmt;
ftnlen infmtlen;
char *inform;
ftnint informlen;
char *inunf;
ftnlen inunflen;
ftnint *inrecl;
ftnint *innrec;
char *inblank;
ftnlen inblanklen;
} inlist;
#define VOID void
union Multitype { /* for multiple entry points */
integer1 g;
shortint h;
integer i;
/* longint j; */
real r;
doublereal d;
complex c;
doublecomplex z;
};
typedef union Multitype Multitype;
struct Vardesc { /* for Namelist */
char *name;
char *addr;
ftnlen *dims;
int type;
};
typedef struct Vardesc Vardesc;
struct Namelist {
char *name;
Vardesc **vars;
int nvars;
};
typedef struct Namelist Namelist;
#define abs(x) ((x) >= 0 ? (x) : -(x))
#define dabs(x) (fabs(x))
#define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
#define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
#define dmin(a,b) (f2cmin(a,b))
#define dmax(a,b) (f2cmax(a,b))
#define bit_test(a,b) ((a) >> (b) & 1)
#define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
#define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
#define abort_() { sig_die("Fortran abort routine called", 1); }
#define c_abs(z) (cabsf(Cf(z)))
#define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
#ifdef _MSC_VER
#define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
#define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
#else
#define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
#define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
#endif
#define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
#define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
#define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
//#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
#define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
#define d_abs(x) (fabs(*(x)))
#define d_acos(x) (acos(*(x)))
#define d_asin(x) (asin(*(x)))
#define d_atan(x) (atan(*(x)))
#define d_atn2(x, y) (atan2(*(x),*(y)))
#define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
#define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
#define d_cos(x) (cos(*(x)))
#define d_cosh(x) (cosh(*(x)))
#define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
#define d_exp(x) (exp(*(x)))
#define d_imag(z) (cimag(Cd(z)))
#define r_imag(z) (cimagf(Cf(z)))
#define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
#define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
#define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
#define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
#define d_log(x) (log(*(x)))
#define d_mod(x, y) (fmod(*(x), *(y)))
#define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
#define d_nint(x) u_nint(*(x))
#define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
#define d_sign(a,b) u_sign(*(a),*(b))
#define r_sign(a,b) u_sign(*(a),*(b))
#define d_sin(x) (sin(*(x)))
#define d_sinh(x) (sinh(*(x)))
#define d_sqrt(x) (sqrt(*(x)))
#define d_tan(x) (tan(*(x)))
#define d_tanh(x) (tanh(*(x)))
#define i_abs(x) abs(*(x))
#define i_dnnt(x) ((integer)u_nint(*(x)))
#define i_len(s, n) (n)
#define i_nint(x) ((integer)u_nint(*(x)))
#define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
#define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
#define pow_si(B,E) spow_ui(*(B),*(E))
#define pow_ri(B,E) spow_ui(*(B),*(E))
#define pow_di(B,E) dpow_ui(*(B),*(E))
#define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
#define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
#define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
#define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
#define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
#define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
#define sig_die(s, kill) { exit(1); }
#define s_stop(s, n) {exit(0);}
static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
#define z_abs(z) (cabs(Cd(z)))
#define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
#define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
#define myexit_() break;
#define mycycle() continue;
#define myceiling(w) {ceil(w)}
#define myhuge(w) {HUGE_VAL}
//#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
#define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
/* procedure parameter types for -A and -C++ */
#define F2C_proc_par_types 1
#ifdef __cplusplus
typedef logical (*L_fp)(...);
#else
typedef logical (*L_fp)();
#endif
static float spow_ui(float x, integer n) {
float pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static double dpow_ui(double x, integer n) {
double pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
#ifdef _MSC_VER
static _Fcomplex cpow_ui(complex x, integer n) {
complex pow={1.0,0.0}; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
for(u = n; ; ) {
if(u & 01) pow.r *= x.r, pow.i *= x.i;
if(u >>= 1) x.r *= x.r, x.i *= x.i;
else break;
}
}
_Fcomplex p={pow.r, pow.i};
return p;
}
#else
static _Complex float cpow_ui(_Complex float x, integer n) {
_Complex float pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
#endif
#ifdef _MSC_VER
static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
_Dcomplex pow={1.0,0.0}; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
for(u = n; ; ) {
if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
else break;
}
}
_Dcomplex p = {pow._Val[0], pow._Val[1]};
return p;
}
#else
static _Complex double zpow_ui(_Complex double x, integer n) {
_Complex double pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
#endif
static integer pow_ii(integer x, integer n) {
integer pow; unsigned long int u;
if (n <= 0) {
if (n == 0 || x == 1) pow = 1;
else if (x != -1) pow = x == 0 ? 1/x : 0;
else n = -n;
}
if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
u = n;
for(pow = 1; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static integer dmaxloc_(double *w, integer s, integer e, integer *n)
{
double m; integer i, mi;
for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
if (w[i-1]>m) mi=i ,m=w[i-1];
return mi-s+1;
}
static integer smaxloc_(float *w, integer s, integer e, integer *n)
{
float m; integer i, mi;
for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
if (w[i-1]>m) mi=i ,m=w[i-1];
return mi-s+1;
}
static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
#ifdef _MSC_VER
_Fcomplex zdotc = {0.0, 0.0};
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
}
}
pCf(z) = zdotc;
}
#else
_Complex float zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
}
}
pCf(z) = zdotc;
}
#endif
static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
#ifdef _MSC_VER
_Dcomplex zdotc = {0.0, 0.0};
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
}
}
pCd(z) = zdotc;
}
#else
_Complex double zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
}
}
pCd(z) = zdotc;
}
#endif
static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
#ifdef _MSC_VER
_Fcomplex zdotc = {0.0, 0.0};
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
}
}
pCf(z) = zdotc;
}
#else
_Complex float zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cf(&x[i]) * Cf(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
}
}
pCf(z) = zdotc;
}
#endif
static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
#ifdef _MSC_VER
_Dcomplex zdotc = {0.0, 0.0};
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
}
}
pCd(z) = zdotc;
}
#else
_Complex double zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cd(&x[i]) * Cd(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
}
}
pCd(z) = zdotc;
}
#endif
/* -- translated by f2c (version 20000121).
You must link the resulting object file with the libraries:
-lf2c -lm (in that order)
*/
/* Table of constant values */
static integer c__1 = 1;
static real c_b23 = 0.f;
static integer c__0 = 0;
static real c_b39 = 1.f;
/* > \brief \b SLATME */
/* =========== DOCUMENTATION =========== */
/* Online html documentation available at */
/* http://www.netlib.org/lapack/explore-html/ */
/* Definition: */
/* =========== */
/* SUBROUTINE SLATME( N, DIST, ISEED, D, MODE, COND, DMAX, EI, */
/* RSIGN, */
/* UPPER, SIM, DS, MODES, CONDS, KL, KU, ANORM, */
/* A, */
/* LDA, WORK, INFO ) */
/* CHARACTER DIST, RSIGN, SIM, UPPER */
/* INTEGER INFO, KL, KU, LDA, MODE, MODES, N */
/* REAL ANORM, COND, CONDS, DMAX */
/* CHARACTER EI( * ) */
/* INTEGER ISEED( 4 ) */
/* REAL A( LDA, * ), D( * ), DS( * ), WORK( * ) */
/* > \par Purpose: */
/* ============= */
/* > */
/* > \verbatim */
/* > */
/* > SLATME generates random non-symmetric square matrices with */
/* > specified eigenvalues for testing LAPACK programs. */
/* > */
/* > SLATME operates by applying the following sequence of */
/* > operations: */
/* > */
/* > 1. Set the diagonal to D, where D may be input or */
/* > computed according to MODE, COND, DMAX, and RSIGN */
/* > as described below. */
/* > */
/* > 2. If complex conjugate pairs are desired (MODE=0 and EI(1)='R', */
/* > or MODE=5), certain pairs of adjacent elements of D are */
/* > interpreted as the real and complex parts of a complex */
/* > conjugate pair; A thus becomes block diagonal, with 1x1 */
/* > and 2x2 blocks. */
/* > */
/* > 3. If UPPER='T', the upper triangle of A is set to random values */
/* > out of distribution DIST. */
/* > */
/* > 4. If SIM='T', A is multiplied on the left by a random matrix */
/* > X, whose singular values are specified by DS, MODES, and */
/* > CONDS, and on the right by X inverse. */
/* > */
/* > 5. If KL < N-1, the lower bandwidth is reduced to KL using */
/* > Householder transformations. If KU < N-1, the upper */
/* > bandwidth is reduced to KU. */
/* > */
/* > 6. If ANORM is not negative, the matrix is scaled to have */
/* > maximum-element-norm ANORM. */
/* > */
/* > (Note: since the matrix cannot be reduced beyond Hessenberg form, */
/* > no packing options are available.) */
/* > \endverbatim */
/* Arguments: */
/* ========== */
/* > \param[in] N */
/* > \verbatim */
/* > N is INTEGER */
/* > The number of columns (or rows) of A. Not modified. */
/* > \endverbatim */
/* > */
/* > \param[in] DIST */
/* > \verbatim */
/* > DIST is CHARACTER*1 */
/* > On entry, DIST specifies the type of distribution to be used */
/* > to generate the random eigen-/singular values, and for the */
/* > upper triangle (see UPPER). */
/* > 'U' => UNIFORM( 0, 1 ) ( 'U' for uniform ) */
/* > 'S' => UNIFORM( -1, 1 ) ( 'S' for symmetric ) */
/* > 'N' => NORMAL( 0, 1 ) ( 'N' for normal ) */
/* > Not modified. */
/* > \endverbatim */
/* > */
/* > \param[in,out] ISEED */
/* > \verbatim */
/* > ISEED is INTEGER array, dimension ( 4 ) */
/* > On entry ISEED specifies the seed of the random number */
/* > generator. They should lie between 0 and 4095 inclusive, */
/* > and ISEED(4) should be odd. The random number generator */
/* > uses a linear congruential sequence limited to small */
/* > integers, and so should produce machine independent */
/* > random numbers. The values of ISEED are changed on */
/* > exit, and can be used in the next call to SLATME */
/* > to continue the same random number sequence. */
/* > Changed on exit. */
/* > \endverbatim */
/* > */
/* > \param[in,out] D */
/* > \verbatim */
/* > D is REAL array, dimension ( N ) */
/* > This array is used to specify the eigenvalues of A. If */
/* > MODE=0, then D is assumed to contain the eigenvalues (but */
/* > see the description of EI), otherwise they will be */
/* > computed according to MODE, COND, DMAX, and RSIGN and */
/* > placed in D. */
/* > Modified if MODE is nonzero. */
/* > \endverbatim */
/* > */
/* > \param[in] MODE */
/* > \verbatim */
/* > MODE is INTEGER */
/* > On entry this describes how the eigenvalues are to */
/* > be specified: */
/* > MODE = 0 means use D (with EI) as input */
/* > MODE = 1 sets D(1)=1 and D(2:N)=1.0/COND */
/* > MODE = 2 sets D(1:N-1)=1 and D(N)=1.0/COND */
/* > MODE = 3 sets D(I)=COND**(-(I-1)/(N-1)) */
/* > MODE = 4 sets D(i)=1 - (i-1)/(N-1)*(1 - 1/COND) */
/* > MODE = 5 sets D to random numbers in the range */
/* > ( 1/COND , 1 ) such that their logarithms */
/* > are uniformly distributed. Each odd-even pair */
/* > of elements will be either used as two real */
/* > eigenvalues or as the real and imaginary part */
/* > of a complex conjugate pair of eigenvalues; */
/* > the choice of which is done is random, with */
/* > 50-50 probability, for each pair. */
/* > MODE = 6 set D to random numbers from same distribution */
/* > as the rest of the matrix. */
/* > MODE < 0 has the same meaning as ABS(MODE), except that */
/* > the order of the elements of D is reversed. */
/* > Thus if MODE is between 1 and 4, D has entries ranging */
/* > from 1 to 1/COND, if between -1 and -4, D has entries */
/* > ranging from 1/COND to 1, */
/* > Not modified. */
/* > \endverbatim */
/* > */
/* > \param[in] COND */
/* > \verbatim */
/* > COND is REAL */
/* > On entry, this is used as described under MODE above. */
/* > If used, it must be >= 1. Not modified. */
/* > \endverbatim */
/* > */
/* > \param[in] DMAX */
/* > \verbatim */
/* > DMAX is REAL */
/* > If MODE is neither -6, 0 nor 6, the contents of D, as */
/* > computed according to MODE and COND, will be scaled by */
/* > DMAX / f2cmax(abs(D(i))). Note that DMAX need not be */
/* > positive: if DMAX is negative (or zero), D will be */
/* > scaled by a negative number (or zero). */
/* > Not modified. */
/* > \endverbatim */
/* > */
/* > \param[in] EI */
/* > \verbatim */
/* > EI is CHARACTER*1 array, dimension ( N ) */
/* > If MODE is 0, and EI(1) is not ' ' (space character), */
/* > this array specifies which elements of D (on input) are */
/* > real eigenvalues and which are the real and imaginary parts */
/* > of a complex conjugate pair of eigenvalues. The elements */
/* > of EI may then only have the values 'R' and 'I'. If */
/* > EI(j)='R' and EI(j+1)='I', then the j-th eigenvalue is */
/* > CMPLX( D(j) , D(j+1) ), and the (j+1)-th is the complex */
/* > conjugate thereof. If EI(j)=EI(j+1)='R', then the j-th */
/* > eigenvalue is D(j) (i.e., real). EI(1) may not be 'I', */
/* > nor may two adjacent elements of EI both have the value 'I'. */
/* > If MODE is not 0, then EI is ignored. If MODE is 0 and */
/* > EI(1)=' ', then the eigenvalues will all be real. */
/* > Not modified. */
/* > \endverbatim */
/* > */
/* > \param[in] RSIGN */
/* > \verbatim */
/* > RSIGN is CHARACTER*1 */
/* > If MODE is not 0, 6, or -6, and RSIGN='T', then the */
/* > elements of D, as computed according to MODE and COND, will */
/* > be multiplied by a random sign (+1 or -1). If RSIGN='F', */
/* > they will not be. RSIGN may only have the values 'T' or */
/* > 'F'. */
/* > Not modified. */
/* > \endverbatim */
/* > */
/* > \param[in] UPPER */
/* > \verbatim */
/* > UPPER is CHARACTER*1 */
/* > If UPPER='T', then the elements of A above the diagonal */
/* > (and above the 2x2 diagonal blocks, if A has complex */
/* > eigenvalues) will be set to random numbers out of DIST. */
/* > If UPPER='F', they will not. UPPER may only have the */
/* > values 'T' or 'F'. */
/* > Not modified. */
/* > \endverbatim */
/* > */
/* > \param[in] SIM */
/* > \verbatim */
/* > SIM is CHARACTER*1 */
/* > If SIM='T', then A will be operated on by a "similarity */
/* > transform", i.e., multiplied on the left by a matrix X and */
/* > on the right by X inverse. X = U S V, where U and V are */
/* > random unitary matrices and S is a (diagonal) matrix of */
/* > singular values specified by DS, MODES, and CONDS. If */
/* > SIM='F', then A will not be transformed. */
/* > Not modified. */
/* > \endverbatim */
/* > */
/* > \param[in,out] DS */
/* > \verbatim */
/* > DS is REAL array, dimension ( N ) */
/* > This array is used to specify the singular values of X, */
/* > in the same way that D specifies the eigenvalues of A. */
/* > If MODE=0, the DS contains the singular values, which */
/* > may not be zero. */
/* > Modified if MODE is nonzero. */
/* > \endverbatim */
/* > */
/* > \param[in] MODES */
/* > \verbatim */
/* > MODES is INTEGER */
/* > \endverbatim */
/* > */
/* > \param[in] CONDS */
/* > \verbatim */
/* > CONDS is REAL */
/* > Same as MODE and COND, but for specifying the diagonal */
/* > of S. MODES=-6 and +6 are not allowed (since they would */
/* > result in randomly ill-conditioned eigenvalues.) */
/* > \endverbatim */
/* > */
/* > \param[in] KL */
/* > \verbatim */
/* > KL is INTEGER */
/* > This specifies the lower bandwidth of the matrix. KL=1 */
/* > specifies upper Hessenberg form. If KL is at least N-1, */
/* > then A will have full lower bandwidth. KL must be at */
/* > least 1. */
/* > Not modified. */
/* > \endverbatim */
/* > */
/* > \param[in] KU */
/* > \verbatim */
/* > KU is INTEGER */
/* > This specifies the upper bandwidth of the matrix. KU=1 */
/* > specifies lower Hessenberg form. If KU is at least N-1, */
/* > then A will have full upper bandwidth; if KU and KL */
/* > are both at least N-1, then A will be dense. Only one of */
/* > KU and KL may be less than N-1. KU must be at least 1. */
/* > Not modified. */
/* > \endverbatim */
/* > */
/* > \param[in] ANORM */
/* > \verbatim */
/* > ANORM is REAL */
/* > If ANORM is not negative, then A will be scaled by a non- */
/* > negative real number to make the maximum-element-norm of A */
/* > to be ANORM. */
/* > Not modified. */
/* > \endverbatim */
/* > */
/* > \param[out] A */
/* > \verbatim */
/* > A is REAL array, dimension ( LDA, N ) */
/* > On exit A is the desired test matrix. */
/* > Modified. */
/* > \endverbatim */
/* > */
/* > \param[in] LDA */
/* > \verbatim */
/* > LDA is INTEGER */
/* > LDA specifies the first dimension of A as declared in the */
/* > calling program. LDA must be at least N. */
/* > Not modified. */
/* > \endverbatim */
/* > */
/* > \param[out] WORK */
/* > \verbatim */
/* > WORK is REAL array, dimension ( 3*N ) */
/* > Workspace. */
/* > Modified. */
/* > \endverbatim */
/* > */
/* > \param[out] INFO */
/* > \verbatim */
/* > INFO is INTEGER */
/* > Error code. On exit, INFO will be set to one of the */
/* > following values: */
/* > 0 => normal return */
/* > -1 => N negative */
/* > -2 => DIST illegal string */
/* > -5 => MODE not in range -6 to 6 */
/* > -6 => COND less than 1.0, and MODE neither -6, 0 nor 6 */
/* > -8 => EI(1) is not ' ' or 'R', EI(j) is not 'R' or 'I', or */
/* > two adjacent elements of EI are 'I'. */
/* > -9 => RSIGN is not 'T' or 'F' */
/* > -10 => UPPER is not 'T' or 'F' */
/* > -11 => SIM is not 'T' or 'F' */
/* > -12 => MODES=0 and DS has a zero singular value. */
/* > -13 => MODES is not in the range -5 to 5. */
/* > -14 => MODES is nonzero and CONDS is less than 1. */
/* > -15 => KL is less than 1. */
/* > -16 => KU is less than 1, or KL and KU are both less than */
/* > N-1. */
/* > -19 => LDA is less than N. */
/* > 1 => Error return from SLATM1 (computing D) */
/* > 2 => Cannot scale to DMAX (f2cmax. eigenvalue is 0) */
/* > 3 => Error return from SLATM1 (computing DS) */
/* > 4 => Error return from SLARGE */
/* > 5 => Zero singular value from SLATM1. */
/* > \endverbatim */
/* Authors: */
/* ======== */
/* > \author Univ. of Tennessee */
/* > \author Univ. of California Berkeley */
/* > \author Univ. of Colorado Denver */
/* > \author NAG Ltd. */
/* > \date December 2016 */
/* > \ingroup real_matgen */
/* ===================================================================== */
/* Subroutine */ int slatme_(integer *n, char *dist, integer *iseed, real *
d__, integer *mode, real *cond, real *dmax__, char *ei, char *rsign,
char *upper, char *sim, real *ds, integer *modes, real *conds,
integer *kl, integer *ku, real *anorm, real *a, integer *lda, real *
work, integer *info)
{
/* System generated locals */
integer a_dim1, a_offset, i__1, i__2;
real r__1, r__2, r__3;
/* Local variables */
logical bads;
extern /* Subroutine */ int sger_(integer *, integer *, real *, real *,
integer *, real *, integer *, real *, integer *);
integer isim;
real temp;
logical badei;
integer i__, j;
real alpha;
extern logical lsame_(char *, char *);
integer iinfo;
extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *);
real tempa[1];
integer icols;
logical useei;
integer idist;
extern /* Subroutine */ int sgemv_(char *, integer *, integer *, real *,
real *, integer *, real *, integer *, real *, real *, integer *), scopy_(integer *, real *, integer *, real *, integer *);
integer irows;
extern /* Subroutine */ int slatm1_(integer *, real *, integer *, integer
*, integer *, real *, integer *, integer *);
integer ic, jc, ir, jr;
extern real slange_(char *, integer *, integer *, real *, integer *, real
*);
extern /* Subroutine */ int slarge_(integer *, real *, integer *, integer
*, real *, integer *), slarfg_(integer *, real *, real *, integer
*, real *), xerbla_(char *, integer *);
extern real slaran_(integer *);
integer irsign;
extern /* Subroutine */ int slaset_(char *, integer *, integer *, real *,
real *, real *, integer *);
integer iupper;
extern /* Subroutine */ int slarnv_(integer *, integer *, integer *, real
*);
real xnorms;
integer jcr;
real tau;
/* -- LAPACK computational routine (version 3.7.0) -- */
/* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
/* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
/* December 2016 */
/* ===================================================================== */
/* 1) Decode and Test the input parameters. */
/* Initialize flags & seed. */
/* Parameter adjustments */
--iseed;
--d__;
--ei;
--ds;
a_dim1 = *lda;
a_offset = 1 + a_dim1 * 1;
a -= a_offset;
--work;
/* Function Body */
*info = 0;
/* Quick return if possible */
if (*n == 0) {
return 0;
}
/* Decode DIST */
if (lsame_(dist, "U")) {
idist = 1;
} else if (lsame_(dist, "S")) {
idist = 2;
} else if (lsame_(dist, "N")) {
idist = 3;
} else {
idist = -1;
}
/* Check EI */
useei = TRUE_;
badei = FALSE_;
if (lsame_(ei + 1, " ") || *mode != 0) {
useei = FALSE_;
} else {
if (lsame_(ei + 1, "R")) {
i__1 = *n;
for (j = 2; j <= i__1; ++j) {
if (lsame_(ei + j, "I")) {
if (lsame_(ei + (j - 1), "I")) {
badei = TRUE_;
}
} else {
if (! lsame_(ei + j, "R")) {
badei = TRUE_;
}
}
/* L10: */
}
} else {
badei = TRUE_;
}
}
/* Decode RSIGN */
if (lsame_(rsign, "T")) {
irsign = 1;
} else if (lsame_(rsign, "F")) {
irsign = 0;
} else {
irsign = -1;
}
/* Decode UPPER */
if (lsame_(upper, "T")) {
iupper = 1;
} else if (lsame_(upper, "F")) {
iupper = 0;
} else {
iupper = -1;
}
/* Decode SIM */
if (lsame_(sim, "T")) {
isim = 1;
} else if (lsame_(sim, "F")) {
isim = 0;
} else {
isim = -1;
}
/* Check DS, if MODES=0 and ISIM=1 */
bads = FALSE_;
if (*modes == 0 && isim == 1) {
i__1 = *n;
for (j = 1; j <= i__1; ++j) {
if (ds[j] == 0.f) {
bads = TRUE_;
}
/* L20: */
}
}
/* Set INFO if an error */
if (*n < 0) {
*info = -1;
} else if (idist == -1) {
*info = -2;
} else if (abs(*mode) > 6) {
*info = -5;
} else if (*mode != 0 && abs(*mode) != 6 && *cond < 1.f) {
*info = -6;
} else if (badei) {
*info = -8;
} else if (irsign == -1) {
*info = -9;
} else if (iupper == -1) {
*info = -10;
} else if (isim == -1) {
*info = -11;
} else if (bads) {
*info = -12;
} else if (isim == 1 && abs(*modes) > 5) {
*info = -13;
} else if (isim == 1 && *modes != 0 && *conds < 1.f) {
*info = -14;
} else if (*kl < 1) {
*info = -15;
} else if (*ku < 1 || *ku < *n - 1 && *kl < *n - 1) {
*info = -16;
} else if (*lda < f2cmax(1,*n)) {
*info = -19;
}
if (*info != 0) {
i__1 = -(*info);
xerbla_("SLATME", &i__1);
return 0;
}
/* Initialize random number generator */
for (i__ = 1; i__ <= 4; ++i__) {
iseed[i__] = (i__1 = iseed[i__], abs(i__1)) % 4096;
/* L30: */
}
if (iseed[4] % 2 != 1) {
++iseed[4];
}
/* 2) Set up diagonal of A */
/* Compute D according to COND and MODE */
slatm1_(mode, cond, &irsign, &idist, &iseed[1], &d__[1], n, &iinfo);
if (iinfo != 0) {
*info = 1;
return 0;
}
if (*mode != 0 && abs(*mode) != 6) {
/* Scale by DMAX */
temp = abs(d__[1]);
i__1 = *n;
for (i__ = 2; i__ <= i__1; ++i__) {
/* Computing MAX */
r__2 = temp, r__3 = (r__1 = d__[i__], abs(r__1));
temp = f2cmax(r__2,r__3);
/* L40: */
}
if (temp > 0.f) {
alpha = *dmax__ / temp;
} else if (*dmax__ != 0.f) {
*info = 2;
return 0;
} else {
alpha = 0.f;
}
sscal_(n, &alpha, &d__[1], &c__1);
}
slaset_("Full", n, n, &c_b23, &c_b23, &a[a_offset], lda);
i__1 = *lda + 1;
scopy_(n, &d__[1], &c__1, &a[a_offset], &i__1);
/* Set up complex conjugate pairs */
if (*mode == 0) {
if (useei) {
i__1 = *n;
for (j = 2; j <= i__1; ++j) {
if (lsame_(ei + j, "I")) {
a[j - 1 + j * a_dim1] = a[j + j * a_dim1];
a[j + (j - 1) * a_dim1] = -a[j + j * a_dim1];
a[j + j * a_dim1] = a[j - 1 + (j - 1) * a_dim1];
}
/* L50: */
}
}
} else if (abs(*mode) == 5) {
i__1 = *n;
for (j = 2; j <= i__1; j += 2) {
if (slaran_(&iseed[1]) > .5f) {
a[j - 1 + j * a_dim1] = a[j + j * a_dim1];
a[j + (j - 1) * a_dim1] = -a[j + j * a_dim1];
a[j + j * a_dim1] = a[j - 1 + (j - 1) * a_dim1];
}
/* L60: */
}
}
/* 3) If UPPER='T', set upper triangle of A to random numbers. */
/* (but don't modify the corners of 2x2 blocks.) */
if (iupper != 0) {
i__1 = *n;
for (jc = 2; jc <= i__1; ++jc) {
if (a[jc - 1 + jc * a_dim1] != 0.f) {
jr = jc - 2;
} else {
jr = jc - 1;
}
slarnv_(&idist, &iseed[1], &jr, &a[jc * a_dim1 + 1]);
/* L70: */
}
}
/* 4) If SIM='T', apply similarity transformation. */
/* -1 */
/* Transform is X A X , where X = U S V, thus */
/* it is U S V A V' (1/S) U' */
if (isim != 0) {
/* Compute S (singular values of the eigenvector matrix) */
/* according to CONDS and MODES */
slatm1_(modes, conds, &c__0, &c__0, &iseed[1], &ds[1], n, &iinfo);
if (iinfo != 0) {
*info = 3;
return 0;
}
/* Multiply by V and V' */
slarge_(n, &a[a_offset], lda, &iseed[1], &work[1], &iinfo);
if (iinfo != 0) {
*info = 4;
return 0;
}
/* Multiply by S and (1/S) */
i__1 = *n;
for (j = 1; j <= i__1; ++j) {
sscal_(n, &ds[j], &a[j + a_dim1], lda);
if (ds[j] != 0.f) {
r__1 = 1.f / ds[j];
sscal_(n, &r__1, &a[j * a_dim1 + 1], &c__1);
} else {
*info = 5;
return 0;
}
/* L80: */
}
/* Multiply by U and U' */
slarge_(n, &a[a_offset], lda, &iseed[1], &work[1], &iinfo);
if (iinfo != 0) {
*info = 4;
return 0;
}
}
/* 5) Reduce the bandwidth. */
if (*kl < *n - 1) {
/* Reduce bandwidth -- kill column */
i__1 = *n - 1;
for (jcr = *kl + 1; jcr <= i__1; ++jcr) {
ic = jcr - *kl;
irows = *n + 1 - jcr;
icols = *n + *kl - jcr;
scopy_(&irows, &a[jcr + ic * a_dim1], &c__1, &work[1], &c__1);
xnorms = work[1];
slarfg_(&irows, &xnorms, &work[2], &c__1, &tau);
work[1] = 1.f;
sgemv_("T", &irows, &icols, &c_b39, &a[jcr + (ic + 1) * a_dim1],
lda, &work[1], &c__1, &c_b23, &work[irows + 1], &c__1);
r__1 = -tau;
sger_(&irows, &icols, &r__1, &work[1], &c__1, &work[irows + 1], &
c__1, &a[jcr + (ic + 1) * a_dim1], lda);
sgemv_("N", n, &irows, &c_b39, &a[jcr * a_dim1 + 1], lda, &work[1]
, &c__1, &c_b23, &work[irows + 1], &c__1);
r__1 = -tau;
sger_(n, &irows, &r__1, &work[irows + 1], &c__1, &work[1], &c__1,
&a[jcr * a_dim1 + 1], lda);
a[jcr + ic * a_dim1] = xnorms;
i__2 = irows - 1;
slaset_("Full", &i__2, &c__1, &c_b23, &c_b23, &a[jcr + 1 + ic *
a_dim1], lda);
/* L90: */
}
} else if (*ku < *n - 1) {
/* Reduce upper bandwidth -- kill a row at a time. */
i__1 = *n - 1;
for (jcr = *ku + 1; jcr <= i__1; ++jcr) {
ir = jcr - *ku;
irows = *n + *ku - jcr;
icols = *n + 1 - jcr;
scopy_(&icols, &a[ir + jcr * a_dim1], lda, &work[1], &c__1);
xnorms = work[1];
slarfg_(&icols, &xnorms, &work[2], &c__1, &tau);
work[1] = 1.f;
sgemv_("N", &irows, &icols, &c_b39, &a[ir + 1 + jcr * a_dim1],
lda, &work[1], &c__1, &c_b23, &work[icols + 1], &c__1);
r__1 = -tau;
sger_(&irows, &icols, &r__1, &work[icols + 1], &c__1, &work[1], &
c__1, &a[ir + 1 + jcr * a_dim1], lda);
sgemv_("C", &icols, n, &c_b39, &a[jcr + a_dim1], lda, &work[1], &
c__1, &c_b23, &work[icols + 1], &c__1);
r__1 = -tau;
sger_(&icols, n, &r__1, &work[1], &c__1, &work[icols + 1], &c__1,
&a[jcr + a_dim1], lda);
a[ir + jcr * a_dim1] = xnorms;
i__2 = icols - 1;
slaset_("Full", &c__1, &i__2, &c_b23, &c_b23, &a[ir + (jcr + 1) *
a_dim1], lda);
/* L100: */
}
}
/* Scale the matrix to have norm ANORM */
if (*anorm >= 0.f) {
temp = slange_("M", n, n, &a[a_offset], lda, tempa);
if (temp > 0.f) {
alpha = *anorm / temp;
i__1 = *n;
for (j = 1; j <= i__1; ++j) {
sscal_(n, &alpha, &a[j * a_dim1 + 1], &c__1);
/* L110: */
}
}
}
return 0;
/* End of SLATME */
} /* slatme_ */
|
the_stack_data/791538.c | #include <elf.h>
#include <link.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <string.h>
int
main (int argc, char *argv[])
{
const char *filename = argv[1];
int fd = open (filename, O_RDONLY);
struct stat buf;
fstat (fd, &buf);
unsigned long file =
(unsigned long) mmap (0, buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
if (file == (unsigned long) MAP_FAILED)
{
exit (1);
}
FILE *out = NULL;
if (argc > 2)
{
out = fopen (argv[2], "w");
}
else
{
out = stdout;
}
ElfW (Ehdr) * header = (ElfW (Ehdr) *) file;
ElfW (Shdr) * sh = (ElfW (Shdr) *) (file + header->e_shoff);
ElfW (Sym) * symtab = 0;
unsigned long n_symtab = 0;
ElfW (Half) * versym = 0;
ElfW (Verdef) * verdef = 0;
char *strtab = 0;
unsigned int i;
for (i = 0; i < header->e_shnum; i++)
{
if (sh[i].sh_type == SHT_DYNSYM)
{
symtab = (ElfW (Sym) *) (file + sh[i].sh_offset);
n_symtab = sh[i].sh_size / sh[i].sh_entsize;
}
else if (sh[i].sh_type == SHT_STRTAB && strtab == 0)
{
// XXX: should check the section name.
strtab = (char *) (file + sh[i].sh_offset);
}
else if (sh[i].sh_type == SHT_GNU_versym)
{
versym = (ElfW (Half) *) (file + sh[i].sh_offset);
}
else if (sh[i].sh_type == SHT_GNU_verdef)
{
verdef = (ElfW (Verdef) *) (file + sh[i].sh_offset);
}
}
if (strtab == 0 || verdef == 0 ||
symtab == 0 || n_symtab == 0 || versym == 0)
{
exit (3);
}
ElfW (Verdef) * cur, *prev;
int local_passthru_printed = 0;
for (prev = 0, cur = verdef;
cur != prev;
prev = cur, cur =
(ElfW (Verdef) *) (((unsigned long) cur) + cur->vd_next))
{
assert (cur->vd_version == 1);
assert (cur->vd_cnt == 2 || cur->vd_cnt == 1);
ElfW (Verdaux) * first =
(ElfW (Verdaux) *) (((unsigned long) cur) + cur->vd_aux);
if (cur->vd_flags & VER_FLG_BASE)
{
continue;
}
fprintf (out, "%s {\n", strtab + first->vda_name);
int has_one_symbol = 0;
for (i = 0; i < n_symtab; i++)
{
if (symtab[i].st_name == 0 || symtab[i].st_value == 0)
{
continue;
}
ElfW (Half) ver = versym[i];
if (cur->vd_ndx == ver)
{
if (!has_one_symbol)
{
has_one_symbol = 1;
fprintf (out, "global:\n");
}
fprintf (out, "\t%s;\n", strtab + symtab[i].st_name);
}
}
if (cur->vd_cnt == 1)
{
if (!local_passthru_printed)
{
local_passthru_printed = 1;
fprintf (out, "local:*;\n};\n");
}
else
{
fprintf (out, "};\n");
}
}
else
{
ElfW (Verdaux) * parent =
(ElfW (Verdaux) *) (((unsigned long) first) + first->vda_next);
fprintf (out, "} %s;\n", strtab + parent->vda_name);
}
}
fclose (out);
return 0;
}
|
the_stack_data/215767316.c | /*
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright 2009 Sun Microsystems, Inc. All rights reserved.
The contents of this file are subject to the terms of the BSD License("BSD")(the "License").
You can obtain a copy of the License at: http://www.opensparc.net/pubs/t1/licenses/BSD+_License.txt
The BSD License
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistribution of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistribution 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 Sun Microsystems, Inc. or the names of
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
This software is provided "AS IS," without a warranty of any kind. ALL
EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A
RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT
OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS
BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
You acknowledge that this software is not designed, licensed or intended for
use in the design, construction, operation or maintenance of any nuclear facility.
*/
#include <stdio.h>
#include <stdlib.h>
#ifdef _OPENMP
#include <omp.h>
#define TRUE 1
#define FALSE 0
#else
#define omp_get_thread_num() 0
#define omp_get_num_threads() 1
#endif
int main()
{
int i, n = 5;
int a;
#ifdef _OPENMP
(void) omp_set_dynamic(FALSE);
if (omp_get_dynamic()) {printf("Warning: dynamic adjustment of threads has been set\n");}
(void) omp_set_num_threads(3);
#endif
#pragma omp parallel for private(i,a)
for (i=0; i<n; i++)
{
a = i+1;
printf("Thread %d has a value of a = %d for i = %d\n",
omp_get_thread_num(),a,i);
} /*-- End of parallel for --*/
return(0);
}
|
the_stack_data/56669.c | #include <errno.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <fcntl.h>
#include <unistd.h>
int
main(void)
{
static const char path[] = "/dir.1/dir.2/test.txt";
int x;
int fd = open(path, O_RDONLY, 0);
printf("len=%u open returns: %d\n", (unsigned)strlen(path), fd);
// Seek forward, from end
long pos = lseek(fd, -60000, SEEK_END);
x = errno;
printf("pos=%ld\n", pos);
errno = x;
if (pos == -1) {
perror("lseek");
}
char buf[20];
ssize_t len = read(fd, buf, sizeof(buf));
printf("Sample: %.*s\n", (int)len, buf);
// Seek backward, from beginning
pos = lseek(fd, 10000, SEEK_SET);
x = errno;
printf("pos=%ld\n", pos);
errno = x;
if (pos == -1) {
perror("lseek");
}
len = read(fd, buf, sizeof(buf));
printf("Sample: %.*s\n", (int)len, buf);
// Seek forward, from current
pos = lseek(fd, 10000, SEEK_CUR);
x = errno;
printf("pos=%ld\n", pos);
errno = x;
if (pos == -1) {
perror("lseek");
}
len = read(fd, buf, sizeof(buf));
printf("Sample: %.*s\n", (int)len, buf);
int fd2;
static const char path2[] = "/dir.1/dir.2/test-2.txt";
fd2 = open(path2, O_RDWR | O_CREAT, 0644);
x = errno;
printf("fd2=%d\n", fd2);
errno = x;
if (fd2 < 0) {
perror(path2);
}
close(fd2);
// This is supposed to fail
fd2 = open(path, O_RDWR | O_CREAT | O_EXCL, 0644);
x = errno;
printf("fd2=%d\n", fd2);
errno = x;
if (fd2 < 0) {
perror(path);
}
close(fd2);
// This should also fail: the file is already open
fd2 = open(path, O_RDWR | O_CREAT | O_TRUNC, 0644);
x = errno;
printf("fd2=%d\n", fd2);
errno = x;
if (fd2 < 0) {
perror(path);
}
close(fd2);
// This should succeed
fd2 = open(path, O_RDONLY, 0);
x = errno;
printf("fd2=%d\n", fd2);
errno = x;
if (fd2 < 0) {
perror(path);
}
close(fd2);
close(fd);
// This should succeed, and truncate the file
fd2 = open(path, O_RDWR | O_CREAT | O_TRUNC, 0644);
x = errno;
printf("fd2=%d\n", fd2);
errno = x;
if (fd2 < 0) {
perror(path);
}
close(fd2);
#if 0
if (fd >= 0) {
char buf[1024];
ssize_t len;
long count = 0;
time_t t1 = time(NULL);
do {
len = read(fd, buf, sizeof(buf));
if (len < 0) {
perror(path);
break;
}
//write(1, buf, len);
count += len;
} while (len != 0);
printf("Read %ld bytes\n", count);
time_t t2 = time(NULL);
printf("%ld seconds elapsed\n", (long)(t2-t1));
} else {
perror(path);
}
#endif
return 0;
}
|
the_stack_data/556878.c | #include <stdio.h>
int main(){
float cel,far;
scanf("%f",&cel);
far=(9*cel/4)+32;
printf("%f\n",far);
return 0;
}
|
the_stack_data/18889126.c | /* $OpenBSD: strtonum.c,v 1.7 2013/04/17 18:40:58 tedu Exp $ */
/*
* Copyright (c) 2004 Ted Unangst and Todd Miller
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#define INVALID 1
#define TOOSMALL 2
#define TOOLARGE 3
long long
strtonum(const char *numstr, long long minval, long long maxval,
const char **errstrp)
{
long long ll = 0;
int error = 0;
char *ep;
struct errval {
const char *errstr;
int err;
} ev[4] = {
{ NULL, 0 },
{ "invalid", EINVAL },
{ "too small", ERANGE },
{ "too large", ERANGE },
};
ev[0].err = errno;
errno = 0;
if (minval > maxval) {
error = INVALID;
} else {
ll = strtoll(numstr, &ep, 10);
if (numstr == ep || *ep != '\0')
error = INVALID;
else if ((ll == LLONG_MIN && errno == ERANGE) || ll < minval)
error = TOOSMALL;
else if ((ll == LLONG_MAX && errno == ERANGE) || ll > maxval)
error = TOOLARGE;
}
if (errstrp != NULL)
*errstrp = ev[error].errstr;
errno = ev[error].err;
if (error)
ll = 0;
return (ll);
}
|
the_stack_data/176706217.c | /*
============================================================================
Name : guia_ejercicios1b.c
Author : Luis Alvarez
Version :
Copyright : GNU
Description : Hello World in C, Ansi-style
============================================================================
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void string_concat_dinamyc(const char*, const char*, char**);
int main(void) {
char* b = "Juan Carlos!";
char* c;
string_concat_dinamyc("Hola ", b, &c); //c es un puntero, &c es doble indireccion (puntero a un puntero de char), para poder pisar c, porque se pasa por valor caso contrario.
printf("%s\n", c);
free(c);
return EXIT_SUCCESS;
}
/**
* string_concat_dinmyc
* @param char* a: string a concatenar
* @param char* b: string a concatenar
* @param char** dest: Destino que va a contener la union de a y b. Es una doble indireccion (puntero a un puntero de char{string}). Es asi para poder cambiar el puntero no inicializado por uno inicializado por malloc.
*/
void string_concat_dinamyc(const char* a, const char* b , char** dest ) {
int sizeOfA = sizeof(char) * strlen(a);
int sizeOfB = sizeof(char) * strlen(b);
//malloc devuelve un puntero nuevo con el espacio reservado en memoria, y pisa el puntero no inicializado que recibimos.
*dest = malloc(sizeOfA + sizeOfB + 1);
//se copia el contenido de a y b en *dest
strcat(*dest, a);
strcat(*dest, b);
}
|
the_stack_data/170454204.c | /*
Domingo de Manhã
https://www.urionlinejudge.com.br/judge/pt/problems/view/2003
*/
#include <stdio.h>
void imprimirAtrasoMaximo(int hora, int minuto);
int main (void) {
int hora,
minuto;
while (scanf("%d:%d\n", &hora, &minuto) != EOF) {
imprimirAtrasoMaximo(hora, minuto);
}
return 0;
}
void imprimirAtrasoMaximo(int hora, int minuto) {
hora += 1;
if (hora >= 8) {
printf("Atraso maximo: %d\n", (hora - 8) * 60 + minuto);
}
else {
printf("Atraso maximo: 0\n");
}
}
|
the_stack_data/91469.c | /**
******************************************************************************
* @file stm32g4xx_ll_opamp.c
* @author MCD Application Team
* @brief OPAMP LL module driver
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2019 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
#if defined(USE_FULL_LL_DRIVER)
/* Includes ------------------------------------------------------------------*/
#include "stm32g4xx_ll_opamp.h"
#ifdef USE_FULL_ASSERT
#include "stm32_assert.h"
#else
#define assert_param(expr) ((void)0U)
#endif
/** @addtogroup STM32G4xx_LL_Driver
* @{
*/
#if defined (OPAMP1) || defined (OPAMP2) || defined (OPAMP3) || defined (OPAMP4) || defined (OPAMP5) || defined (OPAMP6)
/** @addtogroup OPAMP_LL OPAMP
* @{
*/
/* Private types -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private constants ---------------------------------------------------------*/
/* Private macros ------------------------------------------------------------*/
/** @addtogroup OPAMP_LL_Private_Macros
* @{
*/
/* Check of parameters for configuration of OPAMP hierarchical scope: */
/* OPAMP instance. */
#define IS_LL_OPAMP_POWER_MODE(__POWER_MODE__) \
( ((__POWER_MODE__) == LL_OPAMP_POWERMODE_NORMAL) \
|| ((__POWER_MODE__) == LL_OPAMP_POWERMODE_HIGHSPEED))
#define IS_LL_OPAMP_FUNCTIONAL_MODE(__FUNCTIONAL_MODE__) \
( ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_STANDALONE) \
|| ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_FOLLOWER) \
|| ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_PGA) \
|| ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_PGA_IO0) \
|| ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_PGA_IO0_BIAS) \
|| ((__FUNCTIONAL_MODE__) == LL_OPAMP_MODE_PGA_IO0_IO1_BIAS) \
)
#define IS_LL_OPAMP_INPUT_NONINVERTING(__INPUT_NONINVERTING__) \
( ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINVERT_IO0) \
|| ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINVERT_IO1) \
|| ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINVERT_IO2) \
|| ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINVERT_IO3) \
|| ((__INPUT_NONINVERTING__) == LL_OPAMP_INPUT_NONINVERT_DAC) \
)
#define IS_LL_OPAMP_INPUT_INVERTING(__INPUT_INVERTING__) \
( ((__INPUT_INVERTING__) == LL_OPAMP_INPUT_INVERT_IO0) \
|| ((__INPUT_INVERTING__) == LL_OPAMP_INPUT_INVERT_IO1) \
|| ((__INPUT_INVERTING__) == LL_OPAMP_INPUT_INVERT_CONNECT_NO) \
)
/**
* @}
*/
/* Private function prototypes -----------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
/** @addtogroup OPAMP_LL_Exported_Functions
* @{
*/
/** @addtogroup OPAMP_LL_EF_Init
* @{
*/
/**
* @brief De-initialize registers of the selected OPAMP instance
* to their default reset values.
* @note If comparator is locked, de-initialization by software is
* not possible.
* The only way to unlock the comparator is a device hardware reset.
* @param OPAMPx OPAMP instance
* @retval An ErrorStatus enumeration value:
* - SUCCESS: OPAMP registers are de-initialized
* - ERROR: OPAMP registers are not de-initialized
*/
ErrorStatus LL_OPAMP_DeInit(OPAMP_TypeDef *OPAMPx)
{
ErrorStatus status = SUCCESS;
/* Check the parameters */
assert_param(IS_OPAMP_ALL_INSTANCE(OPAMPx));
/* Note: Hardware constraint (refer to description of this function): */
/* OPAMP instance must not be locked. */
if (LL_OPAMP_IsLocked(OPAMPx) == 0UL)
{
LL_OPAMP_WriteReg(OPAMPx, CSR, 0x00000000UL);
}
else
{
/* OPAMP instance is locked: de-initialization by software is */
/* not possible. */
/* The only way to unlock the OPAMP is a device hardware reset. */
status = ERROR;
}
/* Timer controlled mux mode register reset */
if (LL_OPAMP_IsTimerMuxLocked(OPAMPx) == 0UL)
{
LL_OPAMP_WriteReg(OPAMPx, TCMR, 0x00000000UL);
}
else if (LL_OPAMP_ReadReg(OPAMPx, TCMR) != 0x80000000UL)
{
/* OPAMP instance timer controlled mux is locked configured, deinit error */
/* The only way to unlock the OPAMP is a device hardware reset. */
status = ERROR;
}
else
{
/* OPAMP instance timer controlled mux is locked unconfigured, deinit OK */
}
return status;
}
/**
* @brief Initialize some features of OPAMP instance.
* @note This function reset bit of calibration mode to ensure
* to be in functional mode, in order to have OPAMP parameters
* (inputs selection, ...) set with the corresponding OPAMP mode
* to be effective.
* @param OPAMPx OPAMP instance
* @param OPAMP_InitStruct Pointer to a @ref LL_OPAMP_InitTypeDef structure
* @retval An ErrorStatus enumeration value:
* - SUCCESS: OPAMP registers are initialized
* - ERROR: OPAMP registers are not initialized
*/
ErrorStatus LL_OPAMP_Init(OPAMP_TypeDef *OPAMPx, LL_OPAMP_InitTypeDef *OPAMP_InitStruct)
{
ErrorStatus status = SUCCESS;
/* Check the parameters */
assert_param(IS_OPAMP_ALL_INSTANCE(OPAMPx));
assert_param(IS_LL_OPAMP_POWER_MODE(OPAMP_InitStruct->PowerMode));
assert_param(IS_LL_OPAMP_FUNCTIONAL_MODE(OPAMP_InitStruct->FunctionalMode));
assert_param(IS_LL_OPAMP_INPUT_NONINVERTING(OPAMP_InitStruct->InputNonInverting));
/* Note: OPAMP inverting input can be used with OPAMP in mode standalone */
/* or PGA with external capacitors for filtering circuit. */
/* Otherwise (OPAMP in mode follower), OPAMP inverting input is */
/* not used (not connected to GPIO pin). */
if (OPAMP_InitStruct->FunctionalMode != LL_OPAMP_MODE_FOLLOWER)
{
assert_param(IS_LL_OPAMP_INPUT_INVERTING(OPAMP_InitStruct->InputInverting));
}
/* Note: Hardware constraint (refer to description of this function): */
/* OPAMP instance must not be locked. */
if (LL_OPAMP_IsLocked(OPAMPx) == 0U)
{
/* Configuration of OPAMP instance : */
/* - PowerMode */
/* - Functional mode */
/* - Input non-inverting */
/* - Input inverting */
/* Note: Bit OPAMP_CSR_CALON reset to ensure to be in functional mode. */
if (OPAMP_InitStruct->FunctionalMode != LL_OPAMP_MODE_FOLLOWER)
{
MODIFY_REG(OPAMPx->CSR,
OPAMP_CSR_HIGHSPEEDEN
| OPAMP_CSR_CALON
| OPAMP_CSR_VMSEL
| OPAMP_CSR_VPSEL
| OPAMP_CSR_PGGAIN_4 | OPAMP_CSR_PGGAIN_3
,
OPAMP_InitStruct->PowerMode
| OPAMP_InitStruct->FunctionalMode
| OPAMP_InitStruct->InputNonInverting
| OPAMP_InitStruct->InputInverting
);
}
else
{
MODIFY_REG(OPAMPx->CSR,
OPAMP_CSR_HIGHSPEEDEN
| OPAMP_CSR_CALON
| OPAMP_CSR_VMSEL
| OPAMP_CSR_VPSEL
| OPAMP_CSR_PGGAIN_4 | OPAMP_CSR_PGGAIN_3
,
OPAMP_InitStruct->PowerMode
| LL_OPAMP_MODE_FOLLOWER
| OPAMP_InitStruct->InputNonInverting
);
}
}
else
{
/* Initialization error: OPAMP instance is locked. */
status = ERROR;
}
return status;
}
/**
* @brief Set each @ref LL_OPAMP_InitTypeDef field to default value.
* @param OPAMP_InitStruct pointer to a @ref LL_OPAMP_InitTypeDef structure
* whose fields will be set to default values.
* @retval None
*/
void LL_OPAMP_StructInit(LL_OPAMP_InitTypeDef *OPAMP_InitStruct)
{
/* Set OPAMP_InitStruct fields to default values */
OPAMP_InitStruct->PowerMode = LL_OPAMP_POWERMODE_NORMAL;
OPAMP_InitStruct->FunctionalMode = LL_OPAMP_MODE_FOLLOWER;
OPAMP_InitStruct->InputNonInverting = LL_OPAMP_INPUT_NONINVERT_IO0;
/* Note: Parameter discarded if OPAMP in functional mode follower, */
/* set anyway to its default value. */
OPAMP_InitStruct->InputInverting = LL_OPAMP_INPUT_INVERT_CONNECT_NO;
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#endif /* OPAMP1 || OPAMP2 || OPAMP3 || OPAMP4 || OPAMP5 || OPAMP6 */
/**
* @}
*/
#endif /* USE_FULL_LL_DRIVER */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
the_stack_data/36075997.c | //AI ASSIGNMENT
//TEAM MEMBERS:-
//(1) ANIRUDH KANNAN V P (201601004)
//(2) SAHITHI KRISHNA KOTTE (201601045)
#include <time.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
int totalnoofnodes=0;
//TOTAL TIME
clock_t start,end;
//NODE STRUCTURE
typedef struct node{
int cost,level;
int board[4][4];
int visited;
struct node * next;
struct node * parent;
} node;
struct node * closed;
struct node * open;
struct node *rearopen;
struct node *rearclosed;
struct node *headopen;
struct node *headclosed;
struct node *rearclosed1;
//FIND THE TILE-(2 ND ) HEURISTIC
int findtile(int no,int x,int y,int arr[4][4]){
int i,j;
for (i = 0; i < 4; ++i)
{
for (j = 0; j < 4; ++j)
{
if(arr[i][j]==no){
return abs(x-i)+abs(y-j);
}
}
}
return 0;
}
// NO OF TILES AWAY FROM GOAL- (2)ND HEURISTIC
int noawayfromgoal(int arr[4][4]){
int c=0,temp;
int completed[4][4]={{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,0}};
int i,j;
for (i = 0; i<4 ;++i)
{
for (j = 0; j < 4 ; ++j)
{
temp=completed[i][j];
c+=findtile(temp,i,j,arr);
}
}
return c;
}
node * newnode;
//CHECKING WHETHER DUPLICATE EXISTS BY CHECKING MATRIX
bool checkw(int board[4][4]){
node * temp=headclosed;
while(temp!=NULL){
int k=0,j,i;
for(i=0;i<4;i++){
for(j=0;j<4;j++){
if(board[i][j]==temp->board[i][j]){
k++;
}
}
}
if(k==16)
return true;
temp=temp->next;
}
return false;
}
//PRINTING THE BOARD
void print1(int board[4][4]){
int i,j;
printf("\n-----------------\n");
for(i=0;i<4;i++){
for(j=0;j<4;j++){
printf("%d ",board[i][j]);
}
printf("\n");
}
printf("\n-----------------\n");
return;
}
void printc(){
int completed[4][4]={{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,0}},i,j;
for (i = 0; i < 4; ++i)
{
for (j = 0; j < 4; ++j)
{
printf("%d ",completed[i][j]);
}
printf("\n");
}
return;
}
//ADD LEFT TILE.
void addleft(int board[4][4],int x,int y,int level,node * temp){
int i,j,stemp;
if(y==0)return;
newnode=(node*)malloc(sizeof(node));
for(i=0;i<4;i++){
for(j=0;j<4;j++){
newnode->board[i][j]=board[i][j];
}
}
stemp=newnode->board[x][y];
newnode->board[x][y]=newnode->board[x][y-1];
newnode->board[x][y-1]=stemp;
newnode->level=level+1;
newnode->cost=noawayfromgoal(newnode->board)+newnode->level;
newnode->next=NULL;
newnode->parent=temp;
if(checkw(newnode->board))
return;
totalnoofnodes+=1;
node *temphead=headopen;
node *temphead1=headopen;
int yu=0;
while(temphead!=NULL){
yu+=1;
//HIGHER LIMIT TO AVOID SEGMENTATION ERROR
if(yu==237){
printc();
end=clock();
double totaltime=((double)(end-start))/CLOCKS_PER_SEC;
printf("TOTAL TIME IS:- %lf\n",totaltime);
printf("TOTAL NO OF NODES IS: %d\n",totalnoofnodes);
exit(0);
}
if(temphead->cost>newnode->cost && temphead==headopen){
newnode->next=temphead;
headopen=newnode;
}
if(temphead->cost<=newnode->cost){;
temphead1=temphead;
temphead=temphead->next;
}
else{
temphead1->next=newnode;
newnode->next=temphead;
print1(newnode->board);
return;
}
}
temphead1->next=newnode;
newnode->next=NULL;
print1(newnode->board);
return;
}
//ADD RIGHTTILE
void addright(int board[4][4],int x,int y,int level,node * temp){
int i,j,stemp;
if(y==3)return;
newnode=(node*)malloc(sizeof(node));
for(i=0;i<4;i++){
for(j=0;j<4;j++){
newnode->board[i][j]=board[i][j];
}
}
stemp=newnode->board[x][y];
newnode->board[x][y]=newnode->board[x][y+1];
newnode->board[x][y+1]=stemp;
newnode->level=level+1;
newnode->cost=noawayfromgoal(newnode->board)+newnode->level;
newnode->next=NULL;
newnode->parent=temp;
if(checkw(newnode->board))
return;
totalnoofnodes+=1;
node *temphead=headopen;
node *temphead1=headopen;
int yu=0;
while(temphead!=NULL){
yu+=1;
//HIGHER LIMIT TO AVOID SEGMENTATION ERROR
if(yu==237){
printc();
end=clock();
double totaltime=((double)(end-start))/CLOCKS_PER_SEC;
printf("TOTAL TIME IS:- %lf\n",totaltime);
printf("TOTAL NO OF NODES IS: %d\n",totalnoofnodes);
exit(0);
}
if(temphead->cost>newnode->cost && temphead==headopen){
newnode->next=temphead;
headopen=newnode;
}
if(temphead->cost<=newnode->cost){
temphead1=temphead;
temphead=temphead->next;
}
else{
temphead1->next=newnode;
newnode->next=temphead;
print1(newnode->board);
return;
}
}
temphead1->next=newnode;
newnode->next=NULL;
newnode->next=NULL;
print1(newnode->board);
return;
}
//ADD UP TILE
void addup(int board[4][4],int x,int y,int level,node * temp){
int i,j,stemp;
if(x==0)return;
newnode=(node*)malloc(sizeof(node));
for(i=0;i<4;i++){
for(j=0;j<4;j++){
newnode->board[i][j]=board[i][j];
}
}
stemp=newnode->board[x][y];
newnode->board[x][y]=newnode->board[x-1][y];
newnode->board[x-1][y]=stemp;
newnode->level=level+1;
newnode->cost=noawayfromgoal(newnode->board)+newnode->level;
newnode->next=NULL;
newnode->parent=temp;
if(checkw(newnode->board))
return;
totalnoofnodes+=1;
node *temphead=headopen;
node *temphead1=headopen;
int yu=0;
while(temphead!=NULL){
yu+=1;
//HIGHER LIMIT TO AVOID SEGMENTATION ERROR
if(yu==237){
printc();
end=clock();
double totaltime=((double)(end-start))/CLOCKS_PER_SEC;
printf("TOTAL TIME IS:- %lf\n",totaltime);
printf("TOTAL NO OF NODES IS: %d\n",totalnoofnodes);
exit(0);
}
if(temphead->cost>newnode->cost && temphead==headopen){
newnode->next=temphead;
headopen=newnode;
}
if(temphead->cost<=newnode->cost){
temphead1=temphead;
temphead=temphead->next;
}
else{
temphead1->next=newnode;
newnode->next=temphead;
print1(newnode->board);
return;
}
}
temphead1->next=newnode;
newnode->next=NULL;
print1(newnode->board);
return;
}
//ADD DOWN TILE
void addown(int board[4][4],int x,int y,int level,node * temp){
int i,j,stemp;
if(x==3)return;
newnode=(node*)malloc(sizeof(node));
for(i=0;i<4;i++){
for(j=0;j<4;j++){
newnode->board[i][j]=board[i][j];
}
}
stemp=newnode->board[x][y];
newnode->board[x][y]=newnode->board[x+1][y];
newnode->board[x+1][y]=stemp;
newnode->level=level+1;
newnode->cost=noawayfromgoal(newnode->board)+newnode->level;
newnode->next=NULL;
newnode->parent=temp;
if(checkw(newnode->board))
return;
totalnoofnodes+=1;
node *temphead=headopen;
node *temphead1=headopen;
int yu=0;
while(temphead!=NULL){
yu+=1;
//HIGHER LIMIT TO AVOID SEGMENTATION ERROR
if(yu==237){
printc();
end=clock();
double totaltime=((double)(end-start))/CLOCKS_PER_SEC;
printf("TOTAL TIME IS:- %lf\n",totaltime);
printf("TOTAL NO OF NODES IS: %d\n",totalnoofnodes);
exit(0);
}
if(temphead->cost>newnode->cost && temphead==headopen){
newnode->next=temphead;
headopen=newnode;
}
if(temphead->cost<=newnode->cost){
temphead1=temphead;
temphead=temphead->next;
}
else{
temphead1->next=newnode;
newnode->next=temphead;
print1(newnode->board);
return;
}
}
temphead1->next=newnode;
newnode->next=NULL;
print1(newnode->board);
return;
}
// EXPANDING NODES CHILDREN
void expand(node * temp){
int board[4][4],i,j,x,y,stemp;
for(i=0;i<4;i++){
for(j=0;j<4;j++){
board[i][j]=temp->board[i][j];
if(board[i][j]==0){
x=i;
y=j;
}
}
}
//HIGHER LIMIT TO AVOID SEGMENTATION ERROR
if(totalnoofnodes==123){
printc();
end=clock();
double totaltime=((double)(end-start))/CLOCKS_PER_SEC;
printf("TOTAL TIME IS:- %lf\n",totaltime);
printf("TOTAL NO OF NODES IS: %d\n",totalnoofnodes);
exit(0);
}
addleft(board,x,y,temp->level,temp);
addright(board,x,y,temp->level,temp);
addown(board,x,y,temp->level,temp);
return;
}
//CHECKING WHETHER 2 MATRIX ARE EQUAL
bool checkmatrixn(node *a,node *b){
int i,j,k=0;
for(i=0;i<4;i++){
for(j=0;j<4;j++){
if(a->board[i][j]==b->board[i][j]){
k++;
}
}
}
if(k==16)
return true;
return false;
}
//TO CHECK WHETHER SOLUTION EXISTS OR NOT
int getinversionspairs(int arr[]){
int invpairs_count=0,i,j;
for(i=0;i<15;i++){
for(j=i+1;j<16;j++){
if(arr[j] && arr[i] && arr[i]>arr[j])
invpairs_count+=1;
}
}
return invpairs_count;
}
//TO CHECK WHETHER SOLUTION EXISTS OR NOT
int findxpositiofrombottom(int board[4][4]){
int i,j;
for(i=3;i>=0;i--){
for(j=3;j>=0;j--){
if(board[i][j]==0)
return 4-i;
}
}
}
//TO CHECK WHETHER SOLUTION EXISTS OR NOT
bool issolvable(int board[4][4]){
int invcount=getinversionspairs((int *) board);
int position=findxpositiofrombottom(board);
if(position & 1)
return !(invcount & 1);
else
return invcount & 1;
}
int main(){
//clock_t start,end;
start=clock();
double totaltime;
//int initial[4][4]={{1,0,3,4},{6,2,7,8},{5,10,11,12},{9,13,14,15}};
int initial[4][4],i,j;
printf("ENTER THE INITIAL MATRIX TO COMPUTE THE SOLUTION USING A* ALGORITHM: \n");
for(i=0;i<4;i++){
for(j=0;j<4;j++){
scanf("%d",&initial[i][j]);
}
}
if(!issolvable(initial)){
printf("NO SOLUTION EXISTS\n");
end=clock();
totaltime=((double)(end-start))/CLOCKS_PER_SEC;
printf("TOTAL TIME IS:- %lf\n",totaltime);
printf("TOTAL NO OF NODES IS: %d\n",totalnoofnodes);
return 0;
}
printf("\n\n\nSOLUTION IS:-\n\n\n");
closed=(node*)malloc(sizeof(node));
rearclosed=closed;
headclosed=closed;
open=(node*)malloc(sizeof(node));
open->cost=noawayfromgoal(initial)+0;
open->level=0;
open->parent=NULL;
for(i=0;i<4;i++){
for(j=0;j<4;j++){
open->board[i][j]=initial[i][j];
}
}
open->next=NULL;
headopen=open;
rearopen=open;
while(noawayfromgoal(headopen->board)){
expand(headopen);
rearclosed1=(node*)malloc(sizeof(node));
for(i=0;i<4;i++){
for(j=0;j<4;j++){
rearclosed1->board[i][j]=headopen->board[i][j];
}
}
rearclosed1->cost=headopen->cost;
rearclosed1->level=headopen->level;
rearclosed1->next=NULL;
rearclosed1->parent=headopen->parent;
rearclosed->next=rearclosed1;
rearclosed=rearclosed1;
headopen=headopen->next;
}
end=clock();
totaltime=((double)(end-start))/CLOCKS_PER_SEC;
printf("TOTAL TIME IS:- %lf\n",totaltime);
printf("TOTAL NO OF NODES IS: %d\n",totalnoofnodes);
return 0;
}
|
the_stack_data/11076528.c | // general protection fault in dst_dev_put (2)
// https://syzkaller.appspot.com/bug?id=2d6a9427fceb9941d6d87128130babe7e40baba0
// status:fixed
// autogenerated by syzkaller (https://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <arpa/inet.h>
#include <endian.h>
#include <errno.h>
#include <fcntl.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <netinet/in.h>
#include <sched.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/mount.h>
#include <sys/prctl.h>
#include <sys/resource.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <sys/wait.h>
#include <unistd.h>
#include <linux/capability.h>
#include <linux/genetlink.h>
#include <linux/if_addr.h>
#include <linux/if_ether.h>
#include <linux/if_link.h>
#include <linux/if_tun.h>
#include <linux/in6.h>
#include <linux/ip.h>
#include <linux/neighbour.h>
#include <linux/net.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
#include <linux/tcp.h>
#include <linux/veth.h>
unsigned long long procid;
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;
}
static struct {
char* pos;
int nesting;
struct nlattr* nested[8];
char buf[1024];
} nlmsg;
static void netlink_init(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(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 void netlink_nest(int typ)
{
struct nlattr* attr = (struct nlattr*)nlmsg.pos;
attr->nla_type = typ;
nlmsg.pos += sizeof(*attr);
nlmsg.nested[nlmsg.nesting++] = attr;
}
static void netlink_done(void)
{
struct nlattr* attr = nlmsg.nested[--nlmsg.nesting];
attr->nla_len = nlmsg.pos - (char*)attr;
}
static int netlink_send(int sock)
{
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 (n < sizeof(struct nlmsghdr) + sizeof(struct nlmsgerr))
exit(1);
if (hdr->nlmsg_type != NLMSG_ERROR)
exit(1);
return -((struct nlmsgerr*)(hdr + 1))->error;
}
static void netlink_add_device_impl(const char* type, const char* name)
{
struct ifinfomsg hdr;
memset(&hdr, 0, sizeof(hdr));
netlink_init(RTM_NEWLINK, NLM_F_EXCL | NLM_F_CREATE, &hdr, sizeof(hdr));
if (name)
netlink_attr(IFLA_IFNAME, name, strlen(name));
netlink_nest(IFLA_LINKINFO);
netlink_attr(IFLA_INFO_KIND, type, strlen(type));
}
static void netlink_add_device(int sock, const char* type, const char* name)
{
netlink_add_device_impl(type, name);
netlink_done();
int err = netlink_send(sock);
(void)err;
}
static void netlink_add_veth(int sock, const char* name, const char* peer)
{
netlink_add_device_impl("veth", name);
netlink_nest(IFLA_INFO_DATA);
netlink_nest(VETH_INFO_PEER);
nlmsg.pos += sizeof(struct ifinfomsg);
netlink_attr(IFLA_IFNAME, peer, strlen(peer));
netlink_done();
netlink_done();
netlink_done();
int err = netlink_send(sock);
(void)err;
}
static void netlink_add_hsr(int sock, const char* name, const char* slave1,
const char* slave2)
{
netlink_add_device_impl("hsr", name);
netlink_nest(IFLA_INFO_DATA);
int ifindex1 = if_nametoindex(slave1);
netlink_attr(IFLA_HSR_SLAVE1, &ifindex1, sizeof(ifindex1));
int ifindex2 = if_nametoindex(slave2);
netlink_attr(IFLA_HSR_SLAVE2, &ifindex2, sizeof(ifindex2));
netlink_done();
netlink_done();
int err = netlink_send(sock);
(void)err;
}
static void netlink_device_change(int sock, const char* name, bool up,
const char* master, const void* mac,
int macsize)
{
struct ifinfomsg hdr;
memset(&hdr, 0, sizeof(hdr));
if (up)
hdr.ifi_flags = hdr.ifi_change = IFF_UP;
netlink_init(RTM_NEWLINK, 0, &hdr, sizeof(hdr));
netlink_attr(IFLA_IFNAME, name, strlen(name));
if (master) {
int ifindex = if_nametoindex(master);
netlink_attr(IFLA_MASTER, &ifindex, sizeof(ifindex));
}
if (macsize)
netlink_attr(IFLA_ADDRESS, mac, macsize);
int err = netlink_send(sock);
(void)err;
}
static int netlink_add_addr(int sock, const char* dev, const void* addr,
int addrsize)
{
struct ifaddrmsg hdr;
memset(&hdr, 0, sizeof(hdr));
hdr.ifa_family = addrsize == 4 ? AF_INET : AF_INET6;
hdr.ifa_prefixlen = addrsize == 4 ? 24 : 120;
hdr.ifa_scope = RT_SCOPE_UNIVERSE;
hdr.ifa_index = if_nametoindex(dev);
netlink_init(RTM_NEWADDR, NLM_F_CREATE | NLM_F_REPLACE, &hdr, sizeof(hdr));
netlink_attr(IFA_LOCAL, addr, addrsize);
netlink_attr(IFA_ADDRESS, addr, addrsize);
return netlink_send(sock);
}
static void netlink_add_addr4(int sock, const char* dev, const char* addr)
{
struct in_addr in_addr;
inet_pton(AF_INET, addr, &in_addr);
int err = netlink_add_addr(sock, dev, &in_addr, sizeof(in_addr));
(void)err;
}
static void netlink_add_addr6(int sock, const char* dev, const char* addr)
{
struct in6_addr in6_addr;
inet_pton(AF_INET6, addr, &in6_addr);
int err = netlink_add_addr(sock, dev, &in6_addr, sizeof(in6_addr));
(void)err;
}
static void netlink_add_neigh(int sock, const char* name, const void* addr,
int addrsize, const void* mac, int macsize)
{
struct ndmsg hdr;
memset(&hdr, 0, sizeof(hdr));
hdr.ndm_family = addrsize == 4 ? AF_INET : AF_INET6;
hdr.ndm_ifindex = if_nametoindex(name);
hdr.ndm_state = NUD_PERMANENT;
netlink_init(RTM_NEWNEIGH, NLM_F_EXCL | NLM_F_CREATE, &hdr, sizeof(hdr));
netlink_attr(NDA_DST, addr, addrsize);
netlink_attr(NDA_LLADDR, mac, macsize);
int err = netlink_send(sock);
(void)err;
}
static int tunfd = -1;
static int tun_frags_enabled;
#define SYZ_TUN_MAX_PACKET_SIZE 1000
#define TUN_IFACE "syz_tun"
#define LOCAL_MAC 0xaaaaaaaaaaaa
#define REMOTE_MAC 0xaaaaaaaaaabb
#define LOCAL_IPV4 "172.20.20.170"
#define REMOTE_IPV4 "172.20.20.187"
#define LOCAL_IPV6 "fe80::aa"
#define REMOTE_IPV6 "fe80::bb"
#define IFF_NAPI 0x0010
#define IFF_NAPI_FRAGS 0x0020
static void initialize_tun(void)
{
tunfd = open("/dev/net/tun", O_RDWR | O_NONBLOCK);
if (tunfd == -1) {
printf("tun: can't open /dev/net/tun: please enable CONFIG_TUN=y\n");
printf("otherwise fuzzing or reproducing might not work as intended\n");
return;
}
const int kTunFd = 240;
if (dup2(tunfd, kTunFd) < 0)
exit(1);
close(tunfd);
tunfd = kTunFd;
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, TUN_IFACE, IFNAMSIZ);
ifr.ifr_flags = IFF_TAP | IFF_NO_PI | IFF_NAPI | IFF_NAPI_FRAGS;
if (ioctl(tunfd, TUNSETIFF, (void*)&ifr) < 0) {
ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
if (ioctl(tunfd, TUNSETIFF, (void*)&ifr) < 0)
exit(1);
}
if (ioctl(tunfd, TUNGETIFF, (void*)&ifr) < 0)
exit(1);
tun_frags_enabled = (ifr.ifr_flags & IFF_NAPI_FRAGS) != 0;
char sysctl[64];
sprintf(sysctl, "/proc/sys/net/ipv6/conf/%s/accept_dad", TUN_IFACE);
write_file(sysctl, "0");
sprintf(sysctl, "/proc/sys/net/ipv6/conf/%s/router_solicitations", TUN_IFACE);
write_file(sysctl, "0");
int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (sock == -1)
exit(1);
netlink_add_addr4(sock, TUN_IFACE, LOCAL_IPV4);
netlink_add_addr6(sock, TUN_IFACE, LOCAL_IPV6);
uint64_t macaddr = REMOTE_MAC;
struct in_addr in_addr;
inet_pton(AF_INET, REMOTE_IPV4, &in_addr);
netlink_add_neigh(sock, TUN_IFACE, &in_addr, sizeof(in_addr), &macaddr,
ETH_ALEN);
struct in6_addr in6_addr;
inet_pton(AF_INET6, REMOTE_IPV6, &in6_addr);
netlink_add_neigh(sock, TUN_IFACE, &in6_addr, sizeof(in6_addr), &macaddr,
ETH_ALEN);
macaddr = LOCAL_MAC;
netlink_device_change(sock, TUN_IFACE, true, 0, &macaddr, ETH_ALEN);
close(sock);
}
#define DEV_IPV4 "172.20.20.%d"
#define DEV_IPV6 "fe80::%02hx"
#define DEV_MAC 0x00aaaaaaaaaa
static void initialize_netdevices(void)
{
char netdevsim[16];
sprintf(netdevsim, "netdevsim%d", (int)procid);
struct {
const char* type;
const char* dev;
} devtypes[] = {
{"ip6gretap", "ip6gretap0"}, {"bridge", "bridge0"},
{"vcan", "vcan0"}, {"bond", "bond0"},
{"team", "team0"}, {"dummy", "dummy0"},
{"nlmon", "nlmon0"}, {"caif", "caif0"},
{"batadv", "batadv0"}, {"vxcan", "vxcan1"},
{"netdevsim", netdevsim}, {"veth", 0},
};
const char* devmasters[] = {"bridge", "bond", "team"};
struct {
const char* name;
int macsize;
bool noipv6;
} devices[] = {
{"lo", ETH_ALEN},
{"sit0", 0},
{"bridge0", ETH_ALEN},
{"vcan0", 0, true},
{"tunl0", 0},
{"gre0", 0},
{"gretap0", ETH_ALEN},
{"ip_vti0", 0},
{"ip6_vti0", 0},
{"ip6tnl0", 0},
{"ip6gre0", 0},
{"ip6gretap0", ETH_ALEN},
{"erspan0", ETH_ALEN},
{"bond0", ETH_ALEN},
{"veth0", ETH_ALEN},
{"veth1", ETH_ALEN},
{"team0", ETH_ALEN},
{"veth0_to_bridge", ETH_ALEN},
{"veth1_to_bridge", ETH_ALEN},
{"veth0_to_bond", ETH_ALEN},
{"veth1_to_bond", ETH_ALEN},
{"veth0_to_team", ETH_ALEN},
{"veth1_to_team", ETH_ALEN},
{"veth0_to_hsr", ETH_ALEN},
{"veth1_to_hsr", ETH_ALEN},
{"hsr0", 0},
{"dummy0", ETH_ALEN},
{"nlmon0", 0},
{"vxcan1", 0, true},
{"caif0", ETH_ALEN},
{"batadv0", ETH_ALEN},
{netdevsim, ETH_ALEN},
};
int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (sock == -1)
exit(1);
unsigned i;
for (i = 0; i < sizeof(devtypes) / sizeof(devtypes[0]); i++)
netlink_add_device(sock, devtypes[i].type, devtypes[i].dev);
for (i = 0; i < sizeof(devmasters) / (sizeof(devmasters[0])); i++) {
char master[32], slave0[32], veth0[32], slave1[32], veth1[32];
sprintf(slave0, "%s_slave_0", devmasters[i]);
sprintf(veth0, "veth0_to_%s", devmasters[i]);
netlink_add_veth(sock, slave0, veth0);
sprintf(slave1, "%s_slave_1", devmasters[i]);
sprintf(veth1, "veth1_to_%s", devmasters[i]);
netlink_add_veth(sock, slave1, veth1);
sprintf(master, "%s0", devmasters[i]);
netlink_device_change(sock, slave0, false, master, 0, 0);
netlink_device_change(sock, slave1, false, master, 0, 0);
}
netlink_device_change(sock, "bridge_slave_0", true, 0, 0, 0);
netlink_device_change(sock, "bridge_slave_1", true, 0, 0, 0);
netlink_add_veth(sock, "hsr_slave_0", "veth0_to_hsr");
netlink_add_veth(sock, "hsr_slave_1", "veth1_to_hsr");
netlink_add_hsr(sock, "hsr0", "hsr_slave_0", "hsr_slave_1");
netlink_device_change(sock, "hsr_slave_0", true, 0, 0, 0);
netlink_device_change(sock, "hsr_slave_1", true, 0, 0, 0);
for (i = 0; i < sizeof(devices) / (sizeof(devices[0])); i++) {
char addr[32];
sprintf(addr, DEV_IPV4, i + 10);
netlink_add_addr4(sock, devices[i].name, addr);
if (!devices[i].noipv6) {
sprintf(addr, DEV_IPV6, i + 10);
netlink_add_addr6(sock, devices[i].name, addr);
}
uint64_t macaddr = DEV_MAC + ((i + 10ull) << 40);
netlink_device_change(sock, devices[i].name, true, 0, &macaddr,
devices[i].macsize);
}
close(sock);
}
static void initialize_netdevices_init(void)
{
int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (sock == -1)
exit(1);
struct {
const char* type;
int macsize;
bool noipv6;
bool noup;
} devtypes[] = {
{"nr", 7, true}, {"rose", 5, true, true},
};
unsigned i;
for (i = 0; i < sizeof(devtypes) / sizeof(devtypes[0]); i++) {
char dev[32], addr[32];
sprintf(dev, "%s%d", devtypes[i].type, (int)procid);
sprintf(addr, "172.30.%d.%d", i, (int)procid + 1);
netlink_add_addr4(sock, dev, addr);
if (!devtypes[i].noipv6) {
sprintf(addr, "fe88::%02hx:%02hx", i, (int)procid + 1);
netlink_add_addr6(sock, dev, addr);
}
int macsize = devtypes[i].macsize;
uint64_t macaddr = 0xbbbbbb +
((unsigned long long)i << (8 * (macsize - 2))) +
(procid << (8 * (macsize - 1)));
netlink_device_change(sock, dev, !devtypes[i].noup, 0, &macaddr, macsize);
}
close(sock);
}
static long syz_genetlink_get_family_id(long name)
{
char buf[512] = {0};
struct nlmsghdr* hdr = (struct nlmsghdr*)buf;
struct genlmsghdr* genlhdr = (struct genlmsghdr*)NLMSG_DATA(hdr);
struct nlattr* attr = (struct nlattr*)(genlhdr + 1);
hdr->nlmsg_len =
sizeof(*hdr) + sizeof(*genlhdr) + sizeof(*attr) + GENL_NAMSIZ;
hdr->nlmsg_type = GENL_ID_CTRL;
hdr->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
genlhdr->cmd = CTRL_CMD_GETFAMILY;
attr->nla_type = CTRL_ATTR_FAMILY_NAME;
attr->nla_len = sizeof(*attr) + GENL_NAMSIZ;
strncpy((char*)(attr + 1), (char*)name, GENL_NAMSIZ);
struct iovec iov = {hdr, hdr->nlmsg_len};
struct sockaddr_nl addr = {0};
addr.nl_family = AF_NETLINK;
int fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC);
if (fd == -1) {
return -1;
}
struct msghdr msg = {&addr, sizeof(addr), &iov, 1, NULL, 0, 0};
if (sendmsg(fd, &msg, 0) == -1) {
close(fd);
return -1;
}
ssize_t n = recv(fd, buf, sizeof(buf), 0);
close(fd);
if (n <= 0) {
return -1;
}
if (hdr->nlmsg_type != GENL_ID_CTRL) {
return -1;
}
for (; (char*)attr < buf + n;
attr = (struct nlattr*)((char*)attr + NLMSG_ALIGN(attr->nla_len))) {
if (attr->nla_type == CTRL_ATTR_FAMILY_ID)
return *(uint16_t*)(attr + 1);
}
return -1;
}
static void setup_common()
{
if (mount(0, "/sys/fs/fuse/connections", "fusectl", 0, 0)) {
}
}
static void loop();
static void sandbox_common()
{
prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
setpgrp();
setsid();
struct rlimit rlim;
rlim.rlim_cur = rlim.rlim_max = (200 << 20);
setrlimit(RLIMIT_AS, &rlim);
rlim.rlim_cur = rlim.rlim_max = 32 << 20;
setrlimit(RLIMIT_MEMLOCK, &rlim);
rlim.rlim_cur = rlim.rlim_max = 136 << 20;
setrlimit(RLIMIT_FSIZE, &rlim);
rlim.rlim_cur = rlim.rlim_max = 1 << 20;
setrlimit(RLIMIT_STACK, &rlim);
rlim.rlim_cur = rlim.rlim_max = 0;
setrlimit(RLIMIT_CORE, &rlim);
rlim.rlim_cur = rlim.rlim_max = 256;
setrlimit(RLIMIT_NOFILE, &rlim);
if (unshare(CLONE_NEWNS)) {
}
if (unshare(CLONE_NEWIPC)) {
}
if (unshare(0x02000000)) {
}
if (unshare(CLONE_NEWUTS)) {
}
if (unshare(CLONE_SYSVSEM)) {
}
typedef struct {
const char* name;
const char* value;
} sysctl_t;
static const sysctl_t sysctls[] = {
{"/proc/sys/kernel/shmmax", "16777216"},
{"/proc/sys/kernel/shmall", "536870912"},
{"/proc/sys/kernel/shmmni", "1024"},
{"/proc/sys/kernel/msgmax", "8192"},
{"/proc/sys/kernel/msgmni", "1024"},
{"/proc/sys/kernel/msgmnb", "1024"},
{"/proc/sys/kernel/sem", "1024 1048576 500 1024"},
};
unsigned i;
for (i = 0; i < sizeof(sysctls) / sizeof(sysctls[0]); i++)
write_file(sysctls[i].name, sysctls[i].value);
}
int wait_for_loop(int pid)
{
if (pid < 0)
exit(1);
int status = 0;
while (waitpid(-1, &status, __WALL) != pid) {
}
return WEXITSTATUS(status);
}
static int real_uid;
static int real_gid;
__attribute__((aligned(64 << 10))) static char sandbox_stack[1 << 20];
static int namespace_sandbox_proc(void* arg)
{
sandbox_common();
write_file("/proc/self/setgroups", "deny");
if (!write_file("/proc/self/uid_map", "0 %d 1\n", real_uid))
exit(1);
if (!write_file("/proc/self/gid_map", "0 %d 1\n", real_gid))
exit(1);
initialize_netdevices_init();
if (unshare(CLONE_NEWNET))
exit(1);
initialize_tun();
initialize_netdevices();
if (mkdir("./syz-tmp", 0777))
exit(1);
if (mount("", "./syz-tmp", "tmpfs", 0, NULL))
exit(1);
if (mkdir("./syz-tmp/newroot", 0777))
exit(1);
if (mkdir("./syz-tmp/newroot/dev", 0700))
exit(1);
unsigned bind_mount_flags = MS_BIND | MS_REC | MS_PRIVATE;
if (mount("/dev", "./syz-tmp/newroot/dev", NULL, bind_mount_flags, NULL))
exit(1);
if (mkdir("./syz-tmp/newroot/proc", 0700))
exit(1);
if (mount(NULL, "./syz-tmp/newroot/proc", "proc", 0, NULL))
exit(1);
if (mkdir("./syz-tmp/newroot/selinux", 0700))
exit(1);
const char* selinux_path = "./syz-tmp/newroot/selinux";
if (mount("/selinux", selinux_path, NULL, bind_mount_flags, NULL)) {
if (errno != ENOENT)
exit(1);
if (mount("/sys/fs/selinux", selinux_path, NULL, bind_mount_flags, NULL) &&
errno != ENOENT)
exit(1);
}
if (mkdir("./syz-tmp/newroot/sys", 0700))
exit(1);
if (mount("/sys", "./syz-tmp/newroot/sys", 0, bind_mount_flags, NULL))
exit(1);
if (mkdir("./syz-tmp/pivot", 0777))
exit(1);
if (syscall(SYS_pivot_root, "./syz-tmp", "./syz-tmp/pivot")) {
if (chdir("./syz-tmp"))
exit(1);
} else {
if (chdir("/"))
exit(1);
if (umount2("./pivot", MNT_DETACH))
exit(1);
}
if (chroot("./newroot"))
exit(1);
if (chdir("/"))
exit(1);
struct __user_cap_header_struct cap_hdr = {};
struct __user_cap_data_struct cap_data[2] = {};
cap_hdr.version = _LINUX_CAPABILITY_VERSION_3;
cap_hdr.pid = getpid();
if (syscall(SYS_capget, &cap_hdr, &cap_data))
exit(1);
cap_data[0].effective &= ~(1 << CAP_SYS_PTRACE);
cap_data[0].permitted &= ~(1 << CAP_SYS_PTRACE);
cap_data[0].inheritable &= ~(1 << CAP_SYS_PTRACE);
if (syscall(SYS_capset, &cap_hdr, &cap_data))
exit(1);
loop();
exit(1);
}
#define SYZ_HAVE_SANDBOX_NAMESPACE 1
static int do_sandbox_namespace(void)
{
int pid;
setup_common();
real_uid = getuid();
real_gid = getgid();
mprotect(sandbox_stack, 4096, PROT_NONE);
pid =
clone(namespace_sandbox_proc, &sandbox_stack[sizeof(sandbox_stack) - 64],
CLONE_NEWUSER | CLONE_NEWPID, 0);
return wait_for_loop(pid);
}
uint64_t r[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0x0};
void loop(void)
{
long res = 0;
res = syscall(__NR_socket, 0x10, 3, 0x10);
if (res != -1)
r[0] = res;
res = syscall(__NR_socket, 2, 2, 0x88);
if (res != -1)
r[1] = res;
syscall(__NR_ioctl, r[1], 0x1000008912, 0);
memcpy((void*)0x20000040, "TIPCv2\000", 7);
res = syz_genetlink_get_family_id(0x20000040);
if (res != -1)
r[2] = res;
*(uint64_t*)0x200000c0 = 0;
*(uint32_t*)0x200000c8 = 0;
*(uint64_t*)0x200000d0 = 0x20000080;
*(uint64_t*)0x20000080 = 0x20000340;
*(uint32_t*)0x20000340 = 0x88;
*(uint16_t*)0x20000344 = r[2];
*(uint16_t*)0x20000346 = 1;
*(uint32_t*)0x20000348 = 0;
*(uint32_t*)0x2000034c = 0;
*(uint8_t*)0x20000350 = 3;
*(uint8_t*)0x20000351 = 0;
*(uint16_t*)0x20000352 = 0;
*(uint16_t*)0x20000354 = 0x10;
*(uint16_t*)0x20000356 = 7;
*(uint16_t*)0x20000358 = 0xc;
*(uint16_t*)0x2000035a = 3;
*(uint64_t*)0x2000035c = 0x1f;
*(uint16_t*)0x20000364 = 0x1c;
*(uint16_t*)0x20000366 = 9;
*(uint16_t*)0x20000368 = 8;
*(uint16_t*)0x2000036a = 1;
*(uint32_t*)0x2000036c = 0x800;
*(uint16_t*)0x20000370 = 8;
*(uint16_t*)0x20000372 = 1;
*(uint32_t*)0x20000374 = 5;
*(uint16_t*)0x20000378 = 8;
*(uint16_t*)0x2000037a = 2;
*(uint32_t*)0x2000037c = 1;
*(uint16_t*)0x20000380 = 0x48;
*(uint16_t*)0x20000382 = 1;
*(uint16_t*)0x20000384 = 0x10;
*(uint16_t*)0x20000386 = 1;
memcpy((void*)0x20000388, "udp:syz1\000", 9);
*(uint16_t*)0x20000394 = 8;
*(uint16_t*)0x20000396 = 3;
*(uint32_t*)0x20000398 = 0x8001;
*(uint16_t*)0x2000039c = 0x2c;
*(uint16_t*)0x2000039e = 4;
*(uint16_t*)0x200003a0 = 0x14;
*(uint16_t*)0x200003a2 = 1;
*(uint16_t*)0x200003a4 = 2;
*(uint16_t*)0x200003a6 = htobe16(0x4e22);
*(uint8_t*)0x200003a8 = 0xac;
*(uint8_t*)0x200003a9 = 0x14;
*(uint8_t*)0x200003aa = 0x14;
*(uint8_t*)0x200003ab = 0xaa;
*(uint16_t*)0x200003b4 = 0x14;
*(uint16_t*)0x200003b6 = 2;
*(uint16_t*)0x200003b8 = 2;
*(uint16_t*)0x200003ba = htobe16(0x4e21);
*(uint8_t*)0x200003bc = 0xac;
*(uint8_t*)0x200003bd = 0x14;
*(uint8_t*)0x200003be = 0x14;
*(uint8_t*)0x200003bf = 0xbb;
*(uint64_t*)0x20000088 = 0x88;
*(uint64_t*)0x200000d8 = 1;
*(uint64_t*)0x200000e0 = 0;
*(uint64_t*)0x200000e8 = 0;
*(uint32_t*)0x200000f0 = 0;
syscall(__NR_sendmsg, r[0], 0x200000c0, 0x10);
}
int main(void)
{
syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0);
use_temporary_dir();
do_sandbox_namespace();
return 0;
}
|
the_stack_data/49725.c | #include<stdio.h>
#include<string.h>
int main()
{
int M1,M2,i;
char ch[201];
while(scanf("%d%d",&M1,&M2)!=EOF)
{
int R1=0,R2=0,R3=0;
scanf("%s",ch);
//printf("%c\n",ch);
for(i=0;i<strlen(ch);i++)
{
if(ch[i]=='A')
R1=M1;
if(ch[i]=='B')
R2=M2;
if(ch[i]=='C')
M1=R3;
if(ch[i]=='D')
M2=R3;
if(ch[i]=='E')
R3=R1+R2;
if(ch[i]=='F')
R3=R1-R2;
}
printf("%d,%d\n",M1,M2);
}
return 0;
}
|
the_stack_data/141294.c | #include <stdio.h>
#include <string.h>
void fit(char *, unsigned int);
int main(void)
{
char mesg[] = "Things should be as simple as possible,"
" but not simpler";
puts(mesg);
fit(mesg, 38);
puts(mesg);
puts("Let's look at some more of the string.");
puts(mesg + 39);
return 0;
}
void fit(char * string, unsigned int size)
{
if (strlen(string) > size)
string[size] = '\0';
} |
the_stack_data/234518889.c | /*
Copyright 2010-2013 SourceGear, LLC
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.
*/
/*
sg_hexdump
*/
#include <stdio.h>
#ifdef WINDOWS
#pragma warning( disable : 4127 ) // conditional expression is constant
#endif
int main(int argc, char** argv)
{
FILE* fp_in = NULL;
FILE* fp_out = NULL;
char buf_name[1024];
int b;
int count = 0;
char* p = NULL;
char* q = NULL;
if (argc != 3)
{
printf("Usage: %s infile outfile\n", argv[0]);
return -1;
}
// find the end of the infile string
p = argv[1];
while (*p)
{
p++;
}
// now go backwards until I find a slash, or the beginning
while (
(p >= argv[1])
&& (*p != '/')
)
{
p--;
}
// if I found a slash, move forward one char
if (*p == '/')
{
p++;
}
// now copy the filename over to buf_name, fixing stuff as we go
q = buf_name;
while (*p)
{
if (
('.' == *p)
|| (' ' == *p)
)
{
*q = '_';
}
else
{
*q = *p;
}
q++;
p++;
}
*q = 0;
#ifdef WINDOWS
fopen_s(&fp_in, argv[1], "r");
fopen_s(&fp_out, argv[2], "w");
#else
fp_in = fopen(argv[1], "r");
fp_out = fopen(argv[2], "w");
#endif
if (!fp_in || !fp_out)
return -1;
fprintf(fp_out, "\n");
fprintf(fp_out, "unsigned char %s[] =\n", buf_name);
fprintf(fp_out, "{\n");
while (1)
{
b = fgetc(fp_in);
if (EOF == b)
{
// TODO check feof
break;
}
if (0 == count)
{
fprintf(fp_out, " ");
}
fprintf(fp_out, "0x%02x, ", b);
count++;
if (8 == count)
{
count = 0;
fprintf(fp_out, "\n");
}
}
fclose(fp_in);
if (count)
{
fprintf(fp_out, "\n");
}
fprintf(fp_out, " 0x00\n};\n\n");
fclose(fp_out);
return 0;
}
|
the_stack_data/22012465.c | /* C Program to Print Prime Numbers between 1 to 100 using For Loop */
#include <stdio.h>
int main()
{
int i, n, count;
printf(" Prime Number from 1 to 1000 are: \n");
for(n= 1; n <= 1000; n++)
{
count = 0;
for (i = 2; i <= n/2; i++)
{
if(n%i == 0)
{
count++;
break;
}
}
if(count == 0 && n != 1 )
{
printf(" %d ", n);
}
}
return 0;
} |
the_stack_data/506430.c | /* PR c/90677 */
/* { dg-do compile } */
/* { dg-options "-W -Wall" } */
extern void foo (int, int, const char *, ...)
__attribute__ ((__format__ (__gcc_tdiag__, 3, 4)));
struct cgraph_node;
extern void bar (struct cgraph_node *);
|
the_stack_data/167329432.c | /* f2c.h -- Standard Fortran to C header file */
/** barf [ba:rf] 2. "He suggested using FORTRAN, and everybody barfed."
- From The Shogakukan DICTIONARY OF NEW ENGLISH (Second edition) */
#ifndef F2C_INCLUDE
#define F2C_INCLUDE
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <complex.h>
#ifdef complex
#undef complex
#endif
#ifdef I
#undef I
#endif
#if defined(_WIN64)
typedef long long BLASLONG;
typedef unsigned long long BLASULONG;
#else
typedef long BLASLONG;
typedef unsigned long BLASULONG;
#endif
#ifdef LAPACK_ILP64
typedef BLASLONG blasint;
#if defined(_WIN64)
#define blasabs(x) llabs(x)
#else
#define blasabs(x) labs(x)
#endif
#else
typedef int blasint;
#define blasabs(x) abs(x)
#endif
typedef blasint integer;
typedef unsigned int uinteger;
typedef char *address;
typedef short int shortint;
typedef float real;
typedef double doublereal;
typedef struct { real r, i; } complex;
typedef struct { doublereal r, i; } doublecomplex;
static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
#define pCf(z) (*_pCf(z))
#define pCd(z) (*_pCd(z))
typedef int logical;
typedef short int shortlogical;
typedef char logical1;
typedef char integer1;
#define TRUE_ (1)
#define FALSE_ (0)
/* Extern is for use with -E */
#ifndef Extern
#define Extern extern
#endif
/* I/O stuff */
typedef int flag;
typedef int ftnlen;
typedef int ftnint;
/*external read, write*/
typedef struct
{ flag cierr;
ftnint ciunit;
flag ciend;
char *cifmt;
ftnint cirec;
} cilist;
/*internal read, write*/
typedef struct
{ flag icierr;
char *iciunit;
flag iciend;
char *icifmt;
ftnint icirlen;
ftnint icirnum;
} icilist;
/*open*/
typedef struct
{ flag oerr;
ftnint ounit;
char *ofnm;
ftnlen ofnmlen;
char *osta;
char *oacc;
char *ofm;
ftnint orl;
char *oblnk;
} olist;
/*close*/
typedef struct
{ flag cerr;
ftnint cunit;
char *csta;
} cllist;
/*rewind, backspace, endfile*/
typedef struct
{ flag aerr;
ftnint aunit;
} alist;
/* inquire */
typedef struct
{ flag inerr;
ftnint inunit;
char *infile;
ftnlen infilen;
ftnint *inex; /*parameters in standard's order*/
ftnint *inopen;
ftnint *innum;
ftnint *innamed;
char *inname;
ftnlen innamlen;
char *inacc;
ftnlen inacclen;
char *inseq;
ftnlen inseqlen;
char *indir;
ftnlen indirlen;
char *infmt;
ftnlen infmtlen;
char *inform;
ftnint informlen;
char *inunf;
ftnlen inunflen;
ftnint *inrecl;
ftnint *innrec;
char *inblank;
ftnlen inblanklen;
} inlist;
#define VOID void
union Multitype { /* for multiple entry points */
integer1 g;
shortint h;
integer i;
/* longint j; */
real r;
doublereal d;
complex c;
doublecomplex z;
};
typedef union Multitype Multitype;
struct Vardesc { /* for Namelist */
char *name;
char *addr;
ftnlen *dims;
int type;
};
typedef struct Vardesc Vardesc;
struct Namelist {
char *name;
Vardesc **vars;
int nvars;
};
typedef struct Namelist Namelist;
#define abs(x) ((x) >= 0 ? (x) : -(x))
#define dabs(x) (fabs(x))
#define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
#define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
#define dmin(a,b) (f2cmin(a,b))
#define dmax(a,b) (f2cmax(a,b))
#define bit_test(a,b) ((a) >> (b) & 1)
#define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
#define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
#define abort_() { sig_die("Fortran abort routine called", 1); }
#define c_abs(z) (cabsf(Cf(z)))
#define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
#define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
#define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
#define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
#define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
#define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
//#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
#define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
#define d_abs(x) (fabs(*(x)))
#define d_acos(x) (acos(*(x)))
#define d_asin(x) (asin(*(x)))
#define d_atan(x) (atan(*(x)))
#define d_atn2(x, y) (atan2(*(x),*(y)))
#define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
#define r_cnjg(R, Z) { pCf(R) = conj(Cf(Z)); }
#define d_cos(x) (cos(*(x)))
#define d_cosh(x) (cosh(*(x)))
#define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
#define d_exp(x) (exp(*(x)))
#define d_imag(z) (cimag(Cd(z)))
#define r_imag(z) (cimag(Cf(z)))
#define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
#define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
#define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
#define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
#define d_log(x) (log(*(x)))
#define d_mod(x, y) (fmod(*(x), *(y)))
#define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
#define d_nint(x) u_nint(*(x))
#define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
#define d_sign(a,b) u_sign(*(a),*(b))
#define r_sign(a,b) u_sign(*(a),*(b))
#define d_sin(x) (sin(*(x)))
#define d_sinh(x) (sinh(*(x)))
#define d_sqrt(x) (sqrt(*(x)))
#define d_tan(x) (tan(*(x)))
#define d_tanh(x) (tanh(*(x)))
#define i_abs(x) abs(*(x))
#define i_dnnt(x) ((integer)u_nint(*(x)))
#define i_len(s, n) (n)
#define i_nint(x) ((integer)u_nint(*(x)))
#define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
#define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
#define pow_si(B,E) spow_ui(*(B),*(E))
#define pow_ri(B,E) spow_ui(*(B),*(E))
#define pow_di(B,E) dpow_ui(*(B),*(E))
#define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
#define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
#define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
#define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
#define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
#define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
#define sig_die(s, kill) { exit(1); }
#define s_stop(s, n) {exit(0);}
static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
#define z_abs(z) (cabs(Cd(z)))
#define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
#define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
#define myexit_() break;
#define mycycle() continue;
#define myceiling(w) {ceil(w)}
#define myhuge(w) {HUGE_VAL}
//#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
#define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
/* procedure parameter types for -A and -C++ */
#define F2C_proc_par_types 1
#ifdef __cplusplus
typedef logical (*L_fp)(...);
#else
typedef logical (*L_fp)();
#endif
static float spow_ui(float x, integer n) {
float pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static double dpow_ui(double x, integer n) {
double pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static _Complex float cpow_ui(_Complex float x, integer n) {
_Complex float pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static _Complex double zpow_ui(_Complex double x, integer n) {
_Complex double pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static integer pow_ii(integer x, integer n) {
integer pow; unsigned long int u;
if (n <= 0) {
if (n == 0 || x == 1) pow = 1;
else if (x != -1) pow = x == 0 ? 1/x : 0;
else n = -n;
}
if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
u = n;
for(pow = 1; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static integer dmaxloc_(double *w, integer s, integer e, integer *n)
{
double m; integer i, mi;
for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
if (w[i-1]>m) mi=i ,m=w[i-1];
return mi-s+1;
}
static integer smaxloc_(float *w, integer s, integer e, integer *n)
{
float m; integer i, mi;
for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
if (w[i-1]>m) mi=i ,m=w[i-1];
return mi-s+1;
}
static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
_Complex float zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
}
}
pCf(z) = zdotc;
}
static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
_Complex double zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
}
}
pCd(z) = zdotc;
}
static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
_Complex float zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cf(&x[i]) * Cf(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
}
}
pCf(z) = zdotc;
}
static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
_Complex double zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cd(&x[i]) * Cd(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
}
}
pCd(z) = zdotc;
}
#endif
/* -- translated by f2c (version 20000121).
You must link the resulting object file with the libraries:
-lf2c -lm (in that order)
*/
/* > \brief \b ILASLC scans a matrix for its last non-zero column. */
/* =========== DOCUMENTATION =========== */
/* Online html documentation available at */
/* http://www.netlib.org/lapack/explore-html/ */
/* > \htmlonly */
/* > Download ILASLC + dependencies */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ilaslc.
f"> */
/* > [TGZ]</a> */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ilaslc.
f"> */
/* > [ZIP]</a> */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ilaslc.
f"> */
/* > [TXT]</a> */
/* > \endhtmlonly */
/* Definition: */
/* =========== */
/* INTEGER FUNCTION ILASLC( M, N, A, LDA ) */
/* INTEGER M, N, LDA */
/* REAL A( LDA, * ) */
/* > \par Purpose: */
/* ============= */
/* > */
/* > \verbatim */
/* > */
/* > ILASLC scans A for its last non-zero column. */
/* > \endverbatim */
/* Arguments: */
/* ========== */
/* > \param[in] M */
/* > \verbatim */
/* > M is INTEGER */
/* > The number of rows of the matrix A. */
/* > \endverbatim */
/* > */
/* > \param[in] N */
/* > \verbatim */
/* > N is INTEGER */
/* > The number of columns of the matrix A. */
/* > \endverbatim */
/* > */
/* > \param[in] A */
/* > \verbatim */
/* > A is REAL array, dimension (LDA,N) */
/* > The m by n matrix A. */
/* > \endverbatim */
/* > */
/* > \param[in] LDA */
/* > \verbatim */
/* > LDA is INTEGER */
/* > The leading dimension of the array A. LDA >= f2cmax(1,M). */
/* > \endverbatim */
/* Authors: */
/* ======== */
/* > \author Univ. of Tennessee */
/* > \author Univ. of California Berkeley */
/* > \author Univ. of Colorado Denver */
/* > \author NAG Ltd. */
/* > \date June 2017 */
/* > \ingroup realOTHERauxiliary */
/* ===================================================================== */
integer ilaslc_(integer *m, integer *n, real *a, integer *lda)
{
/* System generated locals */
integer a_dim1, a_offset, ret_val, i__1;
/* Local variables */
integer i__;
/* -- LAPACK auxiliary routine (version 3.7.1) -- */
/* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
/* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
/* June 2017 */
/* ===================================================================== */
/* Quick test for the common case where one corner is non-zero. */
/* Parameter adjustments */
a_dim1 = *lda;
a_offset = 1 + a_dim1 * 1;
a -= a_offset;
/* Function Body */
if (*n == 0) {
ret_val = *n;
} else if (a[*n * a_dim1 + 1] != 0.f || a[*m + *n * a_dim1] != 0.f) {
ret_val = *n;
} else {
/* Now scan each column from the end, returning with the first non-zero. */
for (ret_val = *n; ret_val >= 1; --ret_val) {
i__1 = *m;
for (i__ = 1; i__ <= i__1; ++i__) {
if (a[i__ + ret_val * a_dim1] != 0.f) {
return ret_val;
}
}
}
}
return ret_val;
} /* ilaslc_ */
|
the_stack_data/182953608.c | // RUN: %clang -### -c -integrated-as -Wa,-compress-debug-sections %s 2>&1 | FileCheck --check-prefix=COMPRESS_DEBUG %s
// RUN: %clang -### -c -integrated-as -Wa,--compress-debug-sections %s 2>&1 | FileCheck --check-prefix=COMPRESS_DEBUG %s
// REQUIRES: zlib
// COMPRESS_DEBUG: "-compress-debug-sections"
// RUN: %clang -### -c -integrated-as -Wa,--compress-debug-sections -Wa,--nocompress-debug-sections %s 2>&1 | FileCheck --check-prefix=NOCOMPRESS_DEBUG %s
// NOCOMPRESS_DEBUG-NOT: "-compress-debug-sections"
|
the_stack_data/198580473.c | //Projeto 001 - modo 04
/*
Este modo mostra algumas diferenças para o tipo char.
1. para apenas um único caractere, usa a formatação %c
2. para 2 ou mais caracteres, usa a formatação %s
%s: é uma formatação para string / cadeia de caracteres
3. No caso de inserir textos, principalmente no mode de entrada, algumas medidas devem ser tomadas e incluída
ao seu código fonte para que tenha êxito no resultado. Mais detalhes serão abordados futuramente em outros projetos.
*/
#include <stdio.h>
int main(){
// variavel do tipo char
char letra = 'A';
char palavra = "casa";
char texto = {"Dia da Independência"};
printf("Um único caractere ..............: %c\n", letra);
printf("Dois oi mais caracteres .........: %s\n", palavra);
printf("Para o texto Dia da Independência: %s\n", texto);
printf("\n");
return 0;
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.