Advertisement
Regazi

zad3

Jun 14th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #include <linux/module.h>
  2. #include <linux/init.h>
  3. #include <linux/string.h>
  4. #include <linux/slab.h>
  5. struct stack_node{
  6. int data;
  7. struct stack_node *nastepny;
  8. } *top = NULL;
  9.  
  10. struct stack_node *push(struct stack_node *top,int data)
  11. { struct stack_node *new_node = (struct stack_node *)kmalloc(sizeof(struct stack_node),GFP_KERNEL);
  12. if(new_node){
  13. new_node->data=data;
  14. new_node->nastepny=top;
  15. top=new_node;}
  16. return top;}
  17.  
  18. int pop(struct stack_node **top){
  19. int temp = -1;
  20. if(top){
  21. temp =(*top)->data;
  22. struct stack_node *tmp=(*top)->nastepny;
  23. kfree(*top);
  24. *top = tmp;}
  25. return temp;}
  26.  
  27. static int __init stack_init(void){
  28. int i = 0;
  29. for(i=0;i<15;i++){
  30. top = push(top,i);}
  31. return 0;}
  32.  
  33. static void __exit stack_exit(void){
  34. while (top != NULL){
  35. printk(KERN_INFO "%d\n\n",pop(&top));}}
  36.  
  37. module_init(stack_init);
  38. module_exit(stack_exit);
  39. MODULE_LICENSE("GPL");
  40. MODULE_AUTHOR("Mateusz Nachyla Mateusz Orlowski");
  41. MODULE_VERSION("1.0");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement