Thread: Patch file

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    49

    Patch file

    Hi all,

    Can anyone tell me what is a patch file,what does that use for and how can i write and test a patch file.

    Thanks in advance
    diana --> programming is tough

  2. #2
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    A patch file represents changes to a file. Lets say i have 10 million lines of code in my project and i update 3 of them. I could redistribute the entire project to everyone in my group or i could send them a small file that details the differences.

    you shouldent ever "write" a patch file, they are generated using the diff command. I usually find projects requiring a unified diff (diff -u)

    to test out a patch file, write a small program and save it. Modify the program and save it as a different file. then do the following.

    diff -u oldfile.c newfile.c > myPatch.patch
    you can now have a look at what the patch looks like. A "-" shows what will be removed... a "+" shows what will be added. To apply the patch run

    patch -p0 < myPatch.patch
    the file "oldfile.c" will now be patched with the contents of "newfile.c"

    edit: this of course is all from a linux point of view

  3. #3
    Registered User
    Join Date
    Oct 2004
    Posts
    49
    For example, this are the two files readmaze.c and robot2.c that i need to produce a patch file for.

    So what you mean is that, first i run
    Code:
    diff -u readmaze.c
    diff -u robot2.c
    i understand what is a patch file suppose to do,but now i don't know where to start from.
    diana --> programming is tough

  4. #4
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Quote Originally Posted by dianazheng
    For example, this are the two files readmaze.c and robot2.c that i need to produce a patch file for.
    what is the patch for? Patches are for a change in a file. So if you have an original version of readmaze.c and then you modify it to get a new version of readmaze.c you would run:

    diff -u original-readmaze.c new-readmaze.c
    to get a patch representing your changes.

    You can generate the patch from higher directory levels but this will affect the "-pnum" value you use to apply the patch.
    ex:
    diff -u original/readmaze.c myproject/readmaze.c

  5. #5
    Registered User
    Join Date
    Oct 2004
    Posts
    49
    Ahhh, i get what you means already. thanks.
    diana --> programming is tough

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  3. Making a LIB file from a DEF file for a DLL
    By JMPACS in forum C++ Programming
    Replies: 0
    Last Post: 08-02-2003, 08:19 PM
  4. Hmm....help me take a look at this: File Encryptor
    By heljy in forum C Programming
    Replies: 3
    Last Post: 03-23-2002, 10:57 AM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM