What is patch file

Patch file is used to apply changes or difference in a source code.When copy of a original source is updated with new lines, then the new lines will inserted in the original source after patching.

for example :our original source is mainmenu.c and we created a copy of the original called mainmenu_copy.c. and insert new lines

mainmenu.c

#include <stdio.h>
#include <stdio.h>
#include <string.h>

#define PASS "datarate2017"

int main ()
{ 
     char pass[20];
     printf("enter the password :\n"); 
     scanf("%s",pass); 
     if(strncmp(pass,PASS,strlen(PASS))!=0) 
         { 
             printf("auth failed!\n");
             return -1;
         } 
   else 
        { 
              printf("enable bluetooth?\n");
        } 
    return 0;
}

create a copy mainmenu_copy.c and inserted few lines

#include <stdio.h>
#include <stdio.h>
#include <string.h>

#define PASS "datarate123"
#define USER "root"

int main ()
{ 
     char pass[20];
     printf("enter the password :\n"); 
     scanf("%s",pass); 
     if(strncmp(pass,PASS,strlen(PASS))!=0) 
         { 
             printf("auth failed!\n");
             return -1;
         } 
   else 
        { 
              printf("welcome %s\n",USER);
              printf("enable bluetooth?\n");
        } 
    return 0;
}

now lets create a patch file for applying patches in original source by diff command

$ diff -c mainmenu.c mainmenu_copy.c > changes.patch

this create a .patch file called changes.patch

apply this patch to original sources

$ patch < changes.patch

now the original source been patched successfully!

little sleepy !! …update soon !!

Advertisements