~nabijaczleweli/voreutils

9911525e4e2cd6e84c0318682e0cce679897de38 — наб 28 days ago c6c89a2
Add str[n]dupa() polyfills
3 files changed, 37 insertions(+), 2 deletions(-)

M cmd/cut.cpp
A include/vore-dupa
M tests/cut/test
M cmd/cut.cpp => cmd/cut.cpp +1 -0
@@ 11,6 11,7 @@
#include <vector>
#include <vore-file>
#include <vore-getopt>
#include <vore-dupa>
#include <vore-numeric>
#include <vore-optarg>
#include <vore-print>

A include/vore-dupa => include/vore-dupa +34 -0
@@ 0,0 1,34 @@
// SPDX-License-Identifier: 0BSD


#pragma once


#include <cstring>


#ifndef strdupa
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wgnu-statement-expression"

#define strdupa(str)                                                   \
	({                                                                   \
		const char * _strdupa_str = str;                                   \
		auto len                  = std::strlen(_strdupa_str) + 1;         \
		auto ret                  = reinterpret_cast<char *>(alloca(len)); \
		std::memcpy(ret, _strdupa_str, len);                               \
		ret;                                                               \
	})

#define strndupa(str, maxlen)                                              \
	({                                                                       \
		const char * _strdupa_str = str;                                       \
		auto len                  = strnlen(_strdupa_str, maxlen);             \
		auto ret                  = reinterpret_cast<char *>(alloca(len)) + 1; \
		std::memcpy(ret, _strdupa_str, len);                                   \
		ret[len] = '\0';                                                       \
		ret;                                                                   \
	})

#pragma GCC diagnostic pop
#endif

M tests/cut/test => tests/cut/test +2 -2
@@ 26,7 26,7 @@ for f in $files; do
  } | awk '{print; sub(/-b/, "-nb"); print; sub(/-nb/, "-c"); print; sub(/-c/, "-f"); print}' | while read -r s; do
    {
      echo '';
      expr "$s" : "-f" > /dev/null && {
      expr -- "$s" : "-f" > /dev/null && {
        echo '-d/';
        echo '-dя';
        echo '-d:/';


@@ 34,7 34,7 @@ for f in $files; do
    } | while read -r d; do
      {
        echo '';
        expr "$s" : "-f" > /dev/null && {
        expr -- "$s" : "-f" > /dev/null && {
          echo '-Oя';
          echo '-Ozupsko';
        }