POSIX の定義では『テキストファイル』はファイル末尾に改行が必要

3.392 Text File

A file that contains characters organized into one or more lines. https://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap03.html#tag_03_392

3.205 Line

A sequence of zero or more non- s plus a terminating . https://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap03.html#tag_03_205

sbt起動時に Failed to construct terminal エラーが出る

$ sbt 
[ERROR] Failed to construct terminal; falling back to unsupported
java.lang.NumberFormatException: For input string: "0x100"
...

stackoverflow.com

どうも screen-256colorなどがダメなようなので 下記のようなファイルをPATHの優先順位が高いところに作成して対処した

#!/bin/bash
export TERM="${TERM/256color/color}"
exec /usr/bin/sbt "$@"

boolから整数型に変換する時、falseは0に、trueは1になる

N1905

[conv.integral]

If the destination type is bool, see 4.12. If the source type is bool, the value false is converted to zero and the value true is converted to one.

[conv.bool]

An rvalue of arithmetic, enumeration, pointer, or pointer to member type can be converted to an rvalue of type bool. A zero value, null pointer value, or null member pointer value is converted to false any other value is converted to true.

整数型からboolに変換する時は、0ならfalseに、それ以外ならtrueになる。

今素直にvue-loaderをnpm installすると面倒くさい

2018-04-25に vue-loader15がリリースされたのだけど、色々変更が多く互換性が無くて設定が面倒だったので、vue-loader 14 を入れることにした。

 npm install -D vue-loader@14

std::setの要素を追加・削除しても既存の要素への参照やイテレータは有効なまま維持される

N1905 23.1.2 - 8

The insert members shall not affect the validity of iterators and references to the container, and the erase members shall invalidate only iterators and references to the erased elements

C++の連想コンテナ全般(setとかmap系のコンテナ)でそうなる

当然、削除された要素自体への参照やイテレータは無効になる)

pipe + fork + exec 書いてみた

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

void
strwrite(
    int const fd,
    char const* const str)
{
  if(write(fd, str, strlen(str)) < 0) {
    perror("write");
    exit(1);
  }
}

pid_t
process_open(
    char const* const path,
    int const stdin_fd,
    int const stdout_fd,
    int const*   close_on_child_fds,
    size_t const close_on_child_fds_length,
    int const*   close_on_parent_fds,
    size_t const close_on_parent_fds_length)
{
  pid_t const child_pid = fork();

  switch(child_pid) {
    case -1: // error
      perror("fork");
      exit(1);
    case 0: // child
      for(size_t i = 0; i < close_on_child_fds_length; ++i) { close(close_on_child_fds[i]); }
      dup2(stdin_fd,  STDIN_FILENO ); close(stdin_fd);
      dup2(stdout_fd, STDOUT_FILENO); close(stdout_fd);

      execl(path, path, NULL);
      perror(path);
      exit(1);
    default: // parent
      for(size_t i = 0; i < close_on_parent_fds_length; ++i) { close(close_on_parent_fds[i]); }
  }

  return child_pid;
}


int main()
{
  int write_pipefd[2];
  int read_pipefd[2];
  if (pipe(write_pipefd) < 0 || pipe(read_pipefd)) {
    perror("pipe");
    exit(1);
  }

  process_open("/usr/local/bin/lua",
      write_pipefd[0], read_pipefd[1],
      (const int[]){write_pipefd[1], read_pipefd[0]}, 2,
      (const int[]){write_pipefd[0], read_pipefd[1]}, 2);

  strwrite(write_pipefd[1], "print(_VERSION)");
  close(write_pipefd[1]);

  char buf[256] = {0};
  if (read(read_pipefd[0], buf, sizeof(buf)) < 0) {
    perror("read");
    exit(1);
  }

  printf("got [%s]\n", buf);
}