aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--store/home/config/nvim/lua/setup/plugins/cmp.lua5
-rw-r--r--www/content/notes/cheat-sheet/_index.md15
-rw-r--r--www/content/notes/hurd/_index.md (renamed from www/content/hurd/_index.md)2
-rw-r--r--www/content/notes/hurd/todos.md (renamed from www/content/hurd/todos.md)0
-rw-r--r--www/content/notes/todos.md (renamed from www/content/todos.md)2
-rw-r--r--www/content/posts/c-func-ext.md80
-rw-r--r--www/layouts/index.html21
7 files changed, 101 insertions, 24 deletions
diff --git a/store/home/config/nvim/lua/setup/plugins/cmp.lua b/store/home/config/nvim/lua/setup/plugins/cmp.lua
index c977943..be9f8ea 100644
--- a/store/home/config/nvim/lua/setup/plugins/cmp.lua
+++ b/store/home/config/nvim/lua/setup/plugins/cmp.lua
@@ -7,15 +7,12 @@ local function setup()
vim.snippet.expand(args.body)
end,
},
- window = {
- completion = cmp.config.window.bordered(),
- documentation = cmp.config.window.bordered(),
- },
mapping = cmp.mapping.preset.insert({
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-j>'] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }),
['<C-k>'] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }),
+ ['<C-e>'] = cmp.mapping.abort(),
['<C-y>'] = cmp.mapping.confirm({ select = true }),
['<CR>'] = cmp.mapping.confirm({ select = true }),
}),
diff --git a/www/content/notes/cheat-sheet/_index.md b/www/content/notes/cheat-sheet/_index.md
new file mode 100644
index 0000000..f379f0b
--- /dev/null
+++ b/www/content/notes/cheat-sheet/_index.md
@@ -0,0 +1,15 @@
+---
+title: "Cheat Sheet"
+date: 2025-04-01T23:09:53+08:00
+lastmod: 2025-04-01T23:09:53+08:00
+layout: single
+---
+
+Update GRUB after `grub` package is updated. Replace `/boot` with your mount
+point of the EFI partition in `--efi-directory=/boot`. Replace `GRUB` with your
+bootloader id in `--bootloader-id=GRUB`.
+
+```bash-session
+grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB
+grub-mkconfig -o /boot/grub/grub.cfg
+```
diff --git a/www/content/hurd/_index.md b/www/content/notes/hurd/_index.md
index b4c727c..86b062a 100644
--- a/www/content/hurd/_index.md
+++ b/www/content/notes/hurd/_index.md
@@ -7,7 +7,7 @@ layout: single
{{< mono >}}
-[TODOS](/hurd/todos)
+[TODOS](/notes/hurd/todos)
{{< /mono >}}
diff --git a/www/content/hurd/todos.md b/www/content/notes/hurd/todos.md
index f8273fb..f8273fb 100644
--- a/www/content/hurd/todos.md
+++ b/www/content/notes/hurd/todos.md
diff --git a/www/content/todos.md b/www/content/notes/todos.md
index a790e24..1625362 100644
--- a/www/content/todos.md
+++ b/www/content/notes/todos.md
@@ -4,4 +4,4 @@ date: 2025-03-03T15:34:53+08:00
lastmod: 2025-03-03T23:28:46+08:00
---
-[Hurd](/hurd/todos)
+[Hurd](/notes/hurd/todos)
diff --git a/www/content/posts/c-func-ext.md b/www/content/posts/c-func-ext.md
index f5ab8fb..f0fce10 100644
--- a/www/content/posts/c-func-ext.md
+++ b/www/content/posts/c-func-ext.md
@@ -8,16 +8,78 @@ tags:
- posix
---
-Recently, I've been working on porting libraries to GNU/Hurd. The maintainers of GNU/Hurd
-have a strong belief that [`*_MAX` macros on POSIX system interfaces](https://pubs.opengroup.org/onlinepubs/9699919799.2008edition/nframe.html)
-are very evil things. This is indeed true as a lot of (old) libraries relying on those macros
-to determine the buffer size. In modern programming world, it is definitely a bad
-idea to use fixed values for buffer sizes without considering possible overflow, unless
-you are certain that size is sufficient.
-
-When you get rid of some old things, you will always meet compatibility problems. In these
-case, old source codes using these macros just do not compile now. So here are some
+Recently, I’ve been working on porting some libraries to GNU/Hurd. Many (old)
+libraries use [`*_MAX` constants on POSIX system
+interfaces](https://pubs.opengroup.org/onlinepubs/9699919799.2008edition/nframe.html)
+to calculate buffer sizes. However, the GNU/Hurd maintainers urge against the
+blind use of them and refuse to define them in system headers. When old APIs are
+gone, compatibility problems come. To make my life easier, I'll put some
+reusable code snippets here to help *fix `*_MAX` bugs*.
<!--more-->
+```c
+#include <errno.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+static inline char *xreadlink(const char *restrict path) {
+ char *buffer;
+ size_t allocated = 128;
+ ssize_t len;
+
+ while (1) {
+ buffer = (char *)malloc(allocated);
+ if (!buffer) {
+ return NULL;
+ }
+ len = readlink(path, buffer, allocated);
+ if (len < (ssize_t)allocated) {
+ return buffer;
+ }
+ free(buffer);
+ if (len >= (ssize_t)allocated) {
+ allocated *= 2;
+ continue;
+ }
+ return NULL;
+ }
+}
+
+static inline char *xgethostname() {
+ long max_host_name;
+ char *buffer;
+
+ max_host_name = sysconf(_SC_HOST_NAME_MAX);
+ buffer = malloc(max_host_name + 1);
+
+ if (gethostname(buffer, max_host_name + 1)) {
+ free(buffer);
+ return NULL;
+ }
+
+ buffer[max_host_name] = '\0';
+ return buffer;
+}
+
+static inline char *xgetcwd() {
+ char *buffer;
+ size_t allocated = 128;
+ while (1) {
+ buffer = (char *)malloc(allocated);
+ if (!buffer) {
+ return NULL;
+ }
+ getcwd(buffer, allocated);
+ if (buffer)
+ return buffer;
+ free(buffer);
+ if (errno == ERANGE) {
+ allocated *= 2;
+ continue;
+ }
+ return NULL;
+ }
+}
+```
diff --git a/www/layouts/index.html b/www/layouts/index.html
index 7c608f1..f456e71 100644
--- a/www/layouts/index.html
+++ b/www/layouts/index.html
@@ -26,23 +26,26 @@
<hr />
<section>
<p>Welcome to my home page! Nice to meet you here! 🥰</p>
- <p>If you have something interesting to share with me, feel free to email me at
- <a rel="noopener noreferrer" href="mailto:crupest@crupest.life">crupest@crupest.life</a>.
- You can also create an issue in any of my repos on GitHub to talk anything to me.
+ <p>If you have something interesting to share with me, feel free to email me
+ at <a rel="noopener noreferrer" href="mailto:crupest@crupest.life">crupest@crupest.life</a>.
+ You can also create an issue in any of my repos
+ on <a rel="noopener noreferrer" href="https://github.com/crupest">GitHub</a> to talk
+ anything to me.
</p>
<div id="links" class="mono-link">
- links:
+ jump-to:
<ul>
- <li><a href="{{ .RelPermalink }}">home</a></li>
<li><a href="{{ absURL "/git/" }}">git</a></li>
- {{ with .GetPage "/hurd" }}
+ {{ with .GetPage "/notes/hurd" }}
<li><a href="{{ .RelPermalink }}">hurd</a></li>
{{ end }}
- {{ with .GetPage "/todos" }}
+ {{ with .GetPage "/notes/todos" }}
<li><a href="{{ .RelPermalink }}">todos</a></li>
{{ end }}
- <li><a rel="noopener noreferrer" href="https://github.com/crupest">github</a></li>
- </ul>
+ {{ with .GetPage "/notes/cheat-sheet" }}
+ <li><a href="{{ .RelPermalink }}">cheat-sheet</a></li>
+ {{ end }}
+ </ul>
</div>
</section>
<hr>