dirname - return directory part of PATH.

news2025/1/8 3:46:12

用Visual Studio 2022开发Linux程序, 用ssh连接

函数单元测试 

下载glibc解压到E:\library\GNU\glibc-2.38

mzh@DESKTOP-GITL67P:~$ sudo /etc/init.d/ssh start
 * Starting OpenBSD Secure Shell server sshd                                                                     [ OK ] 

Run:

 

Solution explorer

配置*.h头文件路径

* basefunc.h

#pragma once
#include <string.h>

#ifdef __cplusplus
extern "C" {
#endif

#ifndef size_t
	typedef unsigned long size_t;
#endif

#ifndef NULL
#define NULL (void *)0
#endif

/* void* bcl_memrchr(const void* s, char c_in, size_t n); */
char* bcl_dirname(char* path);

#ifdef __cplusplus
};
#endif

 * basefunc.c

#include "basefunc.h"

#ifdef __cplusplus
extern "C" {
#endif

    void* bcl_memrchr(const void* s, char c_in, long int n)
    {
        const char* p = s + n - 1;
        for (; (char*)s != p; p--) {
            if (0 == (p[0] ^ c_in)) { break; }
        }
        return (void*)p;
    }

    char* bcl_dirname(char* path)
    {
        static const char dot[] = ".";
        char* last_slash;

        /* Find last '/'.  */
        last_slash = path != NULL ? strrchr(path, '/') : NULL;
        if (last_slash != NULL && last_slash != path && last_slash[1] == '\0') {
            /* Determine whether all remaining characters are slashes.  */
            char* runp;
            for (runp = last_slash; runp != path; --runp) {
                if (runp[-1] != '/') { break; }
            }
            /* The '/' is the last character, we have to look further.  */
            if (runp != path) {
                last_slash = bcl_memrchr(path, '/', runp - path);
            }
        }
        if (last_slash != NULL) {
            /* Determine whether all remaining characters are slashes.  */
            char* runp;
            for (runp = last_slash; runp != path; --runp) {
                if (runp[-1] != '/') { break; }
            }
            /* Terminate the path.  */
            if (runp == path) {
                /* The last slash is the first character in the string.  We have to
                   return "/".  As a special case we have to return "//" if there
                   are exactly two slashes at the beginning of the string.  See
                   XBD 4.10 Path Name Resolution for more information.  */
                if (last_slash == path + 1) { ++last_slash; }
                else { last_slash = path + 1; }
            }
            else {
                last_slash = runp;
            }
            last_slash[0] = '\0';
        }
        else {
            /* This assignment is ill-designed but the XPG specs require to
            return a string containing "." in any case no directory part is
            found and so a static and constant string is required.  */
            path = (char*)dot;
        }
        return path;
    }

#ifdef __cplusplus
};
#endif

* main.c

/* Download glibc  http://mirrors.nju.edu.cn/gnu/libc/glibc-2.38.tar.gz */
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* struct timeval */
#include <sys/select.h>
#include "basefunc.h"

/*
struct timeval
{
    long int tv_sec;
    long int tv_usec;
};
*/

void bcl_udelay(long usec) {
    struct timeval timeout;

    timeout.tv_usec = usec % 1000000;
    timeout.tv_sec = usec / 1000000;

    select(1, NULL, NULL, NULL, &timeout);
}

static int
test(const char* input, const char* result)
{
    int retval;
    char* cp = calloc(strlen(input) + 1, sizeof(char));
    strcpy(cp, input);
    cp = bcl_dirname(cp);
    retval = strcmp(cp, result);
    if (retval) {
        printf("dirname(\"%s\") should be \"%s\", but is \"%s\"\n",
            input, result, cp);
    }
    return retval;
}

static int do_test(void) {
    int result = 0;

    /* These are the examples given in XPG4.2.  */
    result |= test("/usr/lib", "/usr");
    result |= test("/usr/", "/");
    result |= test("usr", ".");
    result |= test("/", "/");
    result |= test(".", ".");
    result |= test("..", ".");

    /* Some more tests.   */
    result |= test("/usr/lib/", "/usr");
    result |= test("/usr", "/");
    result |= test("a//", ".");
    result |= test("a", ".");
    result |= test("usr", "/");
    result |= test("usr//", "/");
    result |= test("//usr", "//");
    result |= test("//usr//", "//");
    result |= test("//", "//");

    /* Other Unix implementations behave like this.  */
    result |= test("x///y", "x");
    result |= test("x/y", "x");

    return result != 0;
}

int main()
{
    if (do_test()) { 
        printf("test FAILED.\n");
    } else { 
        printf("All test PASSED.\n"); 
    }
    bcl_udelay(60000000);
    return 0;
}

Build & Run

 2个test case没有跑通过

* dirname.vcproj

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Debug|ARM">
      <Configuration>Debug</Configuration>
      <Platform>ARM</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|ARM">
      <Configuration>Release</Configuration>
      <Platform>ARM</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Debug|ARM64">
      <Configuration>Debug</Configuration>
      <Platform>ARM64</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|ARM64">
      <Configuration>Release</Configuration>
      <Platform>ARM64</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Debug|x86">
      <Configuration>Debug</Configuration>
      <Platform>x86</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|x86">
      <Configuration>Release</Configuration>
      <Platform>x86</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Debug|x64">
      <Configuration>Debug</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|x64">
      <Configuration>Release</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
  </ItemGroup>
  <PropertyGroup Label="Globals">
    <ProjectGuid>{56eeb392-cfb2-4a99-ac64-deeb8b38efeb}</ProjectGuid>
    <Keyword>Linux</Keyword>
    <RootNamespace>dirname</RootNamespace>
    <MinimumVisualStudioVersion>15.0</MinimumVisualStudioVersion>
    <ApplicationType>Linux</ApplicationType>
    <ApplicationTypeRevision>1.0</ApplicationTypeRevision>
    <TargetLinuxPlatform>Generic</TargetLinuxPlatform>
    <LinuxProjectType>{D51BCBC9-82E9-4017-911E-C93873C4EA2B}</LinuxProjectType>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'" Label="Configuration">
    <UseDebugLibraries>true</UseDebugLibraries>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'" Label="Configuration">
    <UseDebugLibraries>false</UseDebugLibraries>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x86'" Label="Configuration">
    <UseDebugLibraries>true</UseDebugLibraries>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x86'" Label="Configuration">
    <UseDebugLibraries>false</UseDebugLibraries>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
    <UseDebugLibraries>true</UseDebugLibraries>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
    <UseDebugLibraries>false</UseDebugLibraries>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'" Label="Configuration">
    <UseDebugLibraries>false</UseDebugLibraries>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'" Label="Configuration">
    <UseDebugLibraries>true</UseDebugLibraries>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <ImportGroup Label="ExtensionSettings" />
  <ImportGroup Label="Shared" />
  <ImportGroup Label="PropertySheets" />
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <IncludePath>E:\library\GNU\glibc-2.38\include;$(IncludePath)</IncludePath>
  </PropertyGroup>
  <ItemGroup>
    <ClCompile Include="basefunc.c" />
    <ClCompile Include="main.c" />
  </ItemGroup>
  <ItemGroup>
    <ClInclude Include="basefunc.h" />
  </ItemGroup>
  <ItemDefinitionGroup />
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  <ImportGroup Label="ExtensionTargets" />
</Project>

shellexec 1.0

Welcome to Ubuntu 20.04.4 LTS (GNU/Linux 5.15.90.1-microsoft-standard-WSL2 x86_64)
 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage
  System information as of Sun Sep 24 18:38:30 CST 2023
  System load:  0.24               Processes:             221
  Usage of /:   1.7% of 250.92GB   Users logged in:       0
  Memory usage: 9%                 IPv4 address for eth0: 192.168.131.239
  Swap usage:   0%
239 updates can be applied immediately.
166 of these updates are standard security updates.
To see these additional updates run: apt list --upgradable
New release '22.04.3 LTS' available.
Run 'do-release-upgrade' to upgrade to it.
Last login: Sun Sep 24 18:38:29 2023 from 192.168.128.1
mzh@DESKTOP-GITL67P:~$ =thread-group-added,id="i1"
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word".
=cmd-param-changed,param="pagination",value="off"
Stopped due to shared library event (no libraries added or removed)
Loaded '/lib64/ld-linux-x86-64.so.2'. Symbols loaded.
Stopped due to shared library event:
  Inferior loaded /lib/x86_64-linux-gnu/libc.so.6
