sttsのソースコードMemoブログ

色々やってみた結果のMemo

Solaris11でWindowsとファイル共有

Solaris11のインストール

以下を参考にしてインストールしました。

http://www.kkaneko.com/computer/solaris/sol11.html

SMB

以下を参考にファイル共有しました。

http://www24.atwiki.jp/pcmbeta/pages/39.html

パッケージのインストールやサービスの起動は以下の操作をした。

root@testsolaris:~# pkg install 'pkg://solaris/system/file-system/smb' 'pkg://solaris/service/file-system/smb'
root@testsolaris:~# svcadm enable -r smb/server
root@testsolaris:~# svcadm enable -r smb/client

/etc/pam.d/otherの最後に以下を記載

password required pam_smb_passwd.so.1 nowarm

passwdコマンドでパスワードを再設定

root@testsolaris:~# smbadm join -w workgroup

以下のように共有した。

root@testsolaris:~# zfs set share.smb=on rpool/export/home/testuser

終わり

C言語でバイナリサーチ

C言語でバイナリサーチをするサンプルです。

#include 
#include 
#include 

static int cmp(const void *p1, const void *p2) {
	char *c1;
	char *c2;

	c1 = *(char **)p1;
	c2 = *(char **)p2;
	//printf("cmp %s - %s\n", c1, c2);
	return strcmp(c1, c2);
}
int main (int argc, char *argv[]) {

	int number = 0;
	char *list[4096];
	char buf[4096];
	FILE *fp = NULL;
	char **ret;
	int i;

	fp = fopen(argv[1], "r");
	while ( fgets(buf, sizeof(buf), fp) != NULL) {
		list[number] = strdup(buf);
		number++;
	}
	fclose(fp);
	
	qsort(list, number, sizeof(char *), cmp);

	if (argc == 3) {
		ret = bsearch(&(argv[2]), list, number, sizeof(char *), cmp);
		if (ret != NULL) {
			printf("find! %s\n", *ret);
			exit(1);
		}
	}
		
	for (i=0; i<number; i++) {
		printf("%s", list[i]);
	}
}

以下のように実行します。

$ ./a.out ソート対象の入力ファイル 検索対象の文字列

もっと高級言語を使いたい。。。

zshrcのメモ

バックアップもかねてzshrc

# Enable compsys completion.
autoload -U compinit
compinit
zstyle ':completion:*:default' menu select=1 # Menu like emacs.
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}  # color completion.

bindkey -e # keybind is emacs.

# Prompt
setopt prompt_subst
PROMPT='%{%(?.$fg[green].$fg[red])%}[%n@%m]%# %{$reset_color%}' # left prompt
RPROMPT='[%~]'
autoload -U colors
colors

# History
HISTFILE=$HOME/.zsh-history
HISTSIZE=10000
SAVEHIST=10000
setopt extended_history # save command time.
setopt share_history    # share history in terms.
setopt append_history   # append
function history-all { history -E 1 }

# Beep
setopt no_beep

# cd
setopt auto_pushd
setopt pushd_ignore_dups

# PATH
# For homebrew
export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
export MANPATH=/usr/local/man:$MANPATH