C for Linux

          Session 4

BY:
      Eng.Ahmed Teirelbar
        Software Engineer
        Shuja' Consulting
Your own .so
    gcc line – in the makefile
●


    Versioning
●


    Overview on how it works
●


        Dynamic loader...
Code Organization
    Public/Private includes
●


    Reflection of your abstractions
●


    Delivery: install, lib, bin
●
Multi-file Makefiles
    Example
●


    .h Dependency
●


    Multiple directories
●
Command Line Processing
    argc, argv
●


    usage()
●


    get_opt – libsysfs example
●


        optarg
    –

      ...
File I/O Intro
    FILE * (stream) interface
●


        fopen/fclose
    –

        fread/fwrite    binary
    –

       ...
Function Pointers and Callback
    ret (*name)(args)
●


    Can store (ptr) and execute (fun)
●


    Callback concept
●
...
User Configuration
    Simple guidelines:
●


        Code encapsulates the parsing
    –

        Collect the data once
 ...
Logging
    Your eyes on the software
●


    Debug levels
●


        Run-time (debug.on/msg in xinetd)
    –

        Co...
API Examples – Libsysfs
    Safe string macros
●


    Attr/Device/Bus/Driver/Module structures and
●

    corresponding f...
Linked List
    Concepts
●


        Node
    –

        Next/prev
    –

        Head
    –

        Tail
    –

        ...
Linked List – Cont'd
    Operations
●


        add/add_tail
    –

        remove
    –

    Example from kernel list
●

...
BIGNUM
    Independent functionality
●


    Modularity
●


    Decoupling
●


    Testability
●



    Abstraction – deal...
BIGNUM
    Some of what we have discussed
●


        Initialization/Termination
    ●


        Memory alloc macros
    ●...
Void * and Handle
    Void *
●


    Opaqueness
●


    Handle - Reference counting
●


    Handle - Pimpl Idiom (*)
●
Upcoming SlideShare
Loading in …5
×

sysprog4

926 views

Published on

forth part of the second session in phase I of system programming sessions in eglug

Published in: Technology, Education
  • Be the first to comment

sysprog4

  1. 1. C for Linux Session 4 BY: Eng.Ahmed Teirelbar Software Engineer Shuja' Consulting
  2. 2. Your own .so gcc line – in the makefile ● Versioning ● Overview on how it works ● Dynamic loader ● Relocation - fPIC ● Sharing - mmap ●
  3. 3. Code Organization Public/Private includes ● Reflection of your abstractions ● Delivery: install, lib, bin ●
  4. 4. Multi-file Makefiles Example ● .h Dependency ● Multiple directories ●
  5. 5. Command Line Processing argc, argv ● usage() ● get_opt – libsysfs example ● optarg – optind – getopt_long – ls example ● options structure –
  6. 6. File I/O Intro FILE * (stream) interface ● fopen/fclose – fread/fwrite binary – fprintf/fscanf formatted – Descriptor interface ● open/close – read/write – Note: Filesystem is an abstraction ●
  7. 7. Function Pointers and Callback ret (*name)(args) ● Can store (ptr) and execute (fun) ● Callback concept ● Flexible behavior – Decoupling/Abstraction –
  8. 8. User Configuration Simple guidelines: ● Code encapsulates the parsing – Collect the data once – (Attribute, value) pairs ● Xinetd –
  9. 9. Logging Your eyes on the software ● Debug levels ● Run-time (debug.on/msg in xinetd) – Compile-time – Lookup tables with functions ● Xinetd - parser –
  10. 10. API Examples – Libsysfs Safe string macros ● Attr/Device/Bus/Driver/Module structures and ● corresponding functions (forced by model) Private/public includes and functions ● dlist: generic, separate testing (could be ● opaque) Compare callback ●
  11. 11. Linked List Concepts ● Node – Next/prev – Head – Tail – Size – Singly vs Doubly Linked –
  12. 12. Linked List – Cont'd Operations ● add/add_tail – remove – Example from kernel list ● Example from libsysfs dlist ●
  13. 13. BIGNUM Independent functionality ● Modularity ● Decoupling ● Testability ● Abstraction – dealing with bignums ●
  14. 14. BIGNUM Some of what we have discussed ● Initialization/Termination ● Memory alloc macros ● Expansion macro ● Debug macro ● BN_MASK2 -- SIXTY_FOUR ●
  15. 15. Void * and Handle Void * ● Opaqueness ● Handle - Reference counting ● Handle - Pimpl Idiom (*) ●

×