解析linux patch(解决报错./stdio.h:456:1: error: 'gets' undeclared here (not in a function))

解析linux patch

Patch的主要用途是给代码打补丁,修正已知的错误,或者作为一种调试手段来调试有问题的代码,发现问题和验证修正的结果。 
Patch 过程分三个大的步骤:一是用diff工具比较新旧代码,生成patch文件;二是使用patch命令,将patch文件合并到原有代码;三是检查有无无法patch的文件,修改或重新选择是否对其做patch。patch打完了就可以直接编译了。 
patch对应到的主要命令有两个,diff和patch。至于检查结果,在Linux环境下使用ls命令或者find命令查看有无rej类型的文件就可以了。 
现实中常见的做法,是在makefile中加入patch命令,在编译过程中做好代码的patch,然后编译代码。

patch 文件的结构

补丁头 
补丁头是分别由 —/+++ 开头的两行,用来表示要打补丁的文件。 — 开头表示旧文件, +++ 开头表示新文件。 
一个补丁文件中的多个补丁 
一个补丁文件中可能包含以 —/+++ 开头的很多节,每一节用来打一个补丁。所以在一个补丁文件中可以包含好多个补丁。 
 
块是补丁中要修改的地方。它通常由一部分不用修改的东西开始和结束。他们只是用来表示要修改的位置。他们通常以 @@ 开始,结束于另一个块的开始或者一个新的补丁头。 
块的缩进 
块会缩进一列,而这一列是用来表示这一行是要增加还是要删除的。 
块的第一列 
+ 号表示这一行是要加上的。 
- 号表示这一行是要删除的。 
没有加号也没有减号表示这里只是引用的而不需要修改,用来定位。


diff --git a/include/linux/fb.h b/include/linux/fb.h   ##【这儿表示一个小段的开始】
index c10163b..1296af4 100644
--- a/include/linux/fb.h  ##(一般表示原文件,a是原文件对应的目录)
+++ b/include/linux/fb.h  ##(一般表示改动过的文件,b是其目录名,所以可以直接看他们的下层目录来找)
@@ -403,6 +403,7 @@ struct fb_cursor {   ##第一段不同的地方,旧文件从403行开始,共6行;新文件从403行开始,共7行
 #include <linux/notifier.h>
 #include <linux/list.h>
 #include <linux/backlight.h>
+#include <linux/slab.h>   ##【+表示增加一行】
 #include <asm/io.h>

 struct vm_area_struct;
@@ -862,10 +863,22 @@ struct fb_info {   ##【@@ -862...   此处表示对应该文件的多少行多少列】
    /* we need the PCI or similiar aperture base/size not
       smem_start/size as smem_start may just be an object
       allocated inside the aperture so may not actually overlap */
-   resource_size_t aperture_base;
-   resource_size_t aperture_size;   ##【-表示删除改行】
+   struct apertures_struct {
+       unsigned int count;
+       struct aperture {
+           resource_size_t base;
+           resource_size_t size;
+       } ranges[0];
+   } *apertures;
 };

+static inline struct apertures_struct *alloc_apertures(unsigned int max_num) {
+   struct apertures_struct *a = kzalloc(sizeof(struct apertures_struct)
+           + max_num * sizeof(struct aperture), GFP_KERNEL);
+   a->count = max_num;
+   return a;
+}
+
 #ifdef MODULE
 #define FBINFO_DEFAULT FBINFO_MODULE
 #else

解决方案:

gemfield@CivilNet:~/grub-2.00$ find . -name stdio.in.h ./grub-core/gnulib/stdio.in.h

然后对stdio.in.h文件做出如下改动:

# Begin patch
=== modified file 'grub-core/gnulib/stdio.in.h'
--- grub-core/gnulib/stdio.in.h	2010-09-20 10:35:33 +0000
+++ grub-core/gnulib/stdio.in.h	2012-07-04 15:18:15 +0000
@@ -140,8 +140,10 @@
 /* It is very rare that the developer ever has full control of stdin,
    so any use of gets warrants an unconditional warning.  Assume it is
    always declared, since it is required by C89.  */
+#if defined gets
 #undef gets
 _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
+#endif


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值