⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 codingstyle

📁 linux下获取一些环境信息的代码
💻
字号:
If you start a new file, you get to choose the style.If you change an existing file, follow the existing style.Hard tabs are OK, as long as you consider the tab stops tobe every 8 characters. You can also use 2, 3, or 4 spaces.Tabs are kind of yucky, since cut-and-paste mangles themsometimes and they make "diff -Naurd old new" output lessreadable.Spaces within a line don't matter much, and won't beconsidered part of the style. Just make it readable:if(x){            // OKif( x ){           // OKif (x) {            // OKif(x==y && a==b){     // OKif(x == y && a == b){ // poorif(x==y&&a==b){       // poorThis is evil:szWinStallmanFoulCodingStyle (int iInsanity)  {     if (iInsanity)       {          GoHackEmacs () ;       }          else       {          SeekHelpForYourLisp () ;       }  }Curly braces belong at the end of a line. If you must, go aheadand make function bodies an exception to that rule. (as Linus does)Big fprintf() calls and similar go like this:fprintf(fd, "%d %d %d %d %d %d\n",  sdfsdf_sdfsdf + sdfs_iii,     // not an example of good names!  iijjij,  kjfkkj_sdfssss_sfff,  sdflkjfdskj + sdf - sfds,  jksss,  sfssss + wwwwfwfw);Keep these distinct: NULL, '\0', 0, 0.0Command-line parsers need to be bomb-proof. It is not acceptableto crash due to a messed up command-line. For an option "-x" thattakes an argument, accept both "-x arg" and "-xarg". Remember tosupport "--" and "--version".Be extremely careful when handling data from other users.For example, it is a security hole if /proc/123/cmdline canoverflow an array. It is often a security hole if you allownon-ASCII characters to be printed. Assuming the console isnot in UTF-8 mode, all of these are bad: "\b\e\f\n\r\t\v\x9b".(the "\x9b" is valid in UTF-8 mode, but equivalent to "\e["when not in UTF-8 mode -- which gives control of terminalsettings) It's best if you consider user-supplied data tobe unsafe, since this makes for less work in case the codeends up needing to run setuid. Termcap data is user-supplied.Except for the above security issues, don't bother to checkfor something you can't handle... like printf() failing.It is expected that /dev exists and so on.Remember that a read() may return early, with partial dataor with -1 and errno set to EINTR. You then must try again.char:      may be signed or unsigned by defaultint:       always 32-bitlong long: always 64-bitpointer:   either 32-bit or 64-bitlong:      same size as a pointerKLONG:     same size as a pointer or long IN THE KERNELFunctions used in just one file must be marked static.Use the "const" and "restrict" keywords wherever you can.Put main() at the bottom of a file so you don't need allthose ugly forward declarations.Avoid the strcat() function. It is slow. For some oddreason, snprintf() is faster than sprintf().Reuse memory allocations when you can. When using realloc(),do your increments by more than one. 25% is a nice amount.Avoid compile-time choices. They make documentation difficult,and they are not friendly to binary distribution.Write programs that can handle a million processes withoutgetting hopelessly slow. Allow for /proc/123/cmdline tobe at least 128 kB.The LGPL license is strongly preferred. This allows use ofthe code in the library.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -