annotate tool/patchhook.c @ 18:94999935b791 default tip

main-rvtmodem.patch created
author Mychaela Falconia <falcon@ivan.Harhan.ORG>
date Sun, 01 Nov 2015 06:40:12 +0000
parents 04fd47d382c7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
2 * This module implements the "patch hook" that checks if an archive member
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
3 * needs to be patched and invokes all necessary patch processing.
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
4 */
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
5
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <sys/types.h>
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <stdio.h>
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <stdlib.h>
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <string.h>
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
10 #include <strings.h>
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
11 #include <time.h>
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
12 #include "ar.h"
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
13 #include "globals.h"
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
14 #include "patchinfo.h"
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
15
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
16 extern struct ar_hdr ar_hdr;
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
17
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
18 update_ar_timestamp()
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
19 {
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
20 time_t curtime;
8
04fd47d382c7 ti-libpatch: ar member timestamp patching fixed
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 6
diff changeset
21 char tmpbuf[13];
6
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
22
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
23 time(&curtime);
8
04fd47d382c7 ti-libpatch: ar member timestamp patching fixed
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 6
diff changeset
24 sprintf(tmpbuf, "%-12lu", (u_long) curtime);
04fd47d382c7 ti-libpatch: ar member timestamp patching fixed
Space Falcon <falcon@ivan.Harhan.ORG>
parents: 6
diff changeset
25 bcopy(tmpbuf, ar_hdr.ar_date, 12);
6
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
26 }
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
27
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
28 patch_hook()
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
29 {
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
30 struct patch_module_desc *pmd;
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
31 struct patch_desc *patch;
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
32
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
33 for (pmd = patch_module_list; pmd; pmd = pmd->next)
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
34 if (!strcmp(pmd->member_name, member_name))
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
35 break;
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
36 if (!pmd)
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
37 return(0);
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
38 /* yes, we need to patch it: start digging into it */
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
39 parse_coff_hdr();
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
40 for (patch = pmd->patches; patch; patch = patch->next)
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
41 apply_patch(patch);
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
42 update_ar_timestamp();
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
43 return(1);
87e9f30f5f86 ti-libpatch: patching implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff changeset
44 }