“自作聪明”的 GCC

printf 变 puts /* main.c */ #include <stdio.h> int main(int argc, char *argv[]) { printf("hello world!\n"); return 0; } $ gcc main.c -nostdlib /usr/bin/ld: 警告: 无法找到项目符号 _start; 缺省为 0000000000001030 /usr/bin/ld: /tmp/cc0k0Sjn.o: in function `main': main.c:(.text+0x1b): undefined reference to `puts' collect2: error: ld returned 1 exit status -nostdlib 选项是让 gcc 不链接标准库。……

阅读全文

C语言内联汇编

内联函数 在 C 语言中,我们可以指定编译器将一个函数代码直接复制到调用其代码的地方执行。这种函数调用方式和默认压栈调用方式不同,我们称这种函数为……

阅读全文

MT76xx 无线驱动源码分析

ifconfig ra0 up 这句命令调用的是 pNetDevOps->ndo_open,也就是 main_virtual_if_open /* * ======================================================================== * Routine Description: * Open raxx interface. * ======================================================================== */ int main_virtual_if_open(struct net_device *net_dev) { if (VIRTUAL_IF_INIT(pAd, net_dev) != 0) return -1; if (VIRTUAL_IF_UP(pAd, net_dev) != 0) //……

阅读全文

xargs 将标准输入转成命令行参数

有些命令不支持输入流 前面我们讲过,有些命令是不支持输入流的,只支持命令行参数,如最常用的 ls。我们通常这样使用 $ ls /var/ backups cache crash lib local lock log mail metrics opt run snap……

阅读全文

35 行代码实现一个简单的 shell

先上代码 shell.c #include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <errno.h>#include <sys/types.h>#include <sys/wait.h> #define MAXLINE 4096 /* max line length */ int main(int argc, char *argv[]) { char buf[MAXLINE]; pid_t pid; int status; printf("%% "); /* print prompt (printf requires %% to print %) */ while (fgets(buf, MAXLINE, stdin) != NULL) { if (buf[strlen(buf) - 1] == '\n') buf[strlen(buf) - 1] = '\0'; /* replace newline with NULL */ if……

阅读全文

记录

05/29 Kevin Kelly 给年轻人的99条建议 10/28 libc、glibc和glib的关系 Linux常用系统调用列表 Linux系统调用列表 ## linux 内核源码下载镜像站 strong_alias && weak_alias……

阅读全文