]> git.proxmox.com Git - mirror_lxc.git/commitdiff
CODING_STYLE: add languages to highlight
authorChristian Brauner <christian.brauner@ubuntu.com>
Fri, 2 Mar 2018 11:57:18 +0000 (12:57 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Fri, 2 Mar 2018 11:57:18 +0000 (12:57 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
CODING_STYLE.md

index efbac1f3323ed753f59e3d5a3a559ccc666a425a..24c6d3603ef60096c169e45f13660261f54fd465 100644 (file)
 - Any comments that are added must use `/* */`.
 - All comments should start on the same line as the opening `/*`.
 - Single-line comments should simply be placed between `/* */`. For example:
-  ```
+  ```C
   /* Define pivot_root() if missing from the C library */
   ```
 - Multi-line comments should end with the closing `*/` on a separate line. For
   example:
-  ```
+  ```C
   /* At this point the old-root is mounted on top of our new-root
    * To unmounted it we must not be chdir()ed into it, so escape back
    * to old-root.
@@ -96,7 +96,7 @@
 - They should be descriptive, without being needlessly long. It is best to just
   use already existing error messages as examples.
 - Examples of acceptable error messages are:
-  ```
+  ```C
   SYSERROR("Failed to create directory \"%s\"", path);
   WARN("\"/dev\" directory does not exist. Proceeding without autodev being set up");
   ```
   the function in the `*.c` file the function signature should not be preceded
   by the `extern` keyword. When declaring the function signature in the `*.h`
   file it must be preceded by the `extern` keyword. For example:
-  ```
+  ```C
   /* Valid function definition in a *.c file */
   ssize_t lxc_write_nointr(int fd, const void* buf, size_t count)
   {
   - put standard types defined by libc before types defined by LXC
   - put multiple declarations of the same type on the same line
 - Examples of good declarations can be seen in the following function:
-  ```
+  ```C
   int lxc_clear_procs(struct lxc_conf *c, const char *key)
   {
           struct lxc_list *it, *next;
   single-line conditions. If there is at least one non-single-line
   condition `{}` must be used.
 - For example:
-  ```
+  ```C
   /* no brackets needed */
   if (size > INT_MAX)
           return -EFBIG;
 - When checking whether a function not returning booleans was successful or not
   the returned value must be assigned before it is checked (`str{n}cmp()`
   functions being one notable exception). For example:
-  ```
+  ```C
   /* assign value to "ret" first */
   ret = mount(sourcepath, cgpath, "cgroup", remount_flags, NULL);
   /* check whether function was successful */
   }
   ```
   Functions returning booleans can be checked directly. For example:
-  ```
+  ```C
   extern bool lxc_string_in_array(const char *needle, const char **haystack);
 
   /* check right away */
   treated as such since they don't really behave like boolean functions. So
   `if (!str{n}cmp())` and `if (str{n}cmp())` checks must not be used. Good
   examples are found in the following functions:
-  ```
+  ```C
   static int set_config_hooks(const char *key, const char *value,
                               struct lxc_conf *lxc_conf, void *data)
 
@@ -321,7 +321,7 @@ rules to use them:
 - **only** jump downwards unless you are handling `EAGAIN` errors and want to
   avoid `do-while` constructs.
 - An example of a good usage of `goto` is:
-  ```
+  ```C
   static int set_config_idmaps(const char *key, const char *value,
                              struct lxc_conf *lxc_conf, void *data)
   {
@@ -394,7 +394,7 @@ rules to use them:
 - If you implement a custom cleanup function to e.g. free a complex type
   you declared you must ensure that the object's null type is handled and
   treated as a NOOP. For example:
-  ```
+  ```C
   void lxc_free_array(void **array, lxc_free_fn element_free_fn)
   {
           void **p;
@@ -410,7 +410,7 @@ rules to use them:
   descriptors and sets the already closed file descriptors to `-EBADF`. On the
   next call it can simply check whether the file descriptor is positive and
   move on if it isn't:
-  ```
+  ```C
   static void lxc_put_attach_clone_payload(struct attach_clone_payload *p)
   {
           if (p->ipc_socket >= 0) {
@@ -439,7 +439,7 @@ rules to use them:
   default do not need to be cast to `(void)`. Classical candidates are
   `close()` and `fclose()`.
 - A good example is:
-  ```
+  ```C
   for (i = 0; hierarchies[i]; i++) {
           char *fullpath;
           char *path = hierarchies[i]->fullcgpath;
@@ -521,7 +521,7 @@ rules to use them:
 - Please always use the affected file (without the file type suffix) or module
   as a prefix in the commit message.
 - Examples of good commit messages are:
-  ```
+  ```Diff
   commit b87243830e3b5e95fa31a17cf1bfebe55353bf13
   Author: Felix Abecassis <fabecassis@nvidia.com>
   Date:   Fri Feb 2 06:19:13 2018 -0800
@@ -559,7 +559,7 @@ rules to use them:
 #### Keep Arrays of `struct`s Aligned Horizontally When Initializing 
 
 - Arrays of `struct`s are:
-  ```
+  ```C
   struct foo_struct {
         int n;
         int m;
@@ -577,7 +577,7 @@ rules to use them:
 - Always leave a single space between the largest member of the current column
   and the member in the next column.
 - A good example is
-  ```
+  ```C
   struct signame {
           int num;
           const char *name;