Loaded '/lib/x86_64-linux-gnu/libc.so.6'. Symbols loaded.

Breakpoint 1, main () at /home/mzh/projects/dirname/main.c:70
70    {

Program received signal SIGTRAP, Trace/breakpoint trap.
0x00007ffff7edbf7a in __GI___select (nfds=1, readfds=0x0, writefds=0x0, exceptfds=0x0, timeout=0x7fffffffea20) at ../sysdeps/unix/sysv/linux/select.c:41
1019kill
The thread 'dirname.out' (0x428) has exited with code 0 (0x0).
[Inferior 1 (process 1064) killed]
The program '' has exited with code 0 (0x0).
 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1037882.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【Spring】-Bean的作用域和生命周期

作者&#xff1a;学Java的冬瓜 博客主页&#xff1a;☀冬瓜的主页&#x1f319; 专栏&#xff1a;【Framework】 主要内容&#xff1a;Lombok的使用&#xff0c;Bean作用域的分类和修改。Singleton、Prototype。spring的执行流程&#xff0c;Bean的生命历程。 文章目录 一、Bea…

树莓派+墨水屏 = DIY一个超慢速电影播放器

安装电子墨水屏这里使用了 Waveshare 的一款墨水屏&#xff0c;带驱动板。将驱动板插入树莓派的 GPIO 即完成屏幕和树莓派的连接。驱动这个屏幕需要启用树莓派的 SPI 接口。运行 sudo raspi-config 进入配置工具来启用 SPI 运行python例程 安装函数库 sudo apt-get update su…

指针笔试题详解

个人主页&#xff1a;点我进入主页 专栏分类&#xff1a;C语言初阶 C语言程序设计————KTV C语言小游戏 C语言进阶 C语言刷题 欢迎大家点赞&#xff0c;评论&#xff0c;收藏。 一起努力&#xff0c;一起奔赴大厂。 目录 1.前言 2.指针题写出下列程序的结…

Unity Windows上Inspector界面黑屏无法显示

问题描述&#xff1a;在Windows上Unity 打开工程Inspector显示黑色&#xff0c;不可用。如下图&#xff1a; 可能的问题。 Unity 设置Windows上默认渲染方式显卡不支持。 解决方案&#xff1a; 一、换一个好一点显卡 二、如下图&#xff1a;

Transformer的上下文学习能力

《Uncovering mesa-optimization algorithms in Transformers》 论文链接&#xff1a;https://arxiv.org/abs/2309.05858 为什么 transformer 性能这么好&#xff1f;它给众多大语言模型带来的上下文学习 (In-Context Learning) 能力是从何而来&#xff1f;在人工智能领域里&…

实验室安全教育与考试

目录 我的错题&#xff08;2个&#xff09;新知识题目&#xff08;10个&#xff09;刚开始不太理解的题目&#xff08;10个&#xff09;写在最后&#xff08;免责声明&#xff09; 我的错题&#xff08;2个&#xff09; 18.发生电气火灾时可以使用的灭火设备包括&#xff1a;&…

SAP Service服务重注册技术手册

当SAP服务被卸载后,或SAP虚拟机整机copy后(可能还需要涉及主机名更改),需要对SAP服务重注册。 在路径 \sapmnt\<SID>\ DVEBMGS00\exe下使用程序sapstartsrv.exe来卸载、安装SAP服务: 其中<SID>、NR参考Service中需要卸载的服务名(卸载后,Services列表中的SA…

【UE 粒子练习】08——LOD概述

目录 概念 应用举例 一、检查当前粒子系统中是否设置了LOD 二、添加LOD 三、LOD设置&#xff08;单个粒子发射器&#xff09; 四、LOD设置&#xff08;多个粒子发射器&#xff09; 概念 在 Unreal Engine 中&#xff0c;LOD&#xff08;Level of Detail&#xff0c;细…

Kubernetes 学习总结(37)—— Kubernetes 之 CoreDNS 企业级应用

前言 IP 地址会有变更&#xff0c;程序配置IP地址&#xff0c;所有涉及到此IP的地方都需要改变&#xff0c;对运维和研发都不友好。IP不容易被记住。引入域名来替换 IP&#xff0c;这样业务使用唯一标识域名&#xff0c;域名可以通过 DNS 服务器解析成 IP 供业务三层通信使用。…

时间复杂度、空间复杂度

一、时间复杂度 1、概念 时间复杂度&#xff1a;计算的是当一个问题量级增加的时间&#xff0c;时间增长的趋势&#xff1b; O&#xff08;大O表示法&#xff09;&#xff1a;渐进的时间复杂度 2、举例 ① 以下 for 循环的时间复杂度&#xff1a;O(1 3n) O(n) 去掉常数…

rom修改----安卓系列机型如何内置app 如何选择so文件内置

系统内置app的需求 在与各工作室对接中操作单中&#xff0c;很多需要内置客户特定的有些app到系统里&#xff0c;这样方便客户刷入固件后直接调用。例如内置apk 去开机引导 去usb调试 默认开启usb安全设置等等。那么很多app内置有不同的反应。有的可以直接内置。有的需要加so…

(十三)VBA常用基础知识:编程时各种常用操作之设值,取值,活动窗口设定

cell里设置内容的两个写法 Sub test() Range("A1").Value "帅哥" Cells(1, 2).Value "帅哥 too" End Sub2.cell里内容的取得 Sub test() Range("A1").Value "帅哥" Cells(1, 2).Value "帅哥 too" a Range(…

Baumer工业相机堡盟工业相机如何通过BGAPI SDK设置相机的图像剪切(ROI)功能(C#)

Baumer工业相机堡盟工业相机如何通过BGAPI SDK设置相机的图像剪切&#xff08;ROI&#xff09;功能&#xff08;C#&#xff09; Baumer工业相机Baumer工业相机的图像剪切&#xff08;ROI&#xff09;功能的技术背景CameraExplorer如何使用图像剪切&#xff08;ROI&#xff09;功…

[nodejs]NVM使用指南

安装 官网链接 使用 # 版本号 nvm version# 显示node是运行在32位还是64位。 nvm arch# 显示已安装的列表 nvm list nvm ls# 使用制定版本node。可指定32/64位 nvm use [version] [arch]# 显示可安装的所有版本 nvm list available# 安装最新版本 nvm install latest# 安装指…

【Linux】系统编程简单线程池(C++)

目录 【1】线程池概念 【1.1】线程池 【1.2】线程池的应用场景 【1.3】线程池的种类 【1.4】线程池示例 【2】线程池代码 【1】线程池概念 【1.1】线程池 一种线程使用模式。线程过多会带来调度开销&#xff0c;进而影响缓存局部性和整体性能。而线程池维护着多个线程&a…

【新书推荐】用户画像:了解用户,助力企业成长 ——《用户画像:平台构建与业务实践》

文章目录 〇、引子一、什么是用户画像二、用户画像的优势三、如何实现用户画像四、用户画像应用中的问题五、总结新书推荐 —— 《用户画像&#xff1a;平台构建与业务实践》内容简介目录 〇、引子 在当今市场竞争激烈的时代&#xff0c;了解用户需求、提高用户体验已成为企业…

WebGL 雾化

目录 前言 如何实现雾化 线性雾化公式 雾化因子关系图 根据雾化因子计算片元颜色公式 示例程序&#xff08;Fog.js&#xff09; 代码详解​编辑 详解如何计算雾化因子&#xff08;clamp()&#xff09; 详解如何计算最终片元颜色&#xff08;根据雾化因子计算片元颜色…

二、搭建Java环境

搭建Java环境 搭建Java环境1.1.下载JDK1.2.在Win10下配置JDK环境 —————————————————————————————————————————————————— ———————————————————————————————————————————————…

李航老师《统计学习方法》第1章阅读笔记

1.1 统计学习 统计学习的特点 统计学习&#xff1a;计算机基于数据构建概率统计模型并运用模型对数据进行预测与分析 现在人们提及机器学习时&#xff0c;往往指统计机器学习&#xff0c;所以可以认为本书介绍的是机器学习方法 统计学习的对象 统计学习研究的对象是数据(data)…

IDEA优化import导报-删除无用的包

选择File--Settings--Editor-General-Auto Import&#xff0c;勾选上下面框起来的即可&#xff0c;这样没有用到的包就会自己动被优化掉了~