Usage
plash mkdtemp
Description
Create a temporary directory in the plash data.
  Tested Behaviour
  
    
      #!/bin/bash
    
  
    
      
    
  
    
      set -eux
    
  
    
      
    
  
    
      • `plash clean` cleans tmpdir only if calling proccess died
    
  
    
      tmpd=$(plash mkdtemp)
    
  
    
      plash clean
    
  
    
      file $tmpd
    
  
    
      
    
  
    
      • created tmpdir is in PLASH_DATA
    
  
    
      tmpdir="$(plash mkdtemp)"
    
  
    
      [[ "$tmpdir" = "$PLASH_DATA"* ]]
    
  
    
      
    
  
    
      • created tmpdir is writable
    
  
    
      tmpdir="$(plash mkdtemp)"
    
  
    
      touch "$tmpdir/file"
    
  
    
      mkdir "$tmpdir/dir"
    
  
    
      
    
  
Source Code
#define USAGE "usage: plash mkdtemp\n"
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <plash.h>
int mkdtemp_main(int argc, char *argv[]) {
  char *tmpdir, *tmpdir_templ;
  if (asprintf(&tmpdir_templ, "%s/tmp/plashtmp_%d_%d_XXXXXX", pl_call("data"),
               getsid(0), getppid()) == -1)
    pl_fatal("asprintf");
  tmpdir = mkdtemp(tmpdir_templ);
  if (tmpdir == NULL)
    pl_fatal("mkdtemp: %s", tmpdir_templ);
  puts(tmpdir);
  return EXIT_SUCCESS;
